Changeset 39029


Ignore:
Timestamp:
2024-05-15T21:48:53+12:00 (4 weeks ago)
Author:
anupama
Message:
  1. Drop part of dragging and dropping folder from workspace into coltree works. TODO: Will still need to implement multi file drag and drop (shift+select or ctrl+shift+select is allowed in GLI), but I'll implement as and when needed for writing tests for tutorials. 2. Collection Building and previewing (waiting for build to complete is waiting for preview button to become active) now works.
Location:
gs3-extensions/testing/trunk/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • gs3-extensions/testing/trunk/src/README

    r39023 r39029  
    3333- https://junit.org/junit4/ (we appear to use junit4)
    3434- 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
     35
     36Pages that are useful
     37- https://joel-costigliola.github.io/assertj/swing/api/org/assertj/swing/exception/EdtViolationException.html
     38- VERY USEFUL BASICS: https://docs.oracle.com/javase/6/docs/api/javax/swing/package-summary.html#threading
     39- EDT and AssertJ Swing: https://joel-costigliola.github.io/assertj/assertj-swing-edt.html
    3540
    3641----------------------
     
    9196Reminder: to shift code into the Event Dispatch Thread/EDT, there's SwingUtilities.invokeLater(), which is asynchronous. To be synchronous (code that Must happen now because the code that follows is dependent on results/successful finish of the sequence of events being shifted into the EDT), use SwingUtilities.invokeAndWait() in a try/catch.
    9297
    93 Pages that are useful
    94 - https://joel-costigliola.github.io/assertj/swing/api/org/assertj/swing/exception/EdtViolationException.html
    95 - VERY USEFUL BASICS: https://docs.oracle.com/javase/6/docs/api/javax/swing/package-summary.html#threading
    9698
    9799
  • gs3-extensions/testing/trunk/src/src/gstests/tutorials/RunGLITest.java

    r39025 r39029  
    8686
    8787    private static Properties props;
     88    // TODO: Do we ever expect tutorials to take more than a minute or 2 mins to build?
     89    // And do we think a test can get stuck waiting for the entire time before it bails?
     90    public static final int MAX_BUILD_TIMEOUT = 60;
    8891   
    8992    // Changing Exit SecurityManager is now unused as GLI now doesn't System.exit in testing mode
     
    235238    //changeUserMode("librarian");
    236239    //openWorkspacePath(WKS_TOP_FOLDER_LOCAL, props.get("samplefiles.path").toString());
    237    
    238     // Start a new collection within the Librarian Interface:
    239     /*createCollection("Small HTML Collection",
    240              "A small collection of HTML pages.",
    241              null);                 
    242     */
    243     loadCollection("smallhtm"); // TODO
    244     PAUSE(3);
    245    
    246     String dragNodePath = openWorkspacePath(WKS_TOP_FOLDER_LOCAL, props.get("samplefiles.path").toString()+"simple_html/html_files", SELECT);
    247 
    248     dragNDrop(dragNodePath, "");
    249    
     240
    250241    /*
    251242    loadCollection("lucene-jdbm-demo");
    252243    // wait a couple of seconds for loading to be done
    253244    PAUSE(2);
    254     openCollectionPath("b17mie/b17mie.htm", false);
     245    openCollectionPath("b17mie/b17mie.htm", CLICK);
    255246    PAUSE(3);
    256247    openWorkspacePath(WKS_TOP_FOLDER_LOCAL, props.get("samplefiles.path").toString());
    257248   
    258249    */
    259     PAUSE(2);
     250   
     251    // Start a new collection within the Librarian Interface:
     252    createCollection("Small HTML Collection",
     253             "A small collection of HTML pages.",
     254             null);                 
     255   
     256    //loadCollection("smallhtm"); // TODO
     257    PAUSE(3);
     258
     259   
     260    String dragNodePath = openWorkspacePath(WKS_TOP_FOLDER_LOCAL, props.get("samplefiles.path").toString()+"simple_html/html_files", SELECT);
     261
     262    dragNDrop(dragNodePath, "");
     263   
     264   
     265   
     266    switchToPane(CREATE_PANE);
     267    buildCollection();
     268    previewCollectionWhenReady(MAX_BUILD_TIMEOUT);
     269    PAUSE(4);
    260270    }
    261271
  • gs3-extensions/testing/trunk/src/src/org/greenstone/gsdl3/testing/GSGUITestingUtil.java

    r39025 r39029  
    99import org.junit.Assert;
    1010import org.assertj.swing.fixture.*;
    11 import org.assertj.swing.timing.Timeout ;
    12 
     11import org.assertj.swing.timing.Timeout;
     12
     13import org.assertj.swing.timing.Pause;
     14import org.assertj.swing.timing.Condition;
     15import java.util.concurrent.TimeUnit;
     16   
    1317// GLI imports
    1418import org.greenstone.gatherer.Gatherer;
     
    8286   
    8387    /****************************** APPLICATION  *******************************/
     88    //TODO
    8489    public static void PAUSE() {   
    8590    PAUSE(5);
     91    //Pause.pause(5, TimeUnit.SECONDS);
    8692    }
    8793    public static void PAUSE(int seconds) {
     94    //if(!PAUSE_ON) return; // ignore calls to PAUSE
     95    //Pause.pause(seconds, TimeUnit.SECONDS);
     96   
     97   
    8898    if(!PAUSE_ON) return; // ignore calls to PAUSE
    89    
    9099    // wait a couple of seconds again?
    91100     try{
     
    383392
    384393    /********************** CREATE PANEL ********************/
    385     public static void buildOpenCollection() {}
    386     public static void buildOpenCollection(boolean minimalRebuild) {}
     394    public static JButtonFixture waitForPreviewReady(int maxWaitSeconds) {
     395    return waitForPreviewReady(maxWaitSeconds, true);
     396    }
     397    public static JButtonFixture waitForPreviewReady(int maxWaitSeconds, boolean bailTestingOnBuildFailure) {
     398    //while(!previewButton.isEnabled()) {}
     399   
     400    JButtonFixture previewButtonTester = window.button("CreatePane.preview_button");
     401    javax.swing.JButton previewButton = previewButtonTester.target();
     402    Pause.pause(new Condition("Preview button to be enabled") {
     403        public boolean test() {
     404            return previewButton.isEnabled();
     405        }
     406       
     407        }, Timeout.timeout(maxWaitSeconds, TimeUnit.SECONDS));
     408
     409    if(bailTestingOnBuildFailure) {
     410        JTextComponentFixture txtArea = window.textBox("CreatePane.log_textarea");
     411        //txtArea.requireText("************** Build Finished **************");
     412        //txtArea.requireText(java.util.regex.Pattern.compile("Build Finished|buildcol.pl> Command complete"));
     413        //System.err.println("@@@@ text: " + txtArea.text());
     414    }
     415   
     416    return previewButtonTester;
     417    }
     418    public static void buildCollection() {
     419    window.button("CreatePane.build_button").click();
     420    }
     421    public static void buildCollectionTillReady(int maxWaitSeconds) {
     422    buildCollection();
     423    waitForPreviewReady(maxWaitSeconds);
     424    }
     425    public static void buildCollection(boolean minimalRebuild) {
     426    if(minimalRebuild) {
     427        // try with or without s in sincremental
     428        window.button("CreatePane.sincremental_build_radio_button").click(); // JRadioButtonFixture
     429    } else {
     430        buildCollection();
     431    }
     432    }
     433    public static void previewCollection() {   
     434    window.button("CreatePane.preview_button").click();
     435    }
     436
     437    // Usage of AssertJ Swing Condition, and Pause on Condition
     438    // https://gist.github.com/hashrock/26afb842db35eb03699acf735a692f2e
     439    // https://joel-costigliola.github.io/assertj/swing/api/org/assertj/swing/timing/Pause.html
     440    // https://joel-costigliola.github.io/assertj/swing/api/org/assertj/swing/timing/Condition.html
     441    public static void previewCollectionWhenReady(int maxWaitSeconds) {
     442    JButtonFixture preview = waitForPreviewReady(maxWaitSeconds);
     443        preview.click();   
     444    }
     445   
     446    public static void buildAndPreviewCollection(int maxWaitForBuilding) {
     447    buildCollection();
     448    //JButtonFixture preview = waitForPreviewReady(maxWaitSeconds);
     449    //previewCollection();
     450    previewCollectionWhenReady(maxWaitForBuilding);
     451    }
     452
    387453    public static void configureImportOptions(Map params) {}
    388454    public static void configureBuildOptions(Map params) {}
    389455   
    390     public static void buildOutputContains(String ... n) {}
    391 
     456    public static void buildOutputContains(String ... n) {}   
     457   
    392458    /******************** GATHER PANE ********************/
    393459    public static void createWorkspaceShortcut(){}
     
    403469    workspaceTree.drag(workspacePath);
    404470    if(collPath == null || collPath.equals("")) {
    405         collTree.drop("bla");
     471        collTree.drop(); // empty tree, call ancestor method AbstractComponentFixture.drop()
    406472    } else {
    407         collTree.drop(collPath);
    408     }
    409     }
    410 
    411 
    412     public static String openWorkspacePath(String topGLIFolder, String workspacePath, int leafNodeAction) {
     473        collTree.drop(collPath); // call a JTreeFixture.drop() method
     474    }
     475    System.err.println("@@@ New collPath: " + collPath);
     476    String newPath = workspacePath.substring(workspacePath.lastIndexOf("/")+1);
     477    collPath = (collPath==null || collPath.equals("")) ? newPath : (collPath + "/" + newPath);
     478    openCollectionPath(collPath, SELECT);
     479    System.err.println("@@@ New collPath: " + collPath);
     480    }
     481
     482
     483    public static String openWorkspacePath(String topGLIFolder, String workspacePath, int mouseAction) {
    413484    if(workspacePath.startsWith("/")) {
    414485        workspacePath = workspacePath.substring(1);
     
    449520        wks_ptr = workspaceTree.expandPath(nodes[i]);
    450521        } else { // final node
    451         switch(leafNodeAction) {
     522        /*switch(leafNodeAction) {
    452523        case EXPAND:
    453524            wks_ptr = workspaceTree.expandPath(nodes[i]);
     
    468539            System.err.println("GSGUITestingUtil.openWorkspacePath - unknown action " + leafNodeAction);
    469540        }
     541        */
     542        wks_ptr = handleLeafNode(workspaceTree, nodes[i], mouseAction);
    470543        }
    471544    }
     
    478551   
    479552    }
    480     public static JTreeFixture openCollectionPath(String collPath, boolean openFile) {
     553
     554    public static JTreeFixture handleLeafNode(JTreeFixture tree, String node, int mouseAction){
     555    JTreeFixture tree_ptr = tree;
     556    switch(mouseAction) {
     557        case EXPAND:
     558            tree_ptr = tree.expandPath(node);
     559            break;
     560        case CLICK:
     561            tree_ptr = tree.clickPath(node);
     562            break;
     563        case DOUBLE_CLICK:
     564            tree_ptr = tree.doubleClickPath(node);
     565            break;
     566        case SELECT:
     567            tree_ptr = tree.doubleClickPath(node);
     568            break;
     569        case RIGHT_CLICK:
     570            tree_ptr = tree.rightClickPath(node);
     571            break;
     572        default:
     573            System.err.println("GSGUITestingUtil.handleLeafNode - unknown action " + mouseAction);
     574    }
     575    return tree_ptr;
     576    }
     577   
     578    public static JTreeFixture openCollectionPath(String collPath, int mouseAction) {
    481579    /*
    482580    JTreeFixture tree = window.tree();
     
    509607       
    510608        System.err.println("\t" + nodes[i]);
    511        
     609        if(i < nodes.length) {
     610            collTree = collTree.expandPath(nodes[i]);
     611        } else {
     612            collTree = handleLeafNode(collTree, nodes[i], mouseAction);
     613        }
     614        /*
    512615        if(i == (nodes.length-1) && !openFile) {
    513616            collTree = collTree.clickPath(nodes[i]);
     
    517620            // which can open it in browser. This may not be what we want.
    518621        }
     622        */
    519623       
    520624        }
Note: See TracChangeset for help on using the changeset viewer.