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

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

My first tests are working now: I can see GLI launch and have tested that it the Gather pane is selected and has the right title. Must study JUnit more. If I instantiate GLI in the setUp() function, it's instantiated for EACH TEST and teardown() is called for each test too. I just want GLI to launch once, run each test in sequence and then quit. At the moment that doesn't work out and I have to do all my current basic tests in one test function.

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