Changeset 39033
- Timestamp:
- 2024-05-18T23:03:28+12:00 (2 weeks ago)
- Location:
- gs3-extensions/testing/trunk/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
gs3-extensions/testing/trunk/src/README
r39029 r39033 38 38 - VERY USEFUL BASICS: https://docs.oracle.com/javase/6/docs/api/javax/swing/package-summary.html#threading 39 39 - EDT and AssertJ Swing: https://joel-costigliola.github.io/assertj/assertj-swing-edt.html 40 41 42 NOTES 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. 44 This 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 40 51 41 52 ---------------------- -
gs3-extensions/testing/trunk/src/src/gstests/tutorials/RunGLITest.java
r39029 r39033 167 167 // For testing, want GLI to be in librarian mode by default 168 168 changeUserMode("librarian"); 169 /*169 170 170 switchToPane(GATHER_PANE); 171 171 … … 190 190 191 191 switchToPane(GATHER_PANE); 192 */192 193 193 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 194 194 … … 209 209 stealAnyCollectionLock(1); 210 210 switchToPane(GATHER_PANE); 211 211 */ 212 212 // dummy tests 213 testGLIRunning();214 */213 //testGLIRunning(); 214 215 215 // First tutorial 216 216 simpleHTML(); … … 236 236 stealAnyCollectionLock(1); 237 237 switchToPane(GATHER_PANE); 238 //changeUserMode("librarian");238 changeUserMode("expert"); 239 239 //openWorkspacePath(WKS_TOP_FOLDER_LOCAL, props.get("samplefiles.path").toString()); 240 240 … … 245 245 openCollectionPath("b17mie/b17mie.htm", CLICK); 246 246 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()); 249 248 */ 249 250 250 251 251 252 // Start a new collection within the Librarian Interface: … … 260 261 String dragNodePath = openWorkspacePath(WKS_TOP_FOLDER_LOCAL, props.get("samplefiles.path").toString()+"simple_html/html_files", SELECT); 261 262 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"); 265 273 266 274 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); 269 297 PAUSE(4); 298 270 299 } 271 300 -
gs3-extensions/testing/trunk/src/src/org/greenstone/gsdl3/testing/GSGUITestingUtil.java
r39029 r39033 5 5 import java.util.regex.*; 6 6 import java.awt.Component; 7 import javax.swing.*; 7 8 8 9 // only JUnit and JAssert-Swing, no Selenium in this class … … 26 27 import org.assertj.swing.edt.GuiActionRunner; 27 28 import org.assertj.swing.core.Robot; 29 import 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 33 import org.assertj.swing.core.matcher.*; 34 //import org.assertj.swing.core.matcher.DialogMatcher; // withTitle 35 //import org.assertj.swing.core.matcher.FrameMatcher; // withTitle 28 36 29 37 … … 48 56 { 49 57 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_"; 50 61 51 62 public static final boolean PAUSE_ON = true; … … 73 84 public static final int RIGHT_CLICK = 3; 74 85 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; 75 92 76 93 public static Robot robot = null; … … 205 222 } 206 223 } 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 } 207 287 208 288 // e.g. pane = Enrich,view=collection; pane = Gather, view = workspace (or collection) … … 221 301 */ 222 302 public static void changeUserMode(String toMode) { 303 storedMode = toMode; 304 223 305 openMenuItem("file", "options"); // click MenuBar.file -> MenuBar.file_options 224 306 … … 240 322 dialog.button("Preferences.apply_button").click(); 241 323 dialog.button("Preferences.ok_button").click(); 324 325 modeButtonPrefix = toMode.equals("expert") ? "" : "simple_"; 242 326 } 243 327 … … 398 482 //while(!previewButton.isEnabled()) {} 399 483 400 JButtonFixture previewButtonTester = window.button("CreatePane.preview_button"); 484 JButtonFixture previewButtonTester 485 = window.button("CreatePane."+modeButtonPrefix+ "preview_button"); 401 486 javax.swing.JButton previewButton = previewButtonTester.target(); 402 487 Pause.pause(new Condition("Preview button to be enabled") { … … 411 496 //txtArea.requireText("************** Build Finished **************"); 412 497 //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 413 506 //System.err.println("@@@@ text: " + txtArea.text()); 414 507 } … … 417 510 } 418 511 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 421 548 public static void buildCollectionTillReady(int maxWaitSeconds) { 422 549 buildCollection(); … … 431 558 } 432 559 } 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(); 435 562 } 436 563 … … 462 589 public static void createCollectionSubfolder() {} 463 590 464 public static voiddragNDrop(String workspacePath, String collPath) {591 public static String dragNDrop(String workspacePath, String collPath) { 465 592 JTreeFixture workspaceTree = window.tree("GatherPane.workspace_tree"); 466 593 … … 473 600 collTree.drop(collPath); // call a JTreeFixture.drop() method 474 601 } 475 System.err.println("@@@ New collPath: " + collPath);602 //System.err.println("@@@ New collPath: " + collPath); 476 603 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 } 482 622 483 623 public static String openWorkspacePath(String topGLIFolder, String workspacePath, int mouseAction) { … … 485 625 workspacePath = workspacePath.substring(1); 486 626 } 627 /*if(workspacePath.endsWith("/")) { 628 workspacePath = workspacePath.substring(0, workspacePath.length()-1); 629 }*/ 487 630 488 631 //JTabbedPaneFixture gatherPane = switchToPane(GATHER_PANE); … … 517 660 nodes[i] = prevNode + "/" + nodes[i]; 518 661 System.err.println("\t" + nodes[i]); 519 if(i < nodes.length) {662 if(i < (nodes.length-1)) { 520 663 wks_ptr = workspaceTree.expandPath(nodes[i]); 664 System.err.println("\tExpanded node: " + nodes[i]); 521 665 } else { // final node 666 System.err.println("\tFinal node: " + nodes[i]); 522 667 /*switch(leafNodeAction) { 523 668 case EXPAND: … … 568 713 break; 569 714 case RIGHT_CLICK: 715 System.err.println("### Rightclicking at " + node); 570 716 tree_ptr = tree.rightClickPath(node); 571 717 break; … … 591 737 JTreeFixture collTree = null; 592 738 try { 739 collTree = window.tree("EnrichPane.collection_tree"); 740 } catch(Exception e) { 593 741 collTree = window.tree("GatherPane.collection_tree"); 594 } catch(Exception e) {595 collTree = window.tree("EnrichPane.collection_tree");596 742 } 597 743 if(collPath != "") { … … 607 753 608 754 System.err.println("\t" + nodes[i]); 609 if(i < nodes.length) {755 if(i < (nodes.length-1)) { 610 756 collTree = collTree.expandPath(nodes[i]); 611 757 } else {
Note:
See TracChangeset
for help on using the changeset viewer.