1 | package gstests.tutorials;
|
---|
2 |
|
---|
3 | /*
|
---|
4 | Ctrl+Shift+A TO ABORT A RUNNING GUI-TEST CYCLE (won't abort Selenium/browser tests)
|
---|
5 |
|
---|
6 | Using 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 |
|
---|
10 | Alternatives to AssertJSwing (googled: automate java interface testing) suggested at
|
---|
11 | https://sqa.stackexchange.com/questions/18554/open-source-tools-for-automation-of-java-gui-application-testing
|
---|
12 |
|
---|
13 | Event 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 |
|
---|
19 | Got AssertJ Swing from Maven Central Repository:
|
---|
20 | https://search.maven.org/search?q=assertj-swing-junit
|
---|
21 | -> http://central.maven.org/maven2/org/assertj/assertj-core/3.8.0/
|
---|
22 | More 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 |
|
---|
26 | API:
|
---|
27 | https://joel-costigliola.github.io/assertj/swing/api/index.html
|
---|
28 |
|
---|
29 | JUNIT:
|
---|
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
|
---|
38 | import org.junit.AfterClass;
|
---|
39 | import org.junit.After;
|
---|
40 | import org.junit.Assert;
|
---|
41 | import org.junit.Before;
|
---|
42 | import org.junit.BeforeClass;
|
---|
43 | import org.junit.Test;
|
---|
44 |
|
---|
45 | // GLI imports
|
---|
46 | import org.greenstone.gatherer.Gatherer;
|
---|
47 | import org.greenstone.gatherer.GathererProg; // main GLI class we'll be testing
|
---|
48 | import org.greenstone.gatherer.Dictionary; // access to display strings
|
---|
49 |
|
---|
50 | // Java GUI testing with AssertJ Swing
|
---|
51 | import org.assertj.swing.junit.testcase.AssertJSwingJUnitTestCase;
|
---|
52 | import org.assertj.swing.fixture.*;
|
---|
53 | import org.assertj.swing.core.*; // Robot
|
---|
54 | import org.assertj.swing.data.Index;
|
---|
55 |
|
---|
56 | // Selenium
|
---|
57 | import org.openqa.selenium.By;
|
---|
58 | import org.openqa.selenium.WebDriver;
|
---|
59 | import org.openqa.selenium.WebElement;
|
---|
60 | import org.openqa.selenium.firefox.FirefoxDriver;
|
---|
61 |
|
---|
62 | // Helper classes for selenium and AssertJ Swing tests
|
---|
63 | import org.greenstone.gsdl3.testing.GSTestingUtil;
|
---|
64 | import org.greenstone.gsdl3.testing.GSGUITestingUtil;
|
---|
65 |
|
---|
66 | // Java imports
|
---|
67 | import javax.swing.*;
|
---|
68 |
|
---|
69 | // static imports
|
---|
70 | import 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 | */
|
---|
75 | public class RunGLITest extends AssertJSwingJUnitTestCase {
|
---|
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(); // selenium
|
---|
80 |
|
---|
81 | private FrameFixture window;
|
---|
82 |
|
---|
83 | // Selenium
|
---|
84 | @Before
|
---|
85 | public void init()
|
---|
86 | {
|
---|
87 | //https://stackoverflow.com/questions/38676719/selenium-using-java-the-path-to-the-driver-executable-must-be-set-by-the-webdr
|
---|
88 | // GS3's build.xml would have set the webdriver.gecko.driver path System.Property to
|
---|
89 | // the location of Firefox' geckodriver executable when launching this test class already.
|
---|
90 | // So now we can continue to just do:
|
---|
91 | _driver.get(System.getProperty("SERVERURL"));
|
---|
92 | }
|
---|
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
|
---|
98 | @Override
|
---|
99 | protected void onSetUp() {
|
---|
100 | // Launch GLI and then get a ref to the launched app window:
|
---|
101 | runGLI();
|
---|
102 |
|
---|
103 |
|
---|
104 | // IMPORTANT, note the call to 'robot()': must use the Robot from AssertJSwingJUnitTestCase
|
---|
105 | //window = findFrame("GUIManager").using(robot());
|
---|
106 | window = GSGUITestingUtil.getGLIApplicationWindow(robot());
|
---|
107 | }
|
---|
108 |
|
---|
109 |
|
---|
110 | @Test
|
---|
111 | public void testGLIRunning() {
|
---|
112 |
|
---|
113 |
|
---|
114 | // waiting a few seconds for window, so we can see it
|
---|
115 | PAUSE(2);
|
---|
116 |
|
---|
117 | System.err.println("@@@ First test: GLI Running");
|
---|
118 |
|
---|
119 |
|
---|
120 | String expectedWindowTitle = Gatherer.PROGRAM_NAME;
|
---|
121 |
|
---|
122 |
|
---|
123 | String gatherPaneLabel = Dictionary.get("GUI.Gather");
|
---|
124 | System.err.println("@@@ Expecting label: " + gatherPaneLabel);
|
---|
125 |
|
---|
126 | System.err.println("@@@ Second test: that Gather panel is selected and has right title");
|
---|
127 |
|
---|
128 | JTabbedPaneFixture tab = window.tabbedPane("GUIManager.tab_pane");
|
---|
129 |
|
---|
130 |
|
---|
131 | tab.requireSelectedTab(Index.atIndex(1));
|
---|
132 | tab.requireTitle(gatherPaneLabel, Index.atIndex(1));
|
---|
133 |
|
---|
134 | // attempt to switch to enrich pane, uses static methods of GSGUITestingUtil
|
---|
135 | // through static import of that class
|
---|
136 | switchToPane(DOWNLOAD_PANE);
|
---|
137 |
|
---|
138 | // For testing, want GLI to be in librarian mode by default
|
---|
139 | changeUserMode("librarian");
|
---|
140 |
|
---|
141 | switchToPane(GATHER_PANE);
|
---|
142 |
|
---|
143 | loadCollection("lucene-jdbm-demo");
|
---|
144 |
|
---|
145 | // wait a couple of seconds again?
|
---|
146 | PAUSE(2);
|
---|
147 | closeCollection();
|
---|
148 |
|
---|
149 | createCollection("pinky", "Pinky was here", null);
|
---|
150 | closeCollection(); // collection must be closed in order to be deleted
|
---|
151 | deleteCollection("pinky");
|
---|
152 | // wait a few of seconds again?
|
---|
153 | PAUSE(2);
|
---|
154 |
|
---|
155 | exportCollection("GreenstoneMETS", "lucene-jdbm-demo");
|
---|
156 |
|
---|
157 | // Reset GLI to expert mode for regular GLI use
|
---|
158 | changeUserMode("expert");
|
---|
159 |
|
---|
160 | PAUSE(2);
|
---|
161 |
|
---|
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);
|
---|
166 | }
|
---|
167 |
|
---|
168 | // Selenium
|
---|
169 | // called once and only once: to quit the firefox driver geckodriver
|
---|
170 | @AfterClass
|
---|
171 | public static void destroy()
|
---|
172 | {
|
---|
173 | abortListener.unregister(); // aborting assertJ-swing GUI tests
|
---|
174 | _driver.quit();
|
---|
175 | }
|
---|
176 | }
|
---|