Changeset 32684 for gs3-extensions


Ignore:
Timestamp:
2018-12-13T22:44:57+13:00 (5 years ago)
Author:
ak19
Message:

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:
1 edited

Legend:

Unmodified
Added
Removed
  • gs3-extensions/testing/trunk/src/src/gstests/tutorials/RunGLITest.java

    r32683 r32684  
    1919import org.junit.Before;
    2020import org.junit.Test;
    21 
     21import org.assertj.swing.data.Index;
     22     
     23import org.greenstone.gatherer.Gatherer;
    2224import org.greenstone.gatherer.GathererProg; // main GLI class we'll be testing
     25import org.greenstone.gatherer.Dictionary; // access to display strings
    2326
    2427import org.assertj.swing.junit.testcase.AssertJSwingJUnitTestCase;
    25 import org.assertj.swing.fixture.FrameFixture;
     28import org.assertj.swing.fixture.*;
    2629import org.assertj.swing.edt.GuiActionRunner;
    27 
     30import org.assertj.swing.core.*;
     31import javax.swing.*;
     32     
    2833// static imports
    2934import static org.assertj.swing.launcher.ApplicationLauncher.*;
    30 
     35import static org.assertj.swing.finder.WindowFinder.findFrame;
    3136
    3237public class RunGLITest extends AssertJSwingJUnitTestCase {
    33   private FrameFixture window;
    34 
    35   @Override
    36   protected void onSetUp() {
    37     GathererProg frame = GuiActionRunner.execute(() -> new GathererProg());
    38     // IMPORTANT: note the call to 'robot()'
    39     // we must use the Robot from AssertJSwingJUnitTestCase
     38    private FrameFixture window;
    4039   
    41     //window = new FrameFixture(robot(), frame);
    42     //window.show(); // shows the frame to test
    43 
    44     // Launch GathererProg.java's main() method
    45     // See https://joel-costigliola.github.io/assertj/assertj-swing-launch.html
    46 
    47     String GSDLOS = System.getenv("GSDLOS");
    48     String GSDLHOME = System.getenv("GSDLHOME");
    49     String GSDL3HOME = System.getenv("GSDL3HOME");
    50     String GSDL3SRCHOME = System.getenv("GSDL3SRCHOME");
    51     application("org.greenstone.gatherer.GathererProg").withArgs(
     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(
    5257                                 "-gsdl", GSDLHOME,
    5358                                 "-gsdlos", GSDLOS,
    5459                                 "-gsdl3", GSDL3HOME,
    5560                                 "-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));
    56118  }
    57 
    58   @Test
    59   public void shouldCopyTextInLabelWhenClickingButton() {
    60       System.err.println("@@@ First test");
    61       //window.textBox("textToCopy").enterText("Some random text");
    62       //window.button("copyButton").click();
    63       //window.label("copiedText").requireText("Some random text");
    64   }
     119 
     120   
    65121}
Note: See TracChangeset for help on using the changeset viewer.