source: gs3-extensions/testing/trunk/src/src/gstests/tutorials/RunGLITest.java@ 32705

Last change on this file since 32705 was 32705, checked in by ak19, 5 years ago
  1. Implemented (and testing as I implement) more of the GSGUITestingUtil helper functions. Most of the File Menu is done. Unfortunately can't yet commit the EDT corrections in GLI as at least one of them requires a more complex solution, possibly with a SwingWorker as there's conflict with the ProgressBar. 2. infrastructure for JUnit reports. Not working yet despite the inclusion of necessary jar, will investigate this later.
File size: 6.0 KB
Line 
1package gstests.tutorials;
2
3/*
4Using AssertJ Swing to do Java GUI testing (of swing classes)
5- Obtain from: https://search.maven.org/search?q=assertj-swing-junit
6- Documentation: https://joel-costigliola.github.io/assertj/assertj-swing.html
7
8Alternatives to AssertJSwing (googled: automate java interface testing) suggested at
9https://sqa.stackexchange.com/questions/18554/open-source-tools-for-automation-of-java-gui-application-testing
10
11Event Dispatch Thread (EDT) pages:
12- https://joel-costigliola.github.io/assertj/assertj-swing-edt.html
13- https://web.archive.org/web/20120526191520/http://alexruiz.developerblogs.com/?p=160
14- https://web.archive.org/web/20130218063544/http://weblogs.java.net/blog/alexfromsun/archive/2006/02/debugging_swing.html
15- https://stackoverflow.com/questions/2829364/java-difference-between-swingworker-and-swingutilities-invokelater
16
17Got AssertJ Swing from Maven Central Repository:
18https://search.maven.org/search?q=assertj-swing-junit
19-> http://central.maven.org/maven2/org/assertj/assertj-core/3.8.0/
20More jar files: http://repo1.maven.org/maven2/org/assertj/
21- http://repo1.maven.org/maven2/org/assertj/assertj-swing/3.8.0/
22- http://central.maven.org/maven2/org/assertj/assertj-core/3.8.0/
23
24API:
25https://joel-costigliola.github.io/assertj/swing/api/index.html
26
27JUNIT:
28- https://junit.org/junit4/faq.html#atests_2
29 How do I use a test fixture?
30- https://junit.org/junit4/faq.html#organize_3
31 How can I run setUp() and tearDown() code once for all of my tests?
32
33*/
34
35// Junit imports
36import org.junit.AfterClass;
37import org.junit.Assert;
38import org.junit.Before;
39import org.junit.Test;
40
41// GLI imports
42import org.greenstone.gatherer.Gatherer;
43import org.greenstone.gatherer.GathererProg; // main GLI class we'll be testing
44import org.greenstone.gatherer.Dictionary; // access to display strings
45
46// Java GUI testing with AssertJ Swing
47import org.assertj.swing.junit.testcase.AssertJSwingJUnitTestCase;
48import org.assertj.swing.fixture.*;
49import org.assertj.swing.edt.GuiActionRunner;
50import org.assertj.swing.core.*;
51import org.assertj.swing.data.Index;
52
53// Selenium
54import org.openqa.selenium.By;
55import org.openqa.selenium.WebDriver;
56import org.openqa.selenium.WebElement;
57import org.openqa.selenium.firefox.FirefoxDriver;
58
59// Helper classes for selenium and AssertJ Swing tests
60import org.greenstone.gsdl3.testing.GSTestingUtil;
61import org.greenstone.gsdl3.testing.GSGUITestingUtil;
62
63// Java imports
64import javax.swing.*;
65
66
67
68// static imports
69import static org.assertj.swing.launcher.ApplicationLauncher.*;
70import static org.assertj.swing.finder.WindowFinder.findFrame;
71
72import static org.greenstone.gsdl3.testing.GSGUITestingUtil.*;
73
74public class RunGLITest extends AssertJSwingJUnitTestCase {
75
76 private static WebDriver _driver = new FirefoxDriver(); // selenium
77
78 private FrameFixture window;
79
80 // Selenium
81 @Before
82 public void init()
83 {
84 //https://stackoverflow.com/questions/38676719/selenium-using-java-the-path-to-the-driver-executable-must-be-set-by-the-webdr
85 // GS3's build.xml would have set the webdriver.gecko.driver path System.Property to
86 // the location of Firefox' geckodriver executable when launching this test class already.
87 // So now we can continue to just do:
88 _driver.get(System.getProperty("SERVERURL"));
89 }
90
91 @Override
92 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
96
97 //window = new FrameFixture(robot(), frame);
98 //window.show(); // shows the frame to test
99
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();
113 }
114
115
116 @Test
117 public void testGLIRunning() {
118
119
120 // waiting a few seconds for window, so we can see it
121 PAUSE(2);
122
123
124 System.err.println("@@@ First test: GLI Running");
125
126
127 String expectedWindowTitle = Gatherer.PROGRAM_NAME;
128
129 window = findFrame("GUIManager").using(robot());
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(window, DOWNLOAD_PANE);
145
146 // For testing, want GLI to be in librarian mode by default
147 changeUserMode(window, "librarian");
148
149 switchToPane(window, GATHER_PANE);
150
151 loadCollection(window, "lucene-jdbm-demo");
152
153 // wait a couple of seconds again?
154 PAUSE(2);
155 closeCollection(window);
156
157 createCollection(window, "pinky", "Pinky was here", null);
158 closeCollection(window); // collection must be closed in order to be deleted
159 deleteCollection(window, "pinky");
160 // wait a few of seconds again?
161 PAUSE(2);
162
163 exportCollection(window, "GreenstoneMETS", "lucene-jdbm-demo");
164
165 // Reset GLI to expert mode for regular GLI use
166 changeUserMode(window, "expert");
167
168 PAUSE(5);
169 //exitGLI(window);
170
171 switchToPane(window, GATHER_PANE);
172 }
173
174 // Selenium
175 // called once and only once: to quit the firefox driver geckodriver
176 @AfterClass
177 public static void destroy()
178 {
179 _driver.quit();
180
181 }
182}
Note: See TracBrowser for help on using the repository browser.