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

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

Success in next step: am able to use the shorter component access methods which access a by component by name to repeat the original sample testing code of launching GLI, checking it launched eventually and checking that the Gather pane is selected and has the expected label.

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