Changeset 39041
- Timestamp:
- 2024-05-22T22:40:43+12:00 (4 weeks ago)
- 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 314 314 PAUSE(3); // Need some time before we start making selections in the workspace tree 315 315 changeUserMode("librarian"); 316 /*316 317 317 String image_e_coll = props.get("samplefiles.path")+File.separator+"images"+File.separator+"image-e"; 318 318 File newFolder = GSBasicTestingUtil.copyIntoCollect(image_e_coll); … … 329 329 //loadCollection("backdrop"); 330 330 PAUSE(3); 331 */ 332 333 /* 331 334 332 // Multiple selection drag and drop works iff Shift-Selecting a contiguous set of files. 335 333 // … … 366 364 //previewCollection(); 367 365 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 369 371 switchToPane(ENRICH_PANE); 370 PAUSE( 1);372 PAUSE(2); 371 373 //openCollectionPath("Bear.jpg", CLICK); 372 //changeToMetadataSet("Dublin Core Metadata Element Set");374 changeToMetadataSet("Dublin Core Metadata Element Set"); 373 375 374 376 setMetaByTyping("Bear.jpg", "dc.Title", "Bear"); … … 378 380 addMeta("Cat.jpg", "dc.Description", "Kathy's beloved friend Kouskous"); 379 381 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);400 382 401 383 PAUSE(2); -
gs3-extensions/testing/trunk/src/src/org/greenstone/gsdl3/testing/GSGUITestingUtil.java
r39040 r39041 953 953 //tree_ptr = tree.clickPath(node); 954 954 tree_ptr = tree.drag(node); 955 PAUSE( 1);955 PAUSE(0.25); 956 956 break; 957 957 default: … … 1022 1022 DialogFixture addMetaDialog = mdsetDialog.dialog("AddMetadataSetPrompt.add_set_dialog");//window.dialog("AddMetadataSetPrompt.add_set_dialog");//findDialog(DialogMatcher.withTitle(Dictionary.get("MetadataSetDialog.Add_Title"))).using(robot); 1023 1023 JListFixture mds_list = addMetaDialog.list("AddMetadataSetPrompt.available_sets_list"); 1024 PAUSE(3);1024 //PAUSE(0.25); 1025 1025 mds_list.selectItem(Pattern.compile("^"+toSet+".*$")); 1026 PAUSE(2);1026 //PAUSE(0.25); 1027 1027 addMetaDialog.button("AddMetadataSetPrompt.add_button").click(); 1028 PAUSE(1);1028 //PAUSE(0.25); 1029 1029 mdsetDialog.button("MetadataSetDialog.close_button").click(); 1030 1030 } 1031 1031 1032 // setMeta overwrites first cell 1032 // setMeta overwrites first cell, by *typing* in the value. For testing typing. 1033 1033 public static void setMetaByTyping(String documentPath, String metaname, String metavalue) { 1034 1034 openCollectionPath(documentPath, CLICK); … … 1042 1042 cell.click(); // click elsewhere to let the entered value stick 1043 1043 } 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 1044 1046 public static void setMeta(String documentPath, String metaname, String metavalue) { 1045 1047 openCollectionPath(documentPath, CLICK); … … 1051 1053 cell.click(); // click elsewhere to let the entered value stick 1052 1054 } 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. 1054 1057 public static void addMetaByTyping(String documentPath, String metaname, String metavalue) { 1055 1058 openCollectionPath(documentPath, CLICK); … … 1084 1087 cell.click(); // click elsewhere to let the entered value stick 1085 1088 } 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. 1087 1095 public static void addMetaByPasting(String documentPath, String metaname, String metavalue) { 1088 1096 openCollectionPath(documentPath, CLICK); … … 1115 1123 1116 1124 //GuiActionRunner.execute(() -> table.setSurrendersFocusOnKeystroke(true)); // THE SOLUTION 1117 putOnClipboard(metavalue); 1118 pasteClipboard(metatable); 1125 enterStringInFocusedElement(metatable, metavalue); 1119 1126 1120 1127 cell.click(); // click elsewhere to let the entered value stick 1121 1128 } 1122 1129 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. 1123 1132 public static void addMeta(String documentPath, String metaname, String metavalue) { 1124 1133 openCollectionPath(documentPath, CLICK); … … 1129 1138 openCollectionPath(documentPath, CLICK); 1130 1139 addMetaValsToCurrentDoc(metaname, metavalues); 1131 1132 }1133 1134 // Uses paste method1140 } 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. 1135 1144 public static void addMetaValsToCurrentDoc(String metaname, String[] metavalues) { 1136 1145 JTableFixture metatable = window.table("MetadataValueTable"); … … 1142 1151 for(String metavalue : metavalues) { 1143 1152 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 1148 1158 // This works out because of the way the metadata table in GLI behaves 1149 1159 // Alternative: click on the just edited cell. Use GuiTask to obtain it: to work out 1150 1160 // the current edited row, from which we can obtain the just edited TableCell to click 1151 1161 // 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()); 1156 1165 } 1157 1166 } … … 1163 1172 // or List (sequence) of entries. 1164 1173 // 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 { 1166 1176 openCollectionPath(documentPath, CLICK); 1167 1177 JTableFixture metatable = window.table("MetadataValueTable"); … … 1185 1195 } 1186 1196 } 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. 1224 1205 public static void enterStringInFocusedElement(AbstractComponentFixture widget, 1225 1206 String theString) … … 1234 1215 // https://stackoverflow.com/questions/15260282/converting-a-char-into-java-keyevent-keycode 1235 1216 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 } 1245 1225 public static void putOnClipboard(String theString) { 1246 1226 // https://stackoverflow.com/questions/3591945/copying-to-the-clipboard-in-java … … 1250 1230 1251 1231 } 1232 //For now here for debugging purposes, but can come in handy later 1252 1233 //http://www.avajava.com/tutorials/lessons/how-do-i-get-a-string-from-the-clipboard.html 1253 public static String getString FromClipboard() {1234 public static String getStringOnClipboard() { 1254 1235 String result = "Clipboard retrieval failed"; 1255 1236 try { … … 1262 1243 return result; 1263 1244 } 1264 public static void paste Clipboard(AbstractComponentFixture widget) {1245 public static void pasteFromClipboard(AbstractComponentFixture widget) { 1265 1246 // https://joel-costigliola.github.io/assertj/assertj-swing-edt.html 1266 1247 // https://joel-costigliola.github.io/assertj/swing/api/org/assertj/swing/core/KeyPressInfo.html
Note:
See TracChangeset
for help on using the changeset viewer.