Ignore:
Timestamp:
2018-12-18T21:22:40+13:00 (5 years ago)
Author:
ak19
Message:
  1. window (the main app windows of running GLI, or later GEMS) is now instantiated and a handle kept to it inside GSGUITestingUtil after all. The test class now calls GSGUITestingUtil.runGLI() followed by getApplicationWindow() to launch GLI and get a hold of its window and then sets its own private reference to it. 2. Added an abort listener to stop the running test suite on assertj-swing's default abort key combination of Ctrl+Shift+A. 3. More cleaning up.
File:
1 edited

Legend:

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

    r32713 r32714  
    22
    33/*
     4Ctrl+Shift+A TO ABORT A RUNNING GUI-TEST CYCLE (won't abort Selenium/browser tests)
     5
    46Using AssertJ Swing to do Java GUI testing (of swing classes)
    57- Obtain from: https://search.maven.org/search?q=assertj-swing-junit
     
    3537// Junit imports
    3638import org.junit.AfterClass;
     39import org.junit.After;
    3740import org.junit.Assert;
    3841import org.junit.Before;
     42import org.junit.BeforeClass;
    3943import org.junit.Test;
    4044
     
    4751import org.assertj.swing.junit.testcase.AssertJSwingJUnitTestCase;
    4852import org.assertj.swing.fixture.*;
    49 import org.assertj.swing.edt.GuiActionRunner;
    50 import org.assertj.swing.core.*;
     53import org.assertj.swing.core.*; // Robot
    5154import org.assertj.swing.data.Index;
    5255
     
    6467import javax.swing.*;
    6568
    66 
    67      
    6869// static imports
    69 import static org.assertj.swing.launcher.ApplicationLauncher.*;
    70 import static org.assertj.swing.finder.WindowFinder.findFrame;
    71 
    7270import static org.greenstone.gsdl3.testing.GSGUITestingUtil.*;
    7371
     72/**
     73 * Class that will eventually go through all the Greenstone3 tutorials by running GLI and GEMS.
     74 */
    7475public class RunGLITest extends AssertJSwingJUnitTestCase {
    75 
     76    // For aborting running test suite, with Ctrl+Shift+A by default
     77    // https://joel-costigliola.github.io/assertj/assertj-swing-running.html
     78    private static EmergencyAbortListener abortListener = EmergencyAbortListener.registerInToolkit();   
    7679    private static WebDriver _driver = new FirefoxDriver(); // selenium
    7780   
     
    8992    }
    9093   
     94
     95    // assertj-swing
     96    // As init() above, onSetUp() gets called before every test method too,
     97    // but is overridden from assertj-swing base class
    9198    @Override
    9299    protected void onSetUp() {
    93     GathererProg frame = GuiActionRunner.execute(() -> new GathererProg());           
    94     // IMPORTANT: note the call to 'robot()'
    95     // we must use the Robot from AssertJSwingJUnitTestCase
     100    // Launch GLI and then get a ref to the launched app window:
     101    runGLI();
    96102   
    97     //window = new FrameFixture(robot(), frame);
    98     //window.show(); // shows the frame to test
    99103   
    100     // Launch GathererProg.java's main() method
    101     // See https://joel-costigliola.github.io/assertj/assertj-swing-launch.html
    102    
    103     String GSDLOS = System.getenv("GSDLOS");
    104     String GSDLHOME = System.getenv("GSDLHOME");
    105     String GSDL3HOME = System.getenv("GSDL3HOME");
    106     String GSDL3SRCHOME = System.getenv("GSDL3SRCHOME");
    107     application("org.greenstone.gatherer.GathererProg").withArgs(
    108                                  "-gsdl", GSDLHOME,
    109                                  "-gsdlos", GSDLOS,
    110                                  "-gsdl3", GSDL3HOME,
    111                                  "-gsdl3src", GSDL3SRCHOME,
    112                                  "-testing_mode").start();
     104    // IMPORTANT, note the call to 'robot()': must use the Robot from AssertJSwingJUnitTestCase
     105    //window = findFrame("GUIManager").using(robot());
     106    window = GSGUITestingUtil.getGLIApplicationWindow(robot());
    113107    }
    114108   
     
    117111  public void testGLIRunning() {
    118112
    119      
     113   
    120114      // waiting a few seconds for window, so we can see it
    121       PAUSE(2);
    122      
     115      PAUSE(2);     
    123116   
    124117      System.err.println("@@@ First test: GLI Running");
     
    127120      String expectedWindowTitle = Gatherer.PROGRAM_NAME;
    128121
    129       window = findFrame("GUIManager").using(robot());
    130      
    131       GSGUITestingUtil.setWindow(window); // set this first before calling any of Util's other methods
    132      
     122           
    133123      String gatherPaneLabel = Dictionary.get("GUI.Gather");
    134124      System.err.println("@@@ Expecting label: " + gatherPaneLabel);
     
    168158      changeUserMode("expert");
    169159     
    170       PAUSE(5);
    171       //exitGLI();
     160      PAUSE(2);     
    172161     
    173162      switchToPane(GATHER_PANE);
     163
     164      //exitGLI(); //System.exit() on GLI won't allow quit to be called on Selenium's web _driver, why?
     165      PAUSE(3);
    174166  }
    175167
     
    179171    public static void destroy()
    180172    {
     173    abortListener.unregister(); // aborting assertJ-swing GUI tests
    181174    _driver.quit();
    182    
    183175    }
    184176}
Note: See TracChangeset for help on using the changeset viewer.