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

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

Minor changes in the comments section before I attempt to merge selenium testing with assertj swing testing (not sure if possible, but will try)

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*/
26
27import org.junit.AfterClass;
28import org.junit.Assert;
29import org.junit.Before;
30import org.junit.Test;
31import org.assertj.swing.data.Index;
32
33import org.greenstone.gatherer.Gatherer;
34import org.greenstone.gatherer.GathererProg; // main GLI class we'll be testing
35import org.greenstone.gatherer.Dictionary; // access to display strings
36
37import org.assertj.swing.junit.testcase.AssertJSwingJUnitTestCase;
38import org.assertj.swing.fixture.*;
39import org.assertj.swing.edt.GuiActionRunner;
40import org.assertj.swing.core.*;
41import javax.swing.*;
42
43// static imports
44import static org.assertj.swing.launcher.ApplicationLauncher.*;
45import static org.assertj.swing.finder.WindowFinder.findFrame;
46
47public class RunGLITest extends AssertJSwingJUnitTestCase {
48 private FrameFixture window;
49
50 @Override
51 protected void onSetUp() {
52 GathererProg frame = GuiActionRunner.execute(() -> new GathererProg());
53 // IMPORTANT: note the call to 'robot()'
54 // we must use the Robot from AssertJSwingJUnitTestCase
55
56 //window = new FrameFixture(robot(), frame);
57 //window.show(); // shows the frame to test
58
59 // Launch GathererProg.java's main() method
60 // See https://joel-costigliola.github.io/assertj/assertj-swing-launch.html
61
62 String GSDLOS = System.getenv("GSDLOS");
63 String GSDLHOME = System.getenv("GSDLHOME");
64 String GSDL3HOME = System.getenv("GSDL3HOME");
65 String GSDL3SRCHOME = System.getenv("GSDL3SRCHOME");
66 application("org.greenstone.gatherer.GathererProg").withArgs(
67 "-gsdl", GSDLHOME,
68 "-gsdlos", GSDLOS,
69 "-gsdl3", GSDL3HOME,
70 "-gsdl3src", GSDL3SRCHOME).start();
71 }
72
73
74 @Test
75 public void testGLIRunning() {
76
77
78 // waiting 2 seconds for window, so we can see it
79 try{
80 Thread.sleep(5000);
81 } catch(Exception e) {
82 e.printStackTrace();
83 }
84
85
86 System.err.println("@@@ First test: GLI Running");
87
88
89 String expectedWindowTitle = Gatherer.PROGRAM_NAME;
90
91
92 // https://joel-costigliola.github.io/assertj/assertj-swing-launch.html
93 window = findFrame(new GenericTypeMatcher<JFrame>(JFrame.class) {
94 protected boolean isMatching(JFrame window) {
95 return window.getTitle().trim().startsWith(expectedWindowTitle)
96 && window.isShowing();
97 }
98 }).using(robot());
99
100
101 String gatherPaneLabel = Dictionary.get("GUI.Gather");
102 System.err.println("@@@ Expecting label: " + gatherPaneLabel);
103
104 System.err.println("@@@ Second test: that Gather panel is selected and has right title");
105
106 /*GenericTypeMatcher<JTabbedPane> textMatcher = new GenericTypeMatcher<JTabbedPane>(JTabbedPane.class) {
107 @Override protected boolean isMatching(JTabbedPane tabPane) {
108 int index = GuiActionRunner.execute(() -> tabPane.getSelectedIndex());
109 //int index = tabPane.getSelectedIndex();
110 String selectedTabTitle = GuiActionRunner.execute(() -> tabPane.getTitleAt(index));
111 System.err.println("### GOT TITLE: " + selectedTabTitle);
112 return gatherPaneLabel.equals(selectedTabTitle);
113 }
114 };
115 */
116 JTabbedPaneFixture tab = window.tabbedPane(new GenericTypeMatcher<JTabbedPane>(JTabbedPane.class) {
117 @Override protected boolean isMatching(JTabbedPane tabPane) {
118 System.err.println("### trying for match");
119 //int index = GuiActionRunner.execute(() -> tabPane.getSelectedIndex());
120 int index = tabPane.getSelectedIndex();
121 String selectedTabTitle = tabPane.getTitleAt(index); //GuiActionRunner.execute(() -> tabPane.getTitleAt(index));
122 System.err.println("### GOT TITLE: " + selectedTabTitle);
123 return gatherPaneLabel.equals(selectedTabTitle);
124 }
125 });
126 tab.requireSelectedTab(Index.atIndex(1));
127 tab.requireTitle(gatherPaneLabel, Index.atIndex(1));
128 }
129
130
131}
Note: See TracBrowser for help on using the repository browser.