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

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

Some cleanup and shifting commented out useful code about

File size: 4.8 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
71public class RunGLITest extends AssertJSwingJUnitTestCase {
72
73 private static WebDriver _driver = new FirefoxDriver(); // selenium
74
75 private FrameFixture window;
76
77 // Selenium
78 @Before
79 public void init()
80 {
81 //https://stackoverflow.com/questions/38676719/selenium-using-java-the-path-to-the-driver-executable-must-be-set-by-the-webdr
82 // GS3's build.xml would have set the webdriver.gecko.driver path System.Property to
83 // the location of Firefox' geckodriver executable when launching this test class already.
84 // So now we can continue to just do:
85 _driver.get(System.getProperty("SERVERURL"));
86 }
87
88 @Override
89 protected void onSetUp() {
90 GathererProg frame = GuiActionRunner.execute(() -> new GathererProg());
91 // IMPORTANT: note the call to 'robot()'
92 // we must use the Robot from AssertJSwingJUnitTestCase
93
94 //window = new FrameFixture(robot(), frame);
95 //window.show(); // shows the frame to test
96
97 // Launch GathererProg.java's main() method
98 // See https://joel-costigliola.github.io/assertj/assertj-swing-launch.html
99
100 String GSDLOS = System.getenv("GSDLOS");
101 String GSDLHOME = System.getenv("GSDLHOME");
102 String GSDL3HOME = System.getenv("GSDL3HOME");
103 String GSDL3SRCHOME = System.getenv("GSDL3SRCHOME");
104 application("org.greenstone.gatherer.GathererProg").withArgs(
105 "-gsdl", GSDLHOME,
106 "-gsdlos", GSDLOS,
107 "-gsdl3", GSDL3HOME,
108 "-gsdl3src", GSDL3SRCHOME,
109 "-testing_mode").start();
110 }
111
112
113 @Test
114 public void testGLIRunning() {
115
116
117 // waiting 2 seconds for window, so we can see it
118 try{
119 Thread.sleep(5000);
120 } catch(Exception e) {
121 e.printStackTrace();
122 }
123
124
125 System.err.println("@@@ First test: GLI Running");
126
127
128 String expectedWindowTitle = Gatherer.PROGRAM_NAME;
129
130 window = findFrame("GUIManager").using(robot());
131
132 String gatherPaneLabel = Dictionary.get("GUI.Gather");
133 System.err.println("@@@ Expecting label: " + gatherPaneLabel);
134
135 System.err.println("@@@ Second test: that Gather panel is selected and has right title");
136
137 JTabbedPaneFixture tab = window.tabbedPane("GUIManager.tab_pane");
138
139
140 tab.requireSelectedTab(Index.atIndex(1));
141 tab.requireTitle(gatherPaneLabel, Index.atIndex(1));
142 }
143
144 // Selenium
145 // called once and only once: to quit the firefox driver geckodriver
146 @AfterClass
147 public static void destroy()
148 {
149 _driver.quit();
150 }
151}
Note: See TracBrowser for help on using the repository browser.