Changeset 39033


Ignore:
Timestamp:
2024-05-18T23:03:28+12:00 (2 weeks ago)
Author:
anupama
Message:
  1. Unfortunately the build and preview buttons have different component names automatically assigned by TestingPreparation GLI code when in Expert versus when in Librarian mode. Coded to handle both cases. 2. Checking for building success message (varies between Expert and Librarian modes) too before previewing. 3. The step of creating a shortcut in the workspace is finished. 4. All the utility functions for the former are completed. With this most of the GUI functionality in GS3 tutorial 1 (the small html collection) is done. Assert statements for checking the enrich pane is as expected may be needed. And tests of GS Reader results (browser testing) on preview need to be implemented.
Location:
gs3-extensions/testing/trunk/src
Files:
4 edited

Legend:

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

    r39029 r39033  
    3838- VERY USEFUL BASICS: https://docs.oracle.com/javase/6/docs/api/javax/swing/package-summary.html#threading
    3939- EDT and AssertJ Swing: https://joel-costigliola.github.io/assertj/assertj-swing-edt.html
     40
     41
     42NOTES on moving any code into Runnable class inside Gatherer.invokeOnDispatchThread (which does SwingUtilities.invokeAndWait/invokeLater):
     43- Only an outer class' member variables and final local variables are available to inner class.
     44This is necessary to know when calling SwingUtilities.invokeAndWait/invokeLater(new Runnable() {
     45     public void run() {
     46            // here, only the outer class' member and final local vars are available
     47        // As a closure is created with those variables, like in JavaScript
     48     }
     49});
     50- Rewrite any 'this' reference as '<OuterClassName>.this' when moving code containing any THIS ptr references into inner Runnable class
    4051
    4152----------------------
  • gs3-extensions/testing/trunk/src/src/gstests/tutorials/RunGLITest.java

    r39029 r39033  
    167167      // For testing, want GLI to be in librarian mode by default
    168168      changeUserMode("librarian");
    169       /*     
     169           
    170170      switchToPane(GATHER_PANE);
    171171     
     
    190190     
    191191      switchToPane(GATHER_PANE);     
    192       */
     192     
    193193      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
    194194     
     
    209209    stealAnyCollectionLock(1);
    210210    switchToPane(GATHER_PANE);
    211 
     211    */
    212212    // dummy tests
    213     testGLIRunning();
    214     */
     213    //testGLIRunning();
     214   
    215215    // First tutorial
    216216    simpleHTML();
     
    236236    stealAnyCollectionLock(1);
    237237    switchToPane(GATHER_PANE);
    238     //changeUserMode("librarian");
     238    changeUserMode("expert");
    239239    //openWorkspacePath(WKS_TOP_FOLDER_LOCAL, props.get("samplefiles.path").toString());
    240240
     
    245245    openCollectionPath("b17mie/b17mie.htm", CLICK);
    246246    PAUSE(3);
    247     openWorkspacePath(WKS_TOP_FOLDER_LOCAL, props.get("samplefiles.path").toString());
    248    
     247    openWorkspacePath(WKS_TOP_FOLDER_LOCAL, props.get("samplefiles.path").toString()); 
    249248    */
     249
     250   
    250251   
    251252    // Start a new collection within the Librarian Interface:
     
    260261    String dragNodePath = openWorkspacePath(WKS_TOP_FOLDER_LOCAL, props.get("samplefiles.path").toString()+"simple_html/html_files", SELECT);
    261262
    262     dragNDrop(dragNodePath, "");
    263    
    264    
     263    String collPath = dragNDrop(dragNodePath, "");
     264
     265   
     266    openCollectionPath("html_files", DOUBLE_CLICK);
     267    PAUSE(2);   
     268   
     269   
     270   
     271    //changeUserMode("librarian");
     272    //loadCollection("smallhtm");
    265273   
    266274    switchToPane(CREATE_PANE);
    267     buildCollection();
    268     previewCollectionWhenReady(MAX_BUILD_TIMEOUT);
     275    PAUSE(2);
     276    //buildCollection();
     277    //previewCollectionWhenReady(MAX_BUILD_TIMEOUT);
     278    buildCollectionTillReady(MAX_BUILD_TIMEOUT);   
     279    //closePopup("Collection Creation Result", "OK", DO_NOT_TICK_CHECKBOX);
     280    //closePopup(OPTIONAL, Dictionary.get("CollectionBuilt.Title"), Dictionary.get("General.OK"), TICK_CHECKBOX);
     281    closePopup(Dictionary.get("CollectionBuilt.Title"), Dictionary.get("General.OK"), TICK_CHECKBOX);   
     282    previewCollection();
     283   
     284    //window = getGLIApplicationWindow(robot());
     285   
     286    switchToPane(ENRICH_PANE); 
     287    closeCollection();
     288   
     289
     290    String path = openWorkspacePath(WKS_TOP_FOLDER_LOCAL, props.get("samplefiles.path").toString(), RIGHT_CLICK);
     291    //workspaceRightClickOption(dragNodePath, );
     292    PAUSE(2);
     293    selectContextMenu(Dictionary.get("MappingPrompt.Map")); // Create Shortcut
     294    closePopup(Dictionary.get("MappingPrompt.Title"), Dictionary.get("General.OK")); // accept shortcut name
     295
     296    collapseWorkspacePath(WKS_TOP_FOLDER_LOCAL);
    269297    PAUSE(4);
     298   
    270299    }
    271300
  • gs3-extensions/testing/trunk/src/src/org/greenstone/gsdl3/testing/GSGUITestingUtil.java

    r39029 r39033  
    55import java.util.regex.*;
    66import java.awt.Component;
     7import javax.swing.*;
    78
    89// only JUnit and JAssert-Swing, no Selenium in this class
     
    2627import org.assertj.swing.edt.GuiActionRunner;
    2728import org.assertj.swing.core.Robot;
     29import org.assertj.swing.core.GenericTypeMatcher;
     30// https://joel-costigliola.github.io/assertj/assertj-swing-lookup.html
     31// https://joel-costigliola.github.io/assertj/swing/api/org/assertj/swing/core/matcher/FrameMatcher.html
     32//import static org.assertj.swing.core.matcher.DialogMatcher.withTitle
     33import org.assertj.swing.core.matcher.*;
     34//import org.assertj.swing.core.matcher.DialogMatcher; // withTitle
     35//import org.assertj.swing.core.matcher.FrameMatcher; // withTitle
    2836
    2937
     
    4856{
    4957    public static FrameFixture window = null;
     58    public static String storedMode = null; // librarian/expert etc
     59    // prefix for building buttons in librarian mode (or less). Expert mode lacks the prefix
     60    public static String modeButtonPrefix = "simple_";
    5061   
    5162    public static final boolean PAUSE_ON = true;
     
    7384    public static final int RIGHT_CLICK = 3;
    7485    public static final int SELECT = 4;
     86
     87    public static final boolean TICK_CHECKBOX = true;
     88    public static final boolean DO_NOT_TICK_CHECKBOX = false;
     89
     90    public static final boolean OPTIONAL = true;
     91    public static final boolean COMPULSORY = true;
    7592   
    7693    public static Robot robot = null;
     
    205222    }
    206223    }
     224
     225    public static void closePopup(String winTitle, String buttonLabel) {
     226    closePopup(winTitle, buttonLabel, DO_NOT_TICK_CHECKBOX);
     227    }
     228   
     229    public static void closePopup(String winTitle, String buttonLabel, boolean tickCheck) {
     230    /*DialogFixture popup = findDialog(new GenericTypeMatcher<JDialog>(JDialog.class) {
     231        @Override
     232        protected boolean isMatching(JDialog dlg) {
     233            return winTitle.equals(dlg.getTitle());
     234        }
     235        }).using(robot);
     236    */
     237    // https://joel-costigliola.github.io/assertj/swing/api/org/assertj/swing/core/matcher/FrameMatcher.html
     238    System.err.println("# Looking for popup with title " + winTitle + " by clicking button " + buttonLabel);
     239    DialogFixture popup = findDialog(DialogMatcher.withTitle(winTitle)).using(robot);
     240    // Do any checkbox ticking Before closing the popup with OK click! 
     241
     242    if(tickCheck == TICK_CHECKBOX) {
     243        System.err.println("# Looking for a checkbox to tick");
     244        popup.checkBox().check();
     245        //PAUSE(4);
     246    }   
     247    System.err.println("# Closing popup by clicking button " + buttonLabel);
     248    PAUSE(1);
     249    popup.button(JButtonMatcher.withText(buttonLabel)).click();
     250   
     251    }
     252   
     253    // set tickCheck to false either if there's no checkbox, or if you don't want it ticked
     254    public static void closePopup(boolean optional, String winTitle,
     255                  String buttonLabel, boolean tickCheck)
     256    {
     257    if(optional == OPTIONAL) {
     258        try {
     259        closePopup(winTitle, buttonLabel, tickCheck);
     260        } catch(Exception e) {
     261        System.err.println("@ Optional popup did not appear.");
     262        }
     263    } else {//fatal if no popup or it doesn't have a matching title and label (and a checkbox)
     264        closePopup(winTitle, buttonLabel, tickCheck);
     265    }
     266    }
     267
     268    public static void selectContextMenu(String label) {
     269    JMenuItemFixture menuOption
     270        = window.menuItem(new GenericTypeMatcher<JMenuItem>(JMenuItem.class) {
     271        @Override
     272        protected boolean isMatching(JMenuItem menu) {
     273            /*
     274            System.err.println("### Considering match with menu: " + menu.getText());
     275            if (menu.getText().matches(label)) {
     276            System.err.println("### Matched");
     277            }
     278            */
     279            return (menu.getText().matches(label));
     280        }
     281        });
     282   
     283   
     284    menuOption.click();
     285   
     286    }
    207287   
    208288    // e.g. pane = Enrich,view=collection; pane = Gather, view = workspace (or collection)
     
    221301     */
    222302    public static void changeUserMode(String toMode) {
     303    storedMode = toMode;
     304       
    223305    openMenuItem("file", "options"); // click MenuBar.file -> MenuBar.file_options
    224306
     
    240322    dialog.button("Preferences.apply_button").click();
    241323    dialog.button("Preferences.ok_button").click();
     324
     325    modeButtonPrefix = toMode.equals("expert") ? "" : "simple_";
    242326    }
    243327
     
    398482    //while(!previewButton.isEnabled()) {}
    399483   
    400     JButtonFixture previewButtonTester = window.button("CreatePane.preview_button");
     484    JButtonFixture previewButtonTester
     485        = window.button("CreatePane."+modeButtonPrefix+ "preview_button");
    401486    javax.swing.JButton previewButton = previewButtonTester.target();
    402487    Pause.pause(new Condition("Preview button to be enabled") {
     
    411496        //txtArea.requireText("************** Build Finished **************");
    412497        //txtArea.requireText(java.util.regex.Pattern.compile("Build Finished|buildcol.pl> Command complete"));
     498        //txtArea.requireText(Pattern.compile("^\\s*(\\*+ Build Finished \\*+|buildcol\\.pl> Command complete)", Pattern.MULTILINE)); //https://stackoverflow.com/questions/3651725/match-multiline-text-using-regular-expression
     499
     500        //txtArea.requireText(Pattern.compile(".* (\\*+ Build Finished \\*+|buildcol\\.pl> Command complete) .*", Pattern.DOTALL)); //https://stackoverflow.com/questions/3651725/match-multiline-text-using-regular-expression
     501
     502        // WORKED:
     503        //txtArea.requireText(Pattern.compile(".* Build Finished .*", Pattern.DOTALL)); //https://stackoverflow.com/questions/3651725/match-multiline-text-using-regular-expression
     504        txtArea.requireText(Pattern.compile(".*^(\\*+ Build Finished \\*+|buildcol\\.pl> Command complete).*", Pattern.DOTALL|Pattern.MULTILINE)); //https://stackoverflow.com/questions/3651725/match-multiline-text-using-regular-expression
     505       
    413506        //System.err.println("@@@@ text: " + txtArea.text());
    414507    }
     
    417510    }
    418511    public static void buildCollection() {
    419     window.button("CreatePane.build_button").click();
    420     }
     512    /*
     513    JButtonFixture buildButton = window.button(new GenericTypeMatcher<JButton>(JButton.class) {
     514        @Override
     515        protected boolean isMatching(JButton button) {
     516            //if("CreatePane.build_button".equals(button.getName())) {
     517        //  return true;
     518          //  }
     519            //else return "CreatePane.simple_build_button".equals(button.getName());
     520           
     521            //return button.getName().matches("CreatePane.(simple_)?build_button");
     522           
     523            //return button.getName().equals("CreatePane.simple_build_button"); // NPE: not all buttons have names
     524            //return (button.getName() != null && button.getName().equals("CreatePane.simple_build_button"));
     525            return (button.getName() != null && button.getName().matches("CreatePane.(simple_)?build_button")); // NPE: not all buttons have names
     526        }
     527        });
     528*/ 
     529    //JButtonFixture buildButton
     530    //    = window.button(JButtonMatcher.withName("CreatePane.simple_build_button"));
     531
     532
     533    /*
     534    JButtonFixture buildButton
     535        = window.button(JButtonMatcher
     536                .withName(Pattern.compile("CreatePane\\.(simple_?)build_button"))
     537                .andShowing());
     538    */
     539
     540
     541    window.button("CreatePane."+modeButtonPrefix+ "build_button").click();
     542    }
     543
     544    public static boolean buttonNameMatches(JButton button, String regex) {
     545    return (button.getName() != null && button.getName().matches(regex));
     546    }
     547   
    421548    public static void buildCollectionTillReady(int maxWaitSeconds) {
    422549    buildCollection();
     
    431558    }
    432559    }
    433     public static void previewCollection() {   
    434     window.button("CreatePane.preview_button").click();
     560    public static void previewCollection() {
     561    window.button("CreatePane."+modeButtonPrefix+ "preview_button").click();
    435562    }
    436563
     
    462589    public static void createCollectionSubfolder() {}
    463590   
    464     public static void dragNDrop(String workspacePath, String collPath) {
     591    public static String dragNDrop(String workspacePath, String collPath) {
    465592    JTreeFixture workspaceTree = window.tree("GatherPane.workspace_tree");
    466593
     
    473600        collTree.drop(collPath); // call a JTreeFixture.drop() method
    474601    }
    475     System.err.println("@@@ New collPath: " + collPath);
     602    //System.err.println("@@@ New collPath: " + collPath);
    476603    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 
     604    collPath = (collPath==null || collPath.equals("")) ? newPath : (collPath + "/" + newPath); 
     605    //System.err.println("@@@ New collPath: " + collPath);
     606    return collPath;
     607    }
     608
     609    public static void collapseWorkspacePath(String path) {
     610    JTreeFixture workspaceTree = window.tree("GatherPane.workspace_tree");
     611    workspaceTree.collapsePath(path);
     612    }
     613    public static void collapseCollectionPath(String path) {       
     614    JTreeFixture collTree = null;
     615    try {
     616        collTree = window.tree("EnrichPane.collection_tree");
     617    } catch(Exception e) {
     618        collTree = window.tree("GatherPane.collection_tree");
     619    }
     620    collTree.collapsePath(path);
     621    }
    482622
    483623    public static String openWorkspacePath(String topGLIFolder, String workspacePath, int mouseAction) {
     
    485625        workspacePath = workspacePath.substring(1);
    486626    }
     627    /*if(workspacePath.endsWith("/")) {
     628        workspacePath = workspacePath.substring(0, workspacePath.length()-1);
     629        }*/
    487630   
    488631    //JTabbedPaneFixture gatherPane = switchToPane(GATHER_PANE);
     
    517660        nodes[i] = prevNode + "/" + nodes[i];       
    518661        System.err.println("\t" + nodes[i]);
    519         if(i < nodes.length) {
     662        if(i < (nodes.length-1)) {
    520663        wks_ptr = workspaceTree.expandPath(nodes[i]);
     664        System.err.println("\tExpanded node: " + nodes[i]);
    521665        } else { // final node
     666        System.err.println("\tFinal node: " + nodes[i]);
    522667        /*switch(leafNodeAction) {
    523668        case EXPAND:
     
    568713            break;
    569714        case RIGHT_CLICK:
     715            System.err.println("### Rightclicking at " + node);
    570716            tree_ptr = tree.rightClickPath(node);
    571717            break;
     
    591737    JTreeFixture collTree = null;
    592738    try {
     739        collTree = window.tree("EnrichPane.collection_tree");       
     740    } catch(Exception e) {
    593741        collTree = window.tree("GatherPane.collection_tree");
    594     } catch(Exception e) {
    595         collTree = window.tree("EnrichPane.collection_tree");
    596742    }
    597743    if(collPath != "") {
     
    607753       
    608754        System.err.println("\t" + nodes[i]);
    609         if(i < nodes.length) {
     755        if(i < (nodes.length-1)) {
    610756            collTree = collTree.expandPath(nodes[i]);
    611757        } else {
Note: See TracChangeset for help on using the changeset viewer.