Changeset 39041


Ignore:
Timestamp:
2024-05-22T22:40:43+12:00 (4 weeks ago)
Author:
anupama
Message:

More tidying up (removed unused old variants of functions), more comments, and reinstated the active code for tutorial 2 thus far and tested that works. Still need to find a way to reactivate the GLI window after previewing (which makes the browser active) and how to launch the browser stuff in the robot driver browser window that testing first opens. And of course, I need to continue on tutorial 2 now that setting/adding metadata works.

Location:
gs3-extensions/testing/trunk/src
Files:
3 edited

Legend:

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

    r39040 r39041  
    314314    PAUSE(3); // Need some time before we start making selections in the workspace tree
    315315    changeUserMode("librarian");
    316     /*
     316   
    317317    String image_e_coll = props.get("samplefiles.path")+File.separator+"images"+File.separator+"image-e";
    318318    File newFolder = GSBasicTestingUtil.copyIntoCollect(image_e_coll);
     
    329329    //loadCollection("backdrop");
    330330    PAUSE(3);
    331     */ 
    332 
    333     /*
     331       
    334332    // Multiple selection drag and drop works iff Shift-Selecting a contiguous set of files.
    335333    //
     
    366364    //previewCollection();
    367365    buildAndPreviewCollection(MAX_BUILD_TIMEOUT);
    368     */
     366
     367    // try to make the GLI main window the active one again, instead of the browser
     368    //window.focus();
     369    //PAUSE(2);
     370
    369371    switchToPane(ENRICH_PANE); 
    370     PAUSE(1);   
     372    PAUSE(2);   
    371373    //openCollectionPath("Bear.jpg", CLICK);
    372     //changeToMetadataSet("Dublin Core Metadata Element Set");
     374    changeToMetadataSet("Dublin Core Metadata Element Set");
    373375
    374376    setMetaByTyping("Bear.jpg", "dc.Title", "Bear");   
     
    378380    addMeta("Cat.jpg", "dc.Description", "Kathy's beloved friend Kouskous");
    379381    addMeta("Cheetah.jpg", "dc.Description", "Fastest land mammal");
    380    
    381     /*
    382     addMetaByPasting("Cat.jpg", "dc.Description", "Miao");
    383     addMetaByTyping("Cat.jpg", "dc.Description", "Paw");
    384     addMetaByTyping("Cat.jpg", "dc.Title", "Cat");
    385     addMetaByPasting("Cat.jpg", "dc.Title", "Fur");
    386     */
    387     /*addMetaByPasting("Bear.jpg", "dc.Title", "Pinky");
    388     addMetaByTyping("Bear.jpg", "dc.Title", "Toto");
    389     addMetaByTyping("Bear.jpg", "dc.Title", "Lala");
    390     addMetaByPasting("Bear.jpg", "dc.Title", "Nono");
    391     */
    392     //addMeta_UsingGLItableInEDT("Bear.jpg", "dc.Title", "Pinky");
    393     //addMeta2("Bear.jpg", "dc.Title", "Lala");
    394     //addMeta("Bear.jpg", "dc.Title", "Toto");
    395     //addMeta("Bear.jpg", "dc.Title", "Lala");
    396    
    397     String[] metavalues = {"lala", "nono", "dodo"};
    398     addMeta("Bear.jpg", "dc.Title", metavalues);
    399     //addMetaValsToCurrentDoc("dc.Title", metavalues);
    400382   
    401383    PAUSE(2);
  • gs3-extensions/testing/trunk/src/src/org/greenstone/gsdl3/testing/GSGUITestingUtil.java

    r39040 r39041  
    953953            //tree_ptr = tree.clickPath(node);
    954954            tree_ptr = tree.drag(node);         
    955             PAUSE(1);
     955            PAUSE(0.25);
    956956            break;
    957957        default:
     
    10221022    DialogFixture addMetaDialog = mdsetDialog.dialog("AddMetadataSetPrompt.add_set_dialog");//window.dialog("AddMetadataSetPrompt.add_set_dialog");//findDialog(DialogMatcher.withTitle(Dictionary.get("MetadataSetDialog.Add_Title"))).using(robot);
    10231023    JListFixture mds_list = addMetaDialog.list("AddMetadataSetPrompt.available_sets_list");
    1024     PAUSE(3);
     1024    //PAUSE(0.25);
    10251025    mds_list.selectItem(Pattern.compile("^"+toSet+".*$"));
    1026     PAUSE(2);
     1026    //PAUSE(0.25);
    10271027    addMetaDialog.button("AddMetadataSetPrompt.add_button").click();
    1028     PAUSE(1);
     1028    //PAUSE(0.25);
    10291029    mdsetDialog.button("MetadataSetDialog.close_button").click();
    10301030    }
    10311031
    1032     // setMeta overwrites first cell
     1032    // setMeta overwrites first cell, by *typing* in the value. For testing typing.
    10331033    public static void setMetaByTyping(String documentPath, String metaname, String metavalue) {
    10341034    openCollectionPath(documentPath, CLICK);
     
    10421042    cell.click(); // click elsewhere to let the entered value stick
    10431043    }
     1044    // Sets a piece of metadata, overwriting any 1st value cell
     1045    // for the given metaname, by *pasting* in the value into the value cell
    10441046    public static void setMeta(String documentPath, String metaname, String metavalue) {
    10451047    openCollectionPath(documentPath, CLICK);
     
    10511053    cell.click(); // click elsewhere to let the entered value stick
    10521054    }
    1053 
     1055    // Appending a metadata value for a metaname. Method to test out typing in the value
     1056    // Also works to set the first metadata if there is none, but does not overwrite.
    10541057    public static void addMetaByTyping(String documentPath, String metaname, String metavalue) {
    10551058    openCollectionPath(documentPath, CLICK);
     
    10841087    cell.click(); // click elsewhere to let the entered value stick
    10851088    }
    1086    
     1089
     1090    // Appending a metadata value for a metaname. *Pastes* in the value to save time.
     1091    // Also works to set the first metadata if there is none, but does not overwrite.
     1092    // You can just call addMeta with the same parameters to also add meta() by pasting
     1093    // This variant is here to explain how it works and why and what the settings need to be for
     1094    // Command/Ctrl+V pasting to work.
    10871095    public static void addMetaByPasting(String documentPath, String metaname, String metavalue) {
    10881096    openCollectionPath(documentPath, CLICK);
     
    11151123   
    11161124    //GuiActionRunner.execute(() -> table.setSurrendersFocusOnKeystroke(true)); // THE SOLUTION
    1117     putOnClipboard(metavalue);
    1118     pasteClipboard(metatable);
     1125    enterStringInFocusedElement(metatable, metavalue);
    11191126
    11201127    cell.click(); // click elsewhere to let the entered value stick
    11211128    }
    11221129
     1130    // Appending a metadata value for a metaname. *Pastes* in the value to save time.
     1131    // Also works to set the first metadata if there is none, but does not overwrite.
    11231132    public static void addMeta(String documentPath, String metaname, String metavalue) {
    11241133    openCollectionPath(documentPath, CLICK);
     
    11291138    openCollectionPath(documentPath, CLICK);
    11301139    addMetaValsToCurrentDoc(metaname, metavalues);
    1131 
    1132     }
    1133    
    1134     // Uses paste method
     1140    }
     1141   
     1142    // Uses paste method to set the given metavalues for the given metaname on the currently
     1143    // active document (doc clicked in the Enrich Pane collection tree), whatever that may be.   
    11351144    public static void addMetaValsToCurrentDoc(String metaname, String[] metavalues) {
    11361145    JTableFixture metatable = window.table("MetadataValueTable");
     
    11421151    for(String metavalue : metavalues) {
    11431152        metatable.pressAndReleaseKey(KeyPressInfo.keyCode(java.awt.event.KeyEvent.VK_ENTER));
    1144         System.err.println("### Copying to clipboard: " + metavalue);
    1145         putOnClipboard(metavalue);
    1146         pasteClipboard(metatable);
    1147         // Enter press doesn't happen without 1st a click in initial/1st (metaname!) cell again
     1153
     1154        enterStringInFocusedElement(metatable, metavalue);
     1155        // Enter press doesn't happen without being preced by a click in initial/1st
     1156        // (metaname!) cell again. The click() also needs to happen on the
     1157        // final metadata to make the value stick
    11481158        // This works out because of the way the metadata table in GLI behaves
    11491159        // Alternative: click on the just edited cell. Use GuiTask to obtain it: to work out
    11501160        // the current edited row, from which we can obtain the just edited TableCell to click
    11511161        // See addMetaByTyping() for how to do it.
    1152         cell.click();
    1153         //metatable.pressAndReleaseKey(KeyPressInfo.keyCode(java.awt.event.KeyEvent.VK_ENTER));
    1154         //PAUSE(1);
    1155         System.err.println("### Pasting from clipboard: " + getStringFromClipboard());
     1162        cell.click();       
     1163
     1164        //System.err.println("### Pasting from clipboard: " + getStringOnClipboard());
    11561165    }
    11571166    }
     
    11631172    // or List (sequence) of entries.
    11641173    // java.util.AbstractMap.SimpleEntry<K,V> implements Map.Entry
    1165     public static void addMeta(String documentPath, Collection<Map.Entry<String, Object>> metadata) {
     1174    public static void addMeta(String documentPath, Collection<Map.Entry<String, Object>> metadata)
     1175    {
    11661176    openCollectionPath(documentPath, CLICK);
    11671177    JTableFixture metatable = window.table("MetadataValueTable");
     
    11851195    }   
    11861196    }
    1187    
    1188    
    1189     public static void addMeta_UsingGLItableInEDT(String documentPath, String metaname, String metavalue) {
    1190     openCollectionPath(documentPath, CLICK);
    1191     JTableFixture metatable = window.table("MetadataValueTable");
    1192     JTableCellFixture cell = metatable.cell(metaname); // First matching metaname
    1193     int r = cell.row();
    1194     int c = cell.column();
    1195     metatable.cell(TableCell.row(r).column(c+1)).click();
    1196     //PAUSE(0.5);
    1197     //metatable.pressKey(java.awt.event.KeyEvent.VK_ENTER);
    1198     metatable.pressAndReleaseKey(KeyPressInfo.keyCode(java.awt.event.KeyEvent.VK_ENTER));
    1199 
    1200     // Accessing GUI using javax swing means accessing it outside of assertj swing API,
    1201     // as a result of which we have to ensure it's done in the Event Dispatch Thread (EDT)
    1202     // https://joel-costigliola.github.io/assertj/assertj-swing-edt.html
    1203     JTable table = metatable.target();
    1204     GuiActionRunner.execute(new org.assertj.swing.edt.GuiTask() {
    1205           protected void executeInEDT() {
    1206               // https://stackoverflow.com/questions/43341206/simulating-enter-key-java
    1207               //try {
    1208 
    1209               //java.awt.Robot javabot = new java.awt.Robot();
    1210               //javabot.keyPress(java.awt.event.KeyEvent.VK_ENTER);
    1211               //javabot.keyRelease(java.awt.event.KeyEvent.VK_ENTER);
    1212               int row = table.getEditingRow();
    1213               int col = table.getEditingColumn();
    1214               table.setValueAt(metavalue, row, col);
    1215               //} catch(java.awt.AWTException AWTe) {
    1216               //  System.err.println("@@@ Couldn't create Java robot: " + AWTe.getMessage());
    1217               //}
    1218           }
    1219        
    1220         });
    1221    
    1222     }
    1223    
     1197
     1198    // TODO replaceMeta(doc, metaname, oldvalue, newvalue) - easy to do, locate metanme cell
     1199    // then locate in col2 the oldvalue. Then set the meta in that cell to the new value.
     1200
     1201    // Instead of always typing out string one char at a time into a widget,
     1202    // the faster way, and still realistic to user-behaviour, is to paste a string in.
     1203    // First we cheat by copying whatever string we want to enter onto the clipboard.
     1204    // Then yank it from there with the usual Ctrl/Command+v combination.
    12241205    public static void enterStringInFocusedElement(AbstractComponentFixture widget,
    12251206                           String theString)
     
    12341215    // https://stackoverflow.com/questions/15260282/converting-a-char-into-java-keyevent-keycode
    12351216
    1236     // Copy paste should work if I can copy to clipboard
    1237     // https://stackoverflow.com/questions/3591945/copying-to-the-clipboard-in-java
    1238     System.err.println("### Copying to clipboard: " + theString);
    1239     putOnClipboard(theString);
    1240     System.err.println("### Pasting from clipboard.");
    1241     pasteClipboard(widget);
    1242    
    1243     }
    1244 
     1217    // Copying to clipboard and pasting into active widget
     1218    // For JTables, you may need to make sure to first do (the 1st time):
     1219    //    GuiActionRunner.execute(() -> table.setSurrendersFocusOnKeystroke(true));
     1220    // for the paste to happen in the active cell being edited.
     1221    // https://stackoverflow.com/questions/3591945/copying-to-the-clipboard-in-java
     1222    putOnClipboard(theString); 
     1223    pasteFromClipboard(widget);
     1224    }
    12451225    public static void putOnClipboard(String theString) {
    12461226    // https://stackoverflow.com/questions/3591945/copying-to-the-clipboard-in-java
     
    12501230
    12511231    }
     1232    //For now here for debugging purposes, but can come in handy later
    12521233    //http://www.avajava.com/tutorials/lessons/how-do-i-get-a-string-from-the-clipboard.html
    1253     public static String getStringFromClipboard() {
     1234    public static String getStringOnClipboard() {
    12541235    String result = "Clipboard retrieval failed";
    12551236    try {
     
    12621243    return result;
    12631244    }
    1264     public static void pasteClipboard(AbstractComponentFixture widget) {   
     1245    public static void pasteFromClipboard(AbstractComponentFixture widget) {   
    12651246    // https://joel-costigliola.github.io/assertj/assertj-swing-edt.html   
    12661247    // https://joel-costigliola.github.io/assertj/swing/api/org/assertj/swing/core/KeyPressInfo.html   
Note: See TracChangeset for help on using the changeset viewer.