/** * Internal method used for recursion. * * @return TreeItem - The leaf node that was found */ private TreeItem findAndClick(IUIContext ui, TreeItem parent) throws WidgetSearchException { TreeItemByIndexLocator treeItemLoc = new TreeItemByIndexLocator(_index, _labelPattern, parent, _parentTree); ui.click(treeItemLoc); TreeItem thisItem = treeItemLoc.getFoundItem(); String message = MessageFormat.format( "DID NOT FIND A TREE NODE FOR ITEM <{0}>", //$NON-NLS-1$ new Object[] {toString()}); TestCase.assertNotNull(message, thisItem); TreeItem returnItem = thisItem; if (_child != null) { TreeItemTester itemTester = new TreeItemTester(); itemTester.actionExpandItem(thisItem); // Let the sub-nodes render new SWTIdleCondition().waitForIdle(); // Just for good measure ui.pause(1000); returnItem = _child.findAndClick(ui, thisItem); } return returnItem; }
/** Main test method. */ public void testtestSimpleJavaProjectCreation() throws Exception { IUIContext ui = getUI(); ui.click(new MenuItemLocator("File/New/Project...")); ui.wait(new ShellShowingCondition("New Project")); ui.click( new FilteredTreeItemLocator( "Java Project")); // ? https://fogbugz.instantiations.com/default.php?44689 ui.click(new FilteredTreeItemLocator("Java/Java Project")); ui.click(new ButtonLocator("&Next >")); ui.enterText("JP2"); ui.click(new ButtonLocator("&Finish")); ui.wait(new ShellDisposedCondition("New Java Project")); }
// NOTE: assumes target project is selected... public static void createJavaClass(IUIContext ui, String sourceFolder, String className) throws WidgetSearchException { try { TypingLinuxHelper.switchToInsertStrategyIfNeeded(); ensureNotNull(ui, className); ui.click(new MenuItemLocator("File/New/Class")); ui.wait(new ShellShowingCondition("New Java Class")); ui.click(2, new LabeledTextLocator("Source fol&der:")); ui.enterText(sourceFolder); ui.click(2, new LabeledTextLocator("Na&me:")); ui.enterText(className); ui.assertThat(new ButtonLocator("Finish").isEnabled()); ui.click(new ButtonLocator("Finish")); ui.wait(new ShellDisposedCondition("New Java Class")); } finally { TypingLinuxHelper.restoreOriginalStrategy(); } }
/** * First scroll the source and target FigureCanvases as needed to ensure the source and target * IFigures are showing. Then move the mouse over the source IFigure and drag and drop it on to * the target IFigure * * @since 3.8.0 * @param ui - driver for ui generated input * @param sourceCanvas - the FigureCanvas containing the source IFigure * @param source - the IFigure to be dragged and dropped * @param targetCanvas - the FigureCanvas containing the target IFigure * @param target - the IFigure on which to drop the source */ public void dragAndDrop( IUIContext ui, FigureCanvas sourceCanvas, IFigure source, FigureCanvas targetCanvas, IFigure target) { TestCase.assertNotNull(sourceCanvas); TestCase.assertNotNull(source); TestCase.assertNotNull(targetCanvas); TestCase.assertNotNull(target); // first scroll the source and target canvases // as necessary to show the figures FigureTester figureTester = new FigureTester(); figureTester.scrollForClick(sourceCanvas, source); figureTester.scrollForClick(targetCanvas, target); // compute the source screen location Rectangle sourceRect = source.getBounds().getCopy(); source.translateToAbsolute(sourceRect); // compute the target screen location Rectangle targetRect = source.getBounds().getCopy(); target.translateToAbsolute(targetRect); try { // move the mouse over the source ui.mouseMove(new XYLocator(sourceRect.x, sourceRect.y)); // drag and drop on the target ui.dragTo(new XYLocator(targetRect.x, targetRect.y)); } // SHOULD NEVER HAPPEN BECAUSE WE'RE USING THE XYLOCATOR catch (WidgetSearchException ex) { Draw2DActivator.logException(ex); TestCase.fail(ex.getLocalizedMessage()); } }
/** * compare - Scan each line of the given file and search for the given String in that line. The * String *must not* span multiple lines since this comparison will search line by line in the * given file. The given String does not need to be a full line of text and will be considered a * match if a line of text in the given file contains the String. * * @param ui - Driver for UI generated input * @param baselineString - A single line of text (does not need to be a complete line) to search * for in the given file. * @param actualFile - Source file whose lines are to be searched for the given String * @param exists - True if the text should exist in the target file for the verification to * succeed; False if the text should not exist for the verification to succeed * @throws DifferenceException - Thrown when the String is not found in any of the lines in the * file and it was expected to be found, or when the String was found in at least one of the * lines in the file and it was expected to not be found */ public void compare(IUIContext ui, String baselineString, File actualFile, boolean exists) throws DifferenceException { TestCase.assertNotNull(baselineString); TestCase.assertNotNull(actualFile); ui.wait(new FileExistsCondition(actualFile, true)); boolean matchFound = false; try { InputStream actualStream = new FileInputStream(actualFile); try { InputStreamReader actualreader = new InputStreamReader(actualStream); BufferedReader actual = new BufferedReader(actualreader); String nextActualLine = actual.readLine(); int line = 1; while ((nextActualLine != null) && !matchFound) { matchFound = nextActualLine.contains(baselineString); nextActualLine = actual.readLine(); line++; } } finally { if (actualStream != null) { actualStream.close(); } } } catch (IOException ioe) { ExceptionHandler.handle(ioe); } if (matchFound != exists) { throw new LineDifferenceException(baselineString, actualFile, exists); } }
/** * Walk the tree path described by this node: Click this node to select it then, if there is a * child tree path node, expand this node and recurse into the child TreeItemPathLocator. When the * leaf node is found, context click the node and execute the menu action with the given menu item * label * * @param ui - Driver for UI-generated input * @param menuItem - The path to the menu item to select (can be a regular expression as described * in the StringComparator utility) * @throws WidgetSearchException - If the TreeItem described by this tree item path cannot be * found for any reason */ public void findAndContextClick(IUIContext ui, String menuPath) throws WidgetSearchException { TreeItem leafNode = findAndClick(ui, null); ui.contextClick(new WidgetReference(leafNode), menuPath); }
/* (non-Javadoc) * @see com.windowtester.runtime.condition.IsSelected#isSelected(com.windowtester.runtime.IUIContext) */ public boolean isSelected(IUIContext ui) throws WidgetSearchException { JRadioButtonMenuItem item = (JRadioButtonMenuItem) ((IWidgetReference) ui.find(this)).getWidget(); return item.isSelected(); }
public static void createJavaProject(IUIContext ui, String projectName) throws WidgetSearchException { ensureNotNull(ui, projectName); try { TypingLinuxHelper.switchToInsertStrategyIfNeeded(); ui.click(new MenuItemLocator("File/New/Project...")); ui.wait(new ShellShowingCondition("New Project")); ui.click(new TreeItemLocator("Java/Java Project")); ui.click(new ButtonLocator("Next >")); ui.assertThat(new IsEnabledCondition(new ButtonLocator("Finish"), false)); // new DebugHelper().printWidgets(); // WidgetPrinter printer = new WidgetPrinter(); // DisplayReference.getDefault().getActiveShell().accept(printer); // System.out.println(printer.asString()); // Assert.fail(); ui.click(new LabeledTextLocator("&Project name:")); ui.enterText(projectName); ui.assertThat(new IsEnabledCondition(new ButtonLocator("Finish"), true)); ui.click(new ButtonLocator(SEP_SRC_FOLDER_CREATION_LABEL)); ui.click(new ButtonLocator("Finish")); ui.wait(new ShellDisposedCondition("New Java Project")); ui.wait(new JobsCompleteCondition()); ui.wait(new SWTIdleCondition()); } finally { TypingLinuxHelper.restoreOriginalStrategy(); } }
/** Main test method. */ public void testsaveDisabledAfterNew() throws Exception { IUIContext ui = getUI(); ui.click(new JButtonLocator("New")); ui.assertThat(new JButtonLocator("Save").isEnabled(false)); }