26 import static com.sun.swingset3.demos.progressbar.ProgressBarDemo.*; 27 import java.awt.Component; 28 import static org.testng.AssertJUnit.*; 29 import org.testng.annotations.Test; 30 import org.netbeans.jemmy.ClassReference; 31 import org.netbeans.jemmy.ComponentChooser; 32 import org.netbeans.jemmy.operators.JButtonOperator; 33 import org.netbeans.jemmy.operators.JFrameOperator; 34 import org.netbeans.jemmy.operators.JProgressBarOperator; 35 import org.testng.annotations.Listeners; 36 37 /* 38 * @test 39 * @key headful 40 * @summary Verifies SwingSet3 ProgressBarDemo page by pressing start and stop 41 * buttons and checking the progress bar and the buttons state. 42 * 43 * @library /sanity/client/lib/jemmy/src 44 * @library /sanity/client/lib/Extensions/src 45 * @library /sanity/client/lib/SwingSet3/src 46 * @build org.jemmy2ext.JemmyExt 47 * @build com.sun.swingset3.demos.progressbar.ProgressBarDemo 48 * @run testng ProgressBarDemoTest 49 */ 50 @Listeners(GuiTestListener.class) 51 public class ProgressBarDemoTest { 52 53 @Test 54 public void test() throws Exception { 55 56 new ClassReference(ProgressBarDemo.class.getCanonicalName()).startApplication(); 57 58 JFrameOperator frame = new JFrameOperator(DEMO_TITLE); 59 60 JButtonOperator startButton = new JButtonOperator(frame, START_BUTTON); 61 JButtonOperator stopButton = new JButtonOperator(frame, STOP_BUTTON); 62 JProgressBarOperator jpbo = new JProgressBarOperator(frame); 63 64 // Check that progress completes and corect enable/disable of start/stop buttons 65 checkCompleteProgress(frame, startButton, stopButton, jpbo); 66 67 // Check progess bar progression and start/stop button disabled/enabled states 68 checkStartStop(frame, startButton, stopButton, jpbo); 69 } 70 71 // Check that progress completes and corect enable/disable of start/stop buttons 72 public void checkStartStop(JFrameOperator frame, JButtonOperator startButton, JButtonOperator stopButton, JProgressBarOperator progressBar) throws Exception { 73 int initialProgress = progressBar.getValue(); 74 System.out.println("initialProgress = " + initialProgress); 75 int maximum = progressBar.getMaximum(); 76 77 startButton.pushNoBlock(); 78 79 progressBar.waitState(new ComponentChooser() { 80 81 @Override 82 public boolean checkComponent(Component comp) { 83 int value = progressBar.getValue(); 84 System.out.println("checkComponent1 value = " + value); 85 return value < maximum; 86 } 87 88 @Override 89 public String getDescription() { 90 return "Progress < maximum (" + maximum + ")"; 91 } 92 }); 93 94 stopButton.waitComponentEnabled(); 95 96 progressBar.waitState(new ComponentChooser() { 97 98 @Override 99 public boolean checkComponent(Component comp) { 100 int value = progressBar.getValue(); 101 System.out.println("checkComponent2 value = " + value); 102 return value > 0; 103 } 104 105 @Override 106 public String getDescription() { 107 return "Progress > 0"; 108 } 109 }); 110 111 int progress = progressBar.getValue(); 112 System.out.println("progress = " + progress); 113 114 //Check that progress par has progressed and Start Button Disabled 115 assertTrue("Progress Bar Progressing (progress > 0, actual value: " + progress + ")", progress > 0); 116 assertFalse("Start Button Disabled", startButton.isEnabled()); 117 assertTrue("Stop Button Enabled", stopButton.isEnabled()); 118 119 //Wait a liitle bit longer then Press stop get progress 120 progressBar.waitState(new ComponentChooser() { 121 | 26 import static com.sun.swingset3.demos.progressbar.ProgressBarDemo.*; 27 import java.awt.Component; 28 import static org.testng.AssertJUnit.*; 29 import org.testng.annotations.Test; 30 import org.netbeans.jemmy.ClassReference; 31 import org.netbeans.jemmy.ComponentChooser; 32 import org.netbeans.jemmy.operators.JButtonOperator; 33 import org.netbeans.jemmy.operators.JFrameOperator; 34 import org.netbeans.jemmy.operators.JProgressBarOperator; 35 import org.testng.annotations.Listeners; 36 37 /* 38 * @test 39 * @key headful 40 * @summary Verifies SwingSet3 ProgressBarDemo page by pressing start and stop 41 * buttons and checking the progress bar and the buttons state. 42 * 43 * @library /sanity/client/lib/jemmy/src 44 * @library /sanity/client/lib/Extensions/src 45 * @library /sanity/client/lib/SwingSet3/src 46 * @modules java.desktop 47 * java.logging 48 * @build org.jemmy2ext.JemmyExt 49 * @build com.sun.swingset3.demos.progressbar.ProgressBarDemo 50 * @run testng ProgressBarDemoTest 51 */ 52 @Listeners(GuiTestListener.class) 53 public class ProgressBarDemoTest { 54 55 @Test 56 public void test() throws Exception { 57 58 new ClassReference(ProgressBarDemo.class.getCanonicalName()).startApplication(); 59 60 JFrameOperator frame = new JFrameOperator(DEMO_TITLE); 61 62 JButtonOperator startButton = new JButtonOperator(frame, START_BUTTON); 63 JButtonOperator stopButton = new JButtonOperator(frame, STOP_BUTTON); 64 JProgressBarOperator jpbo = new JProgressBarOperator(frame); 65 66 // Check that progress completes and corect enable/disable of start/stop buttons 67 checkCompleteProgress(frame, startButton, stopButton, jpbo); 68 69 // Check progess bar progression and start/stop button disabled/enabled states 70 checkStartStop(frame, startButton, stopButton, jpbo); 71 } 72 73 // Check that progress completes and corect enable/disable of start/stop buttons 74 public void checkStartStop(JFrameOperator frame, JButtonOperator startButton, JButtonOperator stopButton, JProgressBarOperator progressBar) throws Exception { 75 int initialProgress = progressBar.getValue(); 76 System.out.println("initialProgress = " + initialProgress); 77 int maximum = progressBar.getMaximum(); 78 79 startButton.pushNoBlock(); 80 81 progressBar.waitState(new ComponentChooser() { 82 83 @Override 84 public boolean checkComponent(Component comp) { 85 int value = progressBar.getValue(); 86 return value < maximum; 87 } 88 89 @Override 90 public String getDescription() { 91 return "Progress < maximum (" + maximum + ")"; 92 } 93 }); 94 95 stopButton.waitComponentEnabled(); 96 97 progressBar.waitState(new ComponentChooser() { 98 99 @Override 100 public boolean checkComponent(Component comp) { 101 int value = progressBar.getValue(); 102 return value > 0; 103 } 104 105 @Override 106 public String getDescription() { 107 return "Progress > 0"; 108 } 109 }); 110 111 int progress = progressBar.getValue(); 112 System.out.println("progress = " + progress); 113 114 //Check that progress par has progressed and Start Button Disabled 115 assertTrue("Progress Bar Progressing (progress > 0, actual value: " + progress + ")", progress > 0); 116 assertFalse("Start Button Disabled", startButton.isEnabled()); 117 assertTrue("Stop Button Enabled", stopButton.isEnabled()); 118 119 //Wait a liitle bit longer then Press stop get progress 120 progressBar.waitState(new ComponentChooser() { 121 |