Changeset 32714 for gs3-extensions/testing
- Timestamp:
- 2018-12-18T21:22:40+13:00 (5 years ago)
- Location:
- gs3-extensions/testing/trunk/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
gs3-extensions/testing/trunk/src/src/gstests/tutorials/RunGLITest.java
r32713 r32714 2 2 3 3 /* 4 Ctrl+Shift+A TO ABORT A RUNNING GUI-TEST CYCLE (won't abort Selenium/browser tests) 5 4 6 Using AssertJ Swing to do Java GUI testing (of swing classes) 5 7 - Obtain from: https://search.maven.org/search?q=assertj-swing-junit … … 35 37 // Junit imports 36 38 import org.junit.AfterClass; 39 import org.junit.After; 37 40 import org.junit.Assert; 38 41 import org.junit.Before; 42 import org.junit.BeforeClass; 39 43 import org.junit.Test; 40 44 … … 47 51 import org.assertj.swing.junit.testcase.AssertJSwingJUnitTestCase; 48 52 import org.assertj.swing.fixture.*; 49 import org.assertj.swing.edt.GuiActionRunner; 50 import org.assertj.swing.core.*; 53 import org.assertj.swing.core.*; // Robot 51 54 import org.assertj.swing.data.Index; 52 55 … … 64 67 import javax.swing.*; 65 68 66 67 68 69 // static imports 69 import static org.assertj.swing.launcher.ApplicationLauncher.*;70 import static org.assertj.swing.finder.WindowFinder.findFrame;71 72 70 import static org.greenstone.gsdl3.testing.GSGUITestingUtil.*; 73 71 72 /** 73 * Class that will eventually go through all the Greenstone3 tutorials by running GLI and GEMS. 74 */ 74 75 public class RunGLITest extends AssertJSwingJUnitTestCase { 75 76 // For aborting running test suite, with Ctrl+Shift+A by default 77 // https://joel-costigliola.github.io/assertj/assertj-swing-running.html 78 private static EmergencyAbortListener abortListener = EmergencyAbortListener.registerInToolkit(); 76 79 private static WebDriver _driver = new FirefoxDriver(); // selenium 77 80 … … 89 92 } 90 93 94 95 // assertj-swing 96 // As init() above, onSetUp() gets called before every test method too, 97 // but is overridden from assertj-swing base class 91 98 @Override 92 99 protected void onSetUp() { 93 GathererProg frame = GuiActionRunner.execute(() -> new GathererProg()); 94 // IMPORTANT: note the call to 'robot()' 95 // we must use the Robot from AssertJSwingJUnitTestCase 100 // Launch GLI and then get a ref to the launched app window: 101 runGLI(); 96 102 97 //window = new FrameFixture(robot(), frame);98 //window.show(); // shows the frame to test99 103 100 // Launch GathererProg.java's main() method 101 // See https://joel-costigliola.github.io/assertj/assertj-swing-launch.html 102 103 String GSDLOS = System.getenv("GSDLOS"); 104 String GSDLHOME = System.getenv("GSDLHOME"); 105 String GSDL3HOME = System.getenv("GSDL3HOME"); 106 String GSDL3SRCHOME = System.getenv("GSDL3SRCHOME"); 107 application("org.greenstone.gatherer.GathererProg").withArgs( 108 "-gsdl", GSDLHOME, 109 "-gsdlos", GSDLOS, 110 "-gsdl3", GSDL3HOME, 111 "-gsdl3src", GSDL3SRCHOME, 112 "-testing_mode").start(); 104 // IMPORTANT, note the call to 'robot()': must use the Robot from AssertJSwingJUnitTestCase 105 //window = findFrame("GUIManager").using(robot()); 106 window = GSGUITestingUtil.getGLIApplicationWindow(robot()); 113 107 } 114 108 … … 117 111 public void testGLIRunning() { 118 112 119 113 120 114 // waiting a few seconds for window, so we can see it 121 PAUSE(2); 122 115 PAUSE(2); 123 116 124 117 System.err.println("@@@ First test: GLI Running"); … … 127 120 String expectedWindowTitle = Gatherer.PROGRAM_NAME; 128 121 129 window = findFrame("GUIManager").using(robot()); 130 131 GSGUITestingUtil.setWindow(window); // set this first before calling any of Util's other methods 132 122 133 123 String gatherPaneLabel = Dictionary.get("GUI.Gather"); 134 124 System.err.println("@@@ Expecting label: " + gatherPaneLabel); … … 168 158 changeUserMode("expert"); 169 159 170 PAUSE(5); 171 //exitGLI(); 160 PAUSE(2); 172 161 173 162 switchToPane(GATHER_PANE); 163 164 //exitGLI(); //System.exit() on GLI won't allow quit to be called on Selenium's web _driver, why? 165 PAUSE(3); 174 166 } 175 167 … … 179 171 public static void destroy() 180 172 { 173 abortListener.unregister(); // aborting assertJ-swing GUI tests 181 174 _driver.quit(); 182 183 175 } 184 176 } -
gs3-extensions/testing/trunk/src/src/org/greenstone/gsdl3/testing/GSGUITestingUtil.java
r32713 r32714 16 16 import org.greenstone.gatherer.GathererProg; // main GLI class we'll be testing 17 17 import org.greenstone.gatherer.Dictionary; // access to display strings 18 19 20 // Java GUI testing with AssertJ Swing 21 import org.assertj.swing.junit.testcase.AssertJSwingJUnitTestCase; 22 import org.assertj.swing.fixture.*; 23 import org.assertj.swing.edt.GuiActionRunner; 24 import org.assertj.swing.core.Robot; 25 26 27 // static imports 28 import static org.assertj.swing.launcher.ApplicationLauncher.*; 29 import static org.assertj.swing.finder.WindowFinder.findFrame; 18 30 19 31 /* … … 42 54 // can have easier access to those GUI components when testing here through their names 43 55 44 /************************ GENERAL *******************************/ 45 46 public static void setWindow(FrameFixture w) { window = w; } 47 56 /****************************** APPLICATION *******************************/ 48 57 public static void PAUSE() { 49 58 PAUSE(5); … … 58 67 e.printStackTrace(); 59 68 } 60 } 61 69 } 70 71 //public static void setWindow(FrameFixture w) { window = w; } // if we want to null window 72 73 public static void runGLI() { 74 //GathererProg frame = GuiActionRunner.execute(() -> new GathererProg()); 75 76 // IMPORTANT, note the call to 'robot()': must use the Robot from AssertJSwingJUnitTestCase 77 //window = new FrameFixture(robot(), frame); 78 //window.show(); // shows the frame to test 79 80 // Instead, we'll be launching GLI and then getting a ref to the launched app window: 81 82 // Launch GathererProg.java's main() method 83 // See https://joel-costigliola.github.io/assertj/assertj-swing-launch.html 84 85 String GSDLOS = System.getenv("GSDLOS"); 86 String GSDLHOME = System.getenv("GSDLHOME"); 87 String GSDL3HOME = System.getenv("GSDL3HOME"); 88 String GSDL3SRCHOME = System.getenv("GSDL3SRCHOME"); 89 application("org.greenstone.gatherer.GathererProg").withArgs( 90 "-gsdl", GSDLHOME, 91 "-gsdlos", GSDLOS, 92 "-gsdl3", GSDL3HOME, 93 "-gsdl3src", GSDL3SRCHOME, 94 "-testing_mode").start(); 95 // The -testing_mode flag passed into GLI above is a special flag 96 // that calls GLI's TestingPreparating.setNamesRecursively() 97 // to help testing by calling setName() on GUI components. 98 } 99 100 public static void exitGLI() { 101 openMenuItem("file", "exit"); 102 } 103 104 // Gets a ref to the main window (FrameFixture) of a running GLI 105 public static FrameFixture getGLIApplicationWindow(Robot robot) { 106 // locate and set the internal FrameFixture member variable 'window' and return a handle to it 107 window = findFrame("GUIManager").using(robot); // GLI application JFrame's name is set to its classname, 'GUIManager' 108 109 // https://joel-costigliola.github.io/assertj/swing/api/index.html?org/assertj/swing/launcher/ApplicationLauncher.html 110 // "To change the speed of a GUI test, you need to change the values of both delayBetweenEvents and eventPostingDelay." 111 //robot.settings().delayBetweenEvents(50); 112 //robot.settings().eventPostingDelay(2*SECOND); // annoying, after every click! 113 114 return window; 115 } 116 117 /****************************** BASICS *******************************/ 118 62 119 63 120 //https://joel-costigliola.github.io/assertj/swing/api/org/assertj/swing/fixture/FrameFixture.html … … 122 179 } 123 180 124 public static void exitGLI() {125 openMenuItem("file", "exit");126 PAUSE(5);127 }128 181 129 182 public static void closeCollection(){ … … 315 368 } 316 369 370 371 /********************* GEMS ******************/ 372 373 // TODO: 374 public static void runGEMS() {} 375 public static void exitGEMS() {} 376 public static FrameFixture getGEMSApplicationWindow(Robot robot) { 377 // TODO: don't forget to set internal member variable called 'window' before returning it 378 return window; 379 } 380 317 381 // Moving these working bits of code here, in case I can use them to right 318 382 // general get methods that make use of the GenericTypeMatcher method of accessing components
Note:
See TracChangeset
for help on using the changeset viewer.