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

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

GLI GUI testing can now successfully access menu and submenu items, e.g. successfully displays the open collection dialog. Next step is to actually implement the opening of a selected collection.

File size: 5.2 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
16Got AssertJ Swing from Maven Central Repository:
17https://search.maven.org/search?q=assertj-swing-junit
18-> http://central.maven.org/maven2/org/assertj/assertj-core/3.8.0/
19More jar files: http://repo1.maven.org/maven2/org/assertj/
20- http://repo1.maven.org/maven2/org/assertj/assertj-swing/3.8.0/
21- http://central.maven.org/maven2/org/assertj/assertj-core/3.8.0/
22
23API:
24https://joel-costigliola.github.io/assertj/swing/api/index.html
25
26JUNIT:
27- https://junit.org/junit4/faq.html#atests_2
28 How do I use a test fixture?
29- https://junit.org/junit4/faq.html#organize_3
30 How can I run setUp() and tearDown() code once for all of my tests?
31
32*/
33
34// Junit imports
35import org.junit.AfterClass;
36import org.junit.Assert;
37import org.junit.Before;
38import org.junit.Test;
39
40// GLI imports
41import org.greenstone.gatherer.Gatherer;
42import org.greenstone.gatherer.GathererProg; // main GLI class we'll be testing
43import org.greenstone.gatherer.Dictionary; // access to display strings
44
45// Java GUI testing with AssertJ Swing
46import org.assertj.swing.junit.testcase.AssertJSwingJUnitTestCase;
47import org.assertj.swing.fixture.*;
48import org.assertj.swing.edt.GuiActionRunner;
49import org.assertj.swing.core.*;
50import org.assertj.swing.data.Index;
51
52// Selenium
53import org.openqa.selenium.By;
54import org.openqa.selenium.WebDriver;
55import org.openqa.selenium.WebElement;
56import org.openqa.selenium.firefox.FirefoxDriver;
57
58// Helper classes for selenium and AssertJ Swing tests
59import org.greenstone.gsdl3.testing.GSTestingUtil;
60import org.greenstone.gsdl3.testing.GSGUITestingUtil;
61
62// Java imports
63import javax.swing.*;
64
65
66
67// static imports
68import static org.assertj.swing.launcher.ApplicationLauncher.*;
69import static org.assertj.swing.finder.WindowFinder.findFrame;
70
71import static org.greenstone.gsdl3.testing.GSGUITestingUtil.*;
72
73public class RunGLITest extends AssertJSwingJUnitTestCase {
74
75 private static WebDriver _driver = new FirefoxDriver(); // selenium
76
77 private FrameFixture window;
78
79 // Selenium
80 @Before
81 public void init()
82 {
83 //https://stackoverflow.com/questions/38676719/selenium-using-java-the-path-to-the-driver-executable-must-be-set-by-the-webdr
84 // GS3's build.xml would have set the webdriver.gecko.driver path System.Property to
85 // the location of Firefox' geckodriver executable when launching this test class already.
86 // So now we can continue to just do:
87 _driver.get(System.getProperty("SERVERURL"));
88 }
89
90 @Override
91 protected void onSetUp() {
92 GathererProg frame = GuiActionRunner.execute(() -> new GathererProg());
93 // IMPORTANT: note the call to 'robot()'
94 // we must use the Robot from AssertJSwingJUnitTestCase
95
96 //window = new FrameFixture(robot(), frame);
97 //window.show(); // shows the frame to test
98
99 // Launch GathererProg.java's main() method
100 // See https://joel-costigliola.github.io/assertj/assertj-swing-launch.html
101
102 String GSDLOS = System.getenv("GSDLOS");
103 String GSDLHOME = System.getenv("GSDLHOME");
104 String GSDL3HOME = System.getenv("GSDL3HOME");
105 String GSDL3SRCHOME = System.getenv("GSDL3SRCHOME");
106 application("org.greenstone.gatherer.GathererProg").withArgs(
107 "-gsdl", GSDLHOME,
108 "-gsdlos", GSDLOS,
109 "-gsdl3", GSDL3HOME,
110 "-gsdl3src", GSDL3SRCHOME,
111 "-testing_mode").start();
112 }
113
114
115 @Test
116 public void testGLIRunning() {
117
118
119 // waiting 2 seconds for window, so we can see it
120 try{
121 Thread.sleep(5000);
122 } catch(Exception e) {
123 e.printStackTrace();
124 }
125
126
127 System.err.println("@@@ First test: GLI Running");
128
129
130 String expectedWindowTitle = Gatherer.PROGRAM_NAME;
131
132 window = findFrame("GUIManager").using(robot());
133
134 String gatherPaneLabel = Dictionary.get("GUI.Gather");
135 System.err.println("@@@ Expecting label: " + gatherPaneLabel);
136
137 System.err.println("@@@ Second test: that Gather panel is selected and has right title");
138
139 JTabbedPaneFixture tab = window.tabbedPane("GUIManager.tab_pane");
140
141
142 tab.requireSelectedTab(Index.atIndex(1));
143 tab.requireTitle(gatherPaneLabel, Index.atIndex(1));
144
145 // attempt to switch to enrich pane, uses static methods of GSGUITestingUtil
146 // through static import of that class
147 switchToPane(window, DOWNLOAD_PANE);
148
149 loadCollection(window, "lucene-jdbm-demo");
150
151 // wait a couple of seconds again?
152 try{
153 Thread.sleep(5000);
154 } catch(Exception e) {
155 e.printStackTrace();
156 }
157
158
159 }
160
161 // Selenium
162 // called once and only once: to quit the firefox driver geckodriver
163 @AfterClass
164 public static void destroy()
165 {
166 _driver.quit();
167 }
168}
Note: See TracBrowser for help on using the repository browser.