source: gs3-extensions/testing/trunk/src/src/gstests/tutorials/RunGLITest.EDTcheckOff_NoHelp@ 32715

Last change on this file since 32715 was 32715, checked in by ak19, 5 years ago

Turning off EDT (event dispatch thread) violation check doesn't help if the EDT violation still remains in GLI. In fact, by turning off the check and leaving the errors in, the robot suddenly stops working here and there, with tests failing cryptically. Committing the modifications for turning off the EDT violation check a separate file, but there seems to be no choice but to read up on SwingWorker and start doing the right thing in GLI.

File size: 6.4 KB
Line 
1package gstests.tutorials;
2
3/*
4Ctrl+Shift+A TO ABORT A RUNNING GUI-TEST CYCLE (won't abort Selenium/browser tests)
5
6Using AssertJ Swing to do Java GUI testing (of swing classes)
7- Obtain from: https://search.maven.org/search?q=assertj-swing-junit
8- Documentation: https://joel-costigliola.github.io/assertj/assertj-swing.html
9
10Alternatives to AssertJSwing (googled: automate java interface testing) suggested at
11https://sqa.stackexchange.com/questions/18554/open-source-tools-for-automation-of-java-gui-application-testing
12
13Event Dispatch Thread (EDT) pages:
14- https://joel-costigliola.github.io/assertj/assertj-swing-edt.html
15- https://web.archive.org/web/20120526191520/http://alexruiz.developerblogs.com/?p=160
16- https://web.archive.org/web/20130218063544/http://weblogs.java.net/blog/alexfromsun/archive/2006/02/debugging_swing.html
17- https://stackoverflow.com/questions/2829364/java-difference-between-swingworker-and-swingutilities-invokelater
18
19Got AssertJ Swing from Maven Central Repository:
20https://search.maven.org/search?q=assertj-swing-junit
21-> http://central.maven.org/maven2/org/assertj/assertj-core/3.8.0/
22More jar files: http://repo1.maven.org/maven2/org/assertj/
23- http://repo1.maven.org/maven2/org/assertj/assertj-swing/3.8.0/
24- http://central.maven.org/maven2/org/assertj/assertj-core/3.8.0/
25
26API:
27https://joel-costigliola.github.io/assertj/swing/api/index.html
28
29JUNIT:
30- https://junit.org/junit4/faq.html#atests_2
31 How do I use a test fixture?
32- https://junit.org/junit4/faq.html#organize_3
33 How can I run setUp() and tearDown() code once for all of my tests?
34
35*/
36
37// Junit imports
38import org.junit.AfterClass;
39import org.junit.After;
40import org.junit.Assert;
41import org.junit.Before;
42import org.junit.BeforeClass;
43import org.junit.Test;
44
45// GLI imports
46import org.greenstone.gatherer.Gatherer;
47import org.greenstone.gatherer.GathererProg; // main GLI class we'll be testing
48import org.greenstone.gatherer.Dictionary; // access to display strings
49
50// Java GUI testing with AssertJ Swing
51import org.assertj.swing.junit.testcase.AssertJSwingJUnitTestCase;
52import org.assertj.swing.fixture.*;
53import org.assertj.swing.core.*; // Robot
54import org.assertj.swing.data.Index;
55
56// Selenium
57import org.openqa.selenium.By;
58import org.openqa.selenium.WebDriver;
59import org.openqa.selenium.WebElement;
60import org.openqa.selenium.firefox.FirefoxDriver;
61
62// Helper classes for selenium and AssertJ Swing tests
63import org.greenstone.gsdl3.testing.GSTestingUtil;
64import org.greenstone.gsdl3.testing.GSGUITestingUtil;
65
66// Java imports
67import javax.swing.*;
68
69// static imports
70import static org.greenstone.gsdl3.testing.GSGUITestingUtil.*;
71
72/**
73 * Class that will eventually go through all the Greenstone3 tutorials by running GLI and GEMS.
74 */
75public class RunGLITest {
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();
79 private static WebDriver _driver = new FirefoxDriver(); // for browser tests with selenium
80 private static Robot robot; // for Java GUI tests with assertj-swing
81
82 private FrameFixture window;
83
84 @BeforeClass
85 public static void setUpOnce() {
86 //FailOnThreadViolationRepaintManager.install();
87
88 // Need to have the robot before we can call runGLI()
89 // Robot is the class that controls/drives user input by taking control over the keyboard and mouse
90 robot = BasicRobot.robotWithNewAwtHierarchy();
91 }
92
93
94 @Before
95 public void init()
96 {
97 // 1. Selenium
98
99 //https://stackoverflow.com/questions/38676719/selenium-using-java-the-path-to-the-driver-executable-must-be-set-by-the-webdr
100 // GS3's build.xml would have set the webdriver.gecko.driver path System.Property to
101 // the location of Firefox' geckodriver executable when launching this test class already.
102 // So now we can continue to just do:
103 _driver.get(System.getProperty("SERVERURL"));
104
105
106 // 2. assertj-swing
107
108 // Run GLI and show the window
109 // Launch GLI and then get a ref to the launched app window:
110 runGLI();
111
112 // IMPORTANT, note the call to 'robot()': must use the Robot from AssertJSwingJUnitTestCase base class
113 //window = findFrame("GUIManager").using(robot());
114 window = GSGUITestingUtil.getGLIApplicationWindow(robot);
115 }
116
117
118 @Test
119 public void testGLIRunning() {
120
121
122 // waiting a few seconds for window, so we can see it
123 PAUSE(2);
124
125 System.err.println("@@@ First test: GLI Running");
126
127
128 String expectedWindowTitle = Gatherer.PROGRAM_NAME;
129
130
131 String gatherPaneLabel = Dictionary.get("GUI.Gather");
132 System.err.println("@@@ Expecting label: " + gatherPaneLabel);
133
134 System.err.println("@@@ Second test: that Gather panel is selected and has right title");
135
136 JTabbedPaneFixture tab = window.tabbedPane("GUIManager.tab_pane");
137
138
139 tab.requireSelectedTab(Index.atIndex(1));
140 tab.requireTitle(gatherPaneLabel, Index.atIndex(1));
141
142 // attempt to switch to enrich pane, uses static methods of GSGUITestingUtil
143 // through static import of that class
144 switchToPane(DOWNLOAD_PANE);
145
146 // For testing, want GLI to be in librarian mode by default
147 changeUserMode("librarian");
148
149 switchToPane(GATHER_PANE);
150
151 loadCollection("lucene-jdbm-demo");
152
153 // wait a couple of seconds again?
154 PAUSE(2);
155 closeCollection();
156
157 createCollection("pinky", "Pinky was here", null);
158 closeCollection(); // collection must be closed in order to be deleted
159 deleteCollection("pinky");
160
161 // wait a few of seconds again?
162 PAUSE(2);
163
164 exportCollection("GreenstoneMETS", "lucene-jdbm-demo");
165
166 // Reset GLI to expert mode for regular GLI use
167 changeUserMode("expert");
168
169 PAUSE(2);
170
171 switchToPane(GATHER_PANE);
172
173 //exitGLI(); //System.exit() on GLI won't allow quit to be called on Selenium's web _driver, why?
174 PAUSE(3);
175 }
176
177 @After
178 public void tearDown() {
179 // call FrameFixture's cleanUp() which
180 // "Cleans up any used resources (keyboard, mouse, open windows and ScreenLock) used by this robot."
181 window.cleanUp();
182 }
183
184 // Selenium
185 // called once and only once: to quit the firefox driver geckodriver
186 @AfterClass
187 public static void destroy()
188 {
189 abortListener.unregister(); // aborting assertJ-swing GUI tests
190 _driver.quit();
191 }
192}
Note: See TracBrowser for help on using the repository browser.