Changeset 39018


Ignore:
Timestamp:
2024-05-13T22:17:12+12:00 (10 days ago)
Author:
anupama
Message:
  1. I need to be able to startup GLI and exit it for any given GLI GUI test, e.g. some tutorials should be able to startup GLI fresh or quit GLI and do something and reopen it. However, GLI > File > exit calls System.exit() which has the effect of exiting the outer JUnit tests too. And I first tried in different ways to solve this on the JUnit side with security managers and everything and it wasn't working. The solution was to fix up GLI's GUIManager and Gatherer: GUIManager on TestingPreparation.TEST_MODE being true, will set the GGLI frame to DISPOSE_ON_CLOSE (which is everything but System.exit) and Gatherer.exit() will not call System.exit() if TestingPreparation.TEST_MODE is true. This seems to have at last allowed me to call exitGLI just fine in the testing code. I'm not yet committing the GLI source code changes as both GUIManager and Gatherer have other (Event Dispatch Thread) related changes that I still have to run by Dr Bainbridge or Kathy at least, before I can feel confident I haven't caused problems in GLI. 2. The RunGLITest.java file has the links to the main reading I did in the comments section at the start of the file. So the README now refers to that.
Location:
gs3-extensions/testing/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • gs3-extensions/testing/trunk/README_2024

    r39017 r39018  
    1 ---------------------------
    2 Notes written 2024:
    3 ---------------------------
    4 I'm not sure what I read on junits, assertj swing and (if anything) on selenium to start off the automated gli testing work back in 2018, but here's what I can gather from current code.
     1-------------------------------------------------------------
     2README Notes written 2024
     3(AssertJ Swing GLI GUI testing groundwork laid in 2018-2019)
     4-------------------------------------------------------------
    55
    6 But the following may be useful websites
     6Sections
     7I Code Layout
     8II Background Reading
     9III Compiling and Running
     10
     11
     12-------------------
     13CODE LAYOUT
     14-------------------
     15- ext/testing/src/src/org/greenstone/gsdl3/testing/GSGUIUtil.java (Selenium, browser testing helper functions, needs revisiting in 2024)
     16- ext/testing/src/src/org/greenstone/gsdl3/testing/GSGUITestingUtil.java (AssertJ Swing, GUI testing helper functions)
     17- ext/testing/src/src/gstests/tutorials/RunGLITest.java (tests, rudimentary stage of testing the basic GUI helper functions above)
     18
     19
     20-------------------
     21BACKGROUND READING
     22-------------------
     23See the comments section at the top of ext/testing/src/src/gstests/tutorials/RunGLITest.java
     24It lists the URLs and reading that I went through pertaining to junits, assertj swing and (if anything) on selenium to start off the automated gli testing work back in 2018.
     25
     26I can further gather the following from the current code.
     27
     28The following may be useful websites
    729- interspersed throughout our code that uses assert swing, I find I'd added references to this website: https://joel-costigliola.github.io/assertj/assertj-swing-basics.html
    830
     
    1234- there's also the older wiki page by Sam that has his own work (not yet incorporated): https://wiki.greenstone.org/doku.php?id=internal:gs3_automated_testing
    1335
    14 
     36----------------------
     37COMPILING AND RUNNING
     38----------------------
    15390. Have a fresh GS3, preferrably a code checkout from SVN so that you can tweak the code on any errors.
    1640
  • gs3-extensions/testing/trunk/src/src/gstests/tutorials/RunGLITest.java

    r39016 r39018  
    6868import javax.swing.*;
    6969
    70 // static imports
     70// static imports - call static functions without class as namespace qualifier
    7171import static org.greenstone.gsdl3.testing.GSGUITestingUtil.*;
    7272
     
    8282    private FrameFixture window;
    8383
     84    // https://stackoverflow.com/questions/50815329/close-application-after-test-without-test-failure-using-assertj
     85    // https://stackoverflow.com/questions/23139321/testing-java-gui-application-closing-window-during-test-ends-test-suite
     86    // https://stackoverflow.com/questions/5401281/preventing-system-exit-from-api
     87    /*
     88    @BeforeClass
     89    public static void initOnce() {
     90    // to prevent system.exit from causing issues
     91    org.assertj.swing.security.NoExitSecurityManagerInstaller.installNoExitSecurityManager();   
     92    }
     93    */
    8494    // Selenium
    8595    @Before
     
    99109    @Override
    100110    protected void onSetUp() {
     111    System.err.println("#### onSetUp called - running GLI");
    101112    // Launch GLI and then get a ref to the launched app window:
    102113    runGLI();
     
    111122  @Test
    112123  public void testGLIRunning() {
    113 
    114    
    115124      // waiting a few seconds for window, so we can see it
    116       PAUSE(2);     
    117    
     125      PAUSE(2);
     126
    118127      System.err.println("@@@ First test: GLI Running");
    119 
    120       /*
    121       // See "Testing long duration tasks" at
    122       // https://joel-costigliola.github.io/assertj/assertj-swing-lookup.html   
    123       DialogFixture lockfileDialog = WindowFinder.findDialog("LockFileDialog").using(robot());//new DialogFixture(robot(), "LockFileDialog"); //window.dialog("LockFileDialog", Timeout.timeout(1));
    124       if(lockfileDialog != null) {
    125       lockfileDialog.click(); // bring to foreground in case JProgressBar hides it
    126       lockfileDialog.button("LockFileDialog.ok_button").click();     
    127       }
    128       */
     128     
    129129      // steal any collection lock that may or may not presents itself within param seconds
    130130      stealAnyCollectionLock(1);
     
    150150      // For testing, want GLI to be in librarian mode by default
    151151      changeUserMode("librarian");
    152 
     152     
    153153      switchToPane(GATHER_PANE);
    154154     
     
    166166     
    167167      exportCollection("GreenstoneMETS", "lucene-jdbm-demo");
    168 
     168     
    169169      // Reset GLI to expert mode for regular GLI use
    170170      changeUserMode("expert");
     
    172172      PAUSE(2);     
    173173     
    174       switchToPane(GATHER_PANE);
    175 
    176       //exitGLI(); //System.exit() on GLI won't allow quit to be called on Selenium's web _driver, why?
     174      switchToPane(GATHER_PANE);     
     175
     176      exitGLI(); //System.exit() on GLI won't allow quit to be called on Selenium's web _driver, why? Because System.exit exited the JUnit tests too
     177     
    177178      PAUSE(3);
    178179  }
     180
     181
     182    @Test
     183    public void tutorial_tests() {
     184    /*
     185    // Preliminaries
     186    // waiting a few seconds for window, so we can see GLI running
     187    PAUSE(2);
     188   
     189    System.err.println("@@@ First test: GLI Running");
     190   
     191    // steal any collection lock that may or may not presents itself within param seconds
     192    stealAnyCollectionLock(1);
     193    switchToPane(GATHER_PANE);
     194
     195    // dummy tests
     196    testGLIRunning();
     197    */
     198    // First tutorial
     199    simpleHTML();
     200   
     201    }
    179202
    180203    // Selenium
     
    185208    abortListener.unregister(); // aborting assertJ-swing GUI tests
    186209    _driver.quit();
    187     }
     210    //After exiting your application uninstall the no exit security manager
     211    //org.assertj.swing.security.NoExitSecurityManagerInstaller.installNoExitSecurityManager().uninstall();
     212    }
     213
     214    /****************************** TUTORIAL FUNCTIONS  *******************************/
     215    // Tutorial functions: regular methods called by JUnit at-Test methods in sequence
     216    // to ensure sequential ordering of tests
     217    public void simpleHTML() {
     218    System.err.println("@@@ Tutorial 1: simple HTML"); 
     219    stealAnyCollectionLock(1);
     220    switchToPane(GATHER_PANE);
     221    changeUserMode("librarian");
     222    }
     223   
    188224}
  • gs3-extensions/testing/trunk/src/src/org/greenstone/gsdl3/testing/GSGUITestingUtil.java

    r39016 r39018  
    113113    // Gets a ref to the main window (FrameFixture) of a running GLI
    114114    public static FrameFixture getGLIApplicationWindow(Robot robotParam) {
     115    return getGLIApplicationWindow(robotParam, -1);
     116    }
     117
     118    // Gets a ref to the main window (FrameFixture) of a running GLI
     119    public static FrameFixture getGLIApplicationWindow(Robot robotParam, int waitTime) {
    115120    GSGUITestingUtil.robot = robotParam; // store
    116    
     121
    117122    // locate and set the internal FrameFixture member variable 'window' and return a handle to it
    118     window = findFrame("GUIManager").using(robot); // GLI application JFrame's name is set to its classname, 'GUIManager'
     123    if(waitTime <= 0) {
     124        window = findFrame("GUIManager").using(robot); // GLI application JFrame's name is set to its classname, 'GUIManager'
     125    } else {   
     126        window = findFrame("GUIManager").withTimeout(waitTime*SECOND).using(robot);
     127    }
    119128
    120129    // https://joel-costigliola.github.io/assertj/swing/api/index.html?org/assertj/swing/launcher/ApplicationLauncher.html
     
    295304    //steal any lock
    296305    //PAUSE(3);
    297     // See "Testing long duration tasks" at
    298     // https://joel-costigliola.github.io/assertj/assertj-swing-lookup.html
    299 
    300         /*
    301     try {
    302         DialogFixture lockfileDialog = findDialog("LockFileDialog").using(robot);//window.dialog("LockFileDialog");
    303         if(lockfileDialog != null) {
    304         lockfileDialog.click(); // bring to foreground in case JProgressBar hides it
    305         lockfileDialog.button("LockFileDialog.ok_button").click();
    306         }
    307     } catch(Exception e) {
    308         System.err.println("@@@@@@@@@@@@@ No lockfile dialog");
    309     }
    310         */
    311306    stealAnyCollectionLock(1);
    312307    }
     
    418413    }
    419414   
    420     // Moving these working bits of code here, in case I can use them to right
     415    // Moving these working bits of code here, in case I can use them to write
    421416    // general get methods that make use of the GenericTypeMatcher method of accessing components
    422417    // See https://joel-costigliola.github.io/assertj/assertj-swing-lookup.html
Note: See TracChangeset for help on using the changeset viewer.