Changeset 32714


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.
Location:
gs3-extensions/testing/trunk/src
Files:
3 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}
  • gs3-extensions/testing/trunk/src/src/org/greenstone/gsdl3/testing/GSGUITestingUtil.java

    r32713 r32714  
    1616import org.greenstone.gatherer.GathererProg; // main GLI class we'll be testing
    1717import org.greenstone.gatherer.Dictionary; // access to display strings
     18
     19
     20// Java GUI testing with AssertJ Swing
     21import org.assertj.swing.junit.testcase.AssertJSwingJUnitTestCase;
     22import org.assertj.swing.fixture.*;
     23import org.assertj.swing.edt.GuiActionRunner;
     24import org.assertj.swing.core.Robot;
     25
     26
     27// static imports
     28import static org.assertj.swing.launcher.ApplicationLauncher.*;
     29import static org.assertj.swing.finder.WindowFinder.findFrame;
    1830
    1931/*
     
    4254    // can have easier access to those GUI components when testing here through their names   
    4355
    44     /************************ GENERAL *******************************/
    45 
    46     public static void setWindow(FrameFixture w) { window = w; }
    47    
     56    /****************************** APPLICATION  *******************************/
    4857    public static void PAUSE() {   
    4958    PAUSE(5);
     
    5867         e.printStackTrace();
    5968     }
    60     }
    61    
     69    }   
     70
     71    //public static void setWindow(FrameFixture w) { window = w; } // if we want to null window
     72   
     73    public static void runGLI() {
     74    //GathererProg frame = GuiActionRunner.execute(() -> new GathererProg());           
     75   
     76    // IMPORTANT, note the call to 'robot()': must use the Robot from AssertJSwingJUnitTestCase
     77    //window = new FrameFixture(robot(), frame);
     78    //window.show(); // shows the frame to test
     79
     80    // Instead, we'll be launching GLI and then getting a ref to the launched app window:
     81     
     82    // Launch GathererProg.java's main() method
     83    // See https://joel-costigliola.github.io/assertj/assertj-swing-launch.html
     84   
     85    String GSDLOS = System.getenv("GSDLOS");
     86    String GSDLHOME = System.getenv("GSDLHOME");
     87    String GSDL3HOME = System.getenv("GSDL3HOME");
     88    String GSDL3SRCHOME = System.getenv("GSDL3SRCHOME");
     89    application("org.greenstone.gatherer.GathererProg").withArgs(
     90                                 "-gsdl", GSDLHOME,
     91                                 "-gsdlos", GSDLOS,
     92                                 "-gsdl3", GSDL3HOME,
     93                                 "-gsdl3src", GSDL3SRCHOME,
     94                                 "-testing_mode").start();
     95    // The -testing_mode flag passed into GLI above is a special flag
     96    // that calls GLI's TestingPreparating.setNamesRecursively()
     97    // to help testing by calling setName() on GUI components.
     98    }
     99   
     100    public static void exitGLI() {
     101    openMenuItem("file", "exit");
     102    }
     103
     104    // Gets a ref to the main window (FrameFixture) of a running GLI
     105    public static FrameFixture getGLIApplicationWindow(Robot robot) {
     106    // locate and set the internal FrameFixture member variable 'window' and return a handle to it
     107    window = findFrame("GUIManager").using(robot); // GLI application JFrame's name is set to its classname, 'GUIManager'
     108
     109    // https://joel-costigliola.github.io/assertj/swing/api/index.html?org/assertj/swing/launcher/ApplicationLauncher.html
     110    // "To change the speed of a GUI test, you need to change the values of both delayBetweenEvents and eventPostingDelay."
     111    //robot.settings().delayBetweenEvents(50);
     112    //robot.settings().eventPostingDelay(2*SECOND); // annoying, after every click!
     113   
     114    return window;
     115    }
     116   
     117    /****************************** BASICS  *******************************/
     118
    62119   
    63120    //https://joel-costigliola.github.io/assertj/swing/api/org/assertj/swing/fixture/FrameFixture.html
     
    122179    }
    123180
    124     public static void exitGLI() {
    125     openMenuItem("file", "exit");
    126     PAUSE(5);
    127     }
    128181   
    129182    public static void closeCollection(){
     
    315368    }
    316369
     370
     371    /********************* GEMS ******************/
     372   
     373    // TODO:
     374    public static void runGEMS() {}
     375    public static void exitGEMS() {}
     376    public static FrameFixture getGEMSApplicationWindow(Robot robot) {
     377    // TODO: don't forget to set internal member variable called 'window' before returning it
     378    return window;
     379    }
     380   
    317381    // Moving these working bits of code here, in case I can use them to right
    318382    // general get methods that make use of the GenericTypeMatcher method of accessing components
Note: See TracChangeset for help on using the changeset viewer.