private static boolean waitUntilTreeHasItemImpl(SWTBot bot, final TreeItem tree, final String nodeText) { try { bot.waitUntil(new DefaultCondition() { @Override public String getFailureMessage() { return "Could not find node with text " + nodeText; } @Override public boolean test() throws Exception { return getTreeItem(tree, nodeText) != null; } }); } catch (TimeoutException ex) { return false; } return true; }
private static boolean waitUntilTreeHasTextImpl(SWTBot bot, final TreeItem tree) { try { bot.waitUntil(new DefaultCondition() { @Override public String getFailureMessage() { return "Not all of the nodes in the tree have text."; } @Override public boolean test() throws Exception { return treeItemHasText(tree); } }); } catch (TimeoutException ex) { return false; } return true; }
/** * Blocks the caller until the tree item has the given item text. * * @param tree the tree item to search * @param nodeText the item text to look for * @throws org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException if the item could not * be found within the timeout period */ private static void waitUntilTreeItemHasItem(SWTBot bot, final SWTBotTreeItem tree, final String nodeText) { // Attempt #1 if (!waitUntilTreeHasItemImpl(bot, tree.widget, nodeText)) { // Attempt #2: Something went wrong, try to cautiously reopen it. bot.sleep(1000); // There isn't a method to collapse, so double-click instead tree.doubleClick(); bot.waitUntil(new TreeCollapsedCondition(tree.widget)); bot.sleep(1000); tree.expand(); bot.waitUntil(new TreeExpandedCondition(tree.widget)); if (!waitUntilTreeHasItemImpl(bot, tree.widget, nodeText)) { printTree(tree.widget); throw new TimeoutException( String.format("Timed out waiting for %s, giving up...", nodeText)); } } }
private static void openImportProjectsWizard(SWTWorkbenchBot bot, String wizardCategory, String importWizardName) { for (int tries = 1; true; tries++) { SWTBotShell shell = null; try { bot.menu("File").menu("Import...").click(); shell = bot.shell("Import"); shell.activate(); SwtBotTreeUtilities.waitUntilTreeHasItems(bot, bot.tree()); SWTBotTreeItem treeItem = bot.tree().expandNode(wizardCategory); SwtBotTreeUtilities.waitUntilTreeItemHasChild(bot, treeItem, importWizardName); treeItem.select(importWizardName); break; } catch (TimeoutException e) { if (tries == 2) { throw e; } else if (shell != null) { shell.close(); } } } }
/** * Import a Maven project from a zip file */ public static IProject importMavenProject(SWTWorkbenchBot bot, String projectName, File extractedLocation) { openImportProjectsWizard(bot, "Maven", "Existing Maven Projects"); bot.button("Next >").click(); bot.comboBoxWithLabel("Root Directory:").setText(extractedLocation.getAbsolutePath()); bot.button("Refresh").click(); try { SwtBotTestingUtilities.clickButtonAndWaitForWindowClose(bot, bot.button("Finish")); } catch (TimeoutException ex) { System.err.println("FATAL: timed out while waiting for the wizard to close. Forcibly killing " + "all shells: https://github.com/GoogleCloudPlatform/google-cloud-eclipse/issues/1925"); System.err.println("FATAL: You will see tons of related errors: \"Widget is disposed\", " + "\"Failed to execute runnable\", \"IllegalStateException\", etc."); SwtBotWorkbenchActions.killAllShells(bot); throw ex; } SwtBotTimeoutManager.resetTimeout(); IProject project = waitUntilFacetedProjectExists(bot, getWorkspaceRoot().getProject(projectName)); SwtBotWorkbenchActions.waitForProjects(bot, project); return project; }
/** * Waits until the node collapses. * * @param bot * bot to work with, must not be {@code null} * @param node * node to wait for, must not be {@code null} */ public static void safeBlockingCollapse(final SWTWorkbenchBot bot, final SWTBotTreeItem node) { Assert.isNotNull(bot, ARGUMENT_BOT); Assert.isNotNull(node, ARGUMENT_NODE); if (node.isExpanded()) { node.collapse(); try { bot.waitUntil(new DefaultCondition() { @Override @SuppressWarnings("PMD.JUnit4TestShouldUseTestAnnotation") public boolean test() { return !node.isExpanded(); } @Override public String getFailureMessage() { return "Timeout for node to collapse"; } }, TIMEOUT_FOR_NODE_TO_COLLAPSE_EXPAND); } catch (TimeoutException e) { // Try one last time and do not wait anymore node.collapse(); } } }
private static boolean waitUntilTreeHasItemImpl(SWTBot bot, final TreeItem tree, final String nodeText) { try { bot.waitUntil(new DefaultCondition() { @Override public String getFailureMessage() { return "Could not find node with text " + nodeText; } @Override public boolean test() throws Exception { return getTreeItem(tree, nodeText) != null; } }); } catch (TimeoutException e) { return false; } return true; }
private static boolean waitUntilTreeHasTextImpl(SWTBot bot, final TreeItem tree) { try { bot.waitUntil(new DefaultCondition() { @Override public String getFailureMessage() { return "Not all of the nodes in the tree have text."; } @Override public boolean test() throws Exception { return doesTreeItemHaveText(tree); } }); } catch (TimeoutException e) { return false; } return true; }
/** * Blocks the caller until all of the direct children of the tree have text. The assumption is * that the tree does not have any "empty" children. * * TODO: Refactor some of this logic; it follows the same general pattern as * {@link #waitUntilTreeItemHasItem(SWTBot, SWTBotTreeItem, String)}. * * @param tree the tree to search * @throws TimeoutException if all of the direct children of the tree do not have text within the * timeout period */ public static void waitUntilTreeHasText(SWTBot bot, final SWTBotTreeItem tree) throws TimeoutException { // Attempt #1 if (!waitUntilTreeHasTextImpl(bot, tree.widget)) { // Attempt #2: Something went wrong, try to cautiously reopen it. bot.sleep(1000); // There isn't a method to collapse, so double-click instead tree.doubleClick(); bot.waitUntil(new TreeCollapsedCondition(tree.widget)); bot.sleep(1000); tree.expand(); bot.waitUntil(new TreeExpandedCondition(tree.widget)); if (!waitUntilTreeHasTextImpl(bot, tree.widget)) { printTree(tree.widget); throw new TimeoutException( "Timed out waiting for text of the tree's children, giving up..."); } } }
public boolean create (String project,String packageRootFragment, String pkg,String targetFilename,String targetFormat,String checkTestBox,boolean finish) { try { prepare (project,packageRootFragment,pkg,targetFilename,targetFormat, checkTestBox); if (!finish) return true; SWTBotButton fbutton = bot.button("Finish"); fbutton.click(); bot.waitUntil(Conditions.shellCloses(this.shell), 10 * SWTBotPreferences.TIMEOUT); return true; } catch (TimeoutException e) { return false; } }
/** * Blocks the caller until all of the direct children of the tree have text. The assumption is * that the tree does not have any "empty" children. * * @param tree the tree to search * @throws TimeoutException if any of the direct children of the tree do not have text within the * timeout period */ public static void waitUntilTreeHasText(SWTBot bot, final SWTBotTreeItem tree) throws TimeoutException { // TODO: Refactor some of this logic; it follows the same general pattern as // {@link #waitUntilTreeItemHasItem(SWTBot, SWTBotTreeItem, String)}. // Attempt #1 if (!waitUntilTreeHasTextImpl(bot, tree.widget)) { // Attempt #2: Something went wrong, try to cautiously reopen it. bot.sleep(1000); // There isn't a method to collapse, so double-click instead tree.doubleClick(); bot.waitUntil(new TreeCollapsedCondition(tree.widget)); bot.sleep(1000); tree.expand(); bot.waitUntil(new TreeExpandedCondition(tree.widget)); if (!waitUntilTreeHasTextImpl(bot, tree.widget)) { printTree(tree.widget); throw new TimeoutException( "Timed out waiting for text of the tree's children, giving up..."); } } }
/** * Use the the Eclipse general import project wizard to import an existing project from a * location. */ public static IProject importNativeProject(SWTWorkbenchBot bot, String projectName, File extractedLocation) { openImportProjectsWizard(bot, "General", "Existing Projects into Workspace"); bot.button("Next >").click(); // current comboBox is associated with a radio button // with "Select root directory:" bot.comboBox().setText(extractedLocation.getAbsolutePath()); bot.button("Refresh").click(); // can take a loooong time to resolve jars (e.g. servlet-api.jar) from Maven Central int libraryResolutionTimeout = 300 * 1000/* ms */; SwtBotTimeoutManager.setTimeout(libraryResolutionTimeout); try { SwtBotTestingUtilities.clickButtonAndWaitForWindowClose(bot, bot.button("Finish")); } catch (TimeoutException ex) { System.err.println("FATAL: timed out while waiting for the wizard to close. Forcibly killing " + "all shells: https://github.com/GoogleCloudPlatform/google-cloud-eclipse/issues/1925"); System.err.println("FATAL: You will see tons of related errors: \"Widget is disposed\", " + "\"Failed to execute runnable\", \"IllegalStateException\", etc."); SwtBotWorkbenchActions.killAllShells(bot); throw ex; } SwtBotTimeoutManager.resetTimeout(); IProject project = waitUntilFacetedProjectExists(bot, getWorkspaceRoot().getProject(projectName)); SwtBotWorkbenchActions.waitForProjects(bot, project); return project; }
@Override public void waitUntilWidgetAppears(final ICondition waitForWidget) { try { waitUntil(waitForWidget, SHORT_TIME_OUT, SHORT_INTERVAL); } catch (TimeoutException e) { throw new WidgetNotFoundException("Could not find widget.", e); //$NON-NLS-1$ } }
/** * Waits until the node expands. * * @param bot * bot to work with, must not be {@code null} * @param node * node to wait for, must not be {@code null} */ public static void safeBlockingExpand(final SWTWorkbenchBot bot, final SWTBotTreeItem node) { Assert.isNotNull(bot, ARGUMENT_BOT); Assert.isNotNull(node, ARGUMENT_NODE); if (!node.isExpanded()) { node.expand(); try { bot.waitUntil(new DefaultCondition() { @Override @SuppressWarnings("PMD.JUnit4TestShouldUseTestAnnotation") public boolean test() { return node.isExpanded(); } @Override public String getFailureMessage() { return "Timeout for node to expand"; } }, TIMEOUT_FOR_NODE_TO_COLLAPSE_EXPAND); } catch (TimeoutException e) { // Try one last time and do not wait anymore node.expand(); } } }
@Test public void testEnableDisableSynchronization() throws CoreException, IOException, InterruptedException { String expectedNewGenerator = "random(vertex_coverage(50))"; PetClinicProject.create (bot,gwproject); // At this step the generator is "random(edge_coverage(100))" IFile veterinarien = PetClinicProject.getVeterinariensSharedStateImplFile(gwproject); ICompilationUnit cu = JavaCore.createCompilationUnitFrom(veterinarien); String oldGenerator = JDTManager.findPathGeneratorInGraphWalkerAnnotation(cu); SourceHelper.updatePathGenerator(veterinarien, oldGenerator, expectedNewGenerator); cu = JavaCore.createCompilationUnitFrom(veterinarien); String newGenerator = JDTManager.findPathGeneratorInGraphWalkerAnnotation(cu); assertEquals(newGenerator,expectedNewGenerator); String location = JDTManager.getGW4EGeneratedAnnotationValue(cu,"value"); IPath path = new Path (gwproject).append(location); IFile graphModel = (IFile)ResourceManager.getResource(path.toString()); IPath buildPolicyPath = ResourceManager.getBuildPoliciesPathForGraphModel(graphModel); IFile buildPolicyFile = (IFile)ResourceManager.getResource(buildPolicyPath.toString()); PropertyValueCondition condition = new PropertyValueCondition(buildPolicyFile,graphModel.getName(),"random(edge_coverage(100));I;random(vertex_coverage(50));I;"); bot.waitUntil(condition); GW4EProjectPreference gwpp = new GW4EProjectPreference(bot, gwproject); GW4EProjectProperties page = gwpp.openPropertiesPage( ); page.toggleSynchronizationButton(); page.ok(); cu = JavaCore.createCompilationUnitFrom(veterinarien); oldGenerator = JDTManager.findPathGeneratorInGraphWalkerAnnotation(cu); SourceHelper.updatePathGenerator(veterinarien, oldGenerator, "random(edge_coverage(80))"); cu = JavaCore.createCompilationUnitFrom(veterinarien); newGenerator = JDTManager.findPathGeneratorInGraphWalkerAnnotation(cu); // Nothing should have changed condition = new PropertyValueCondition(buildPolicyFile,graphModel.getName(),"random(edge_coverage(100));I;random(vertex_coverage(50));I;"); bot.waitUntil(condition); page = gwpp.openPropertiesPage(); page.toggleSynchronizationButton(); page.ok(); cu = JavaCore.createCompilationUnitFrom(veterinarien); oldGenerator = JDTManager.findPathGeneratorInGraphWalkerAnnotation(cu); SourceHelper.updatePathGenerator(veterinarien, oldGenerator, "random(edge_coverage(80))"); cu = JavaCore.createCompilationUnitFrom(veterinarien); newGenerator = JDTManager.findPathGeneratorInGraphWalkerAnnotation(cu); // should have changed try { condition = new PropertyValueCondition(buildPolicyFile,graphModel.getName(),"random(vertex_coverage(50));I;random(edge_coverage(80));I;"); bot.waitUntil(condition); } catch (TimeoutException e) { condition = new PropertyValueCondition(buildPolicyFile,graphModel.getName(),"random(edge_coverage(80));I;random(vertex_coverage(50));I;"); bot.waitUntil(condition); } }
public static IProject createWebAppProject(SWTWorkbenchBot bot, String projectName, String location, String javaPackage, AppEngineRuntime runtime, Runnable extraBotActions) { bot.menu("File").menu("New").menu("Project...").click(); SWTBotShell shell = bot.shell("New Project"); shell.activate(); SwtBotTreeUtilities.waitUntilTreeHasItems(bot, bot.tree()); bot.tree().expandNode("Google Cloud Platform") .select("Google App Engine Standard Java Project"); bot.button("Next >").click(); if (extraBotActions != null) { extraBotActions.run(); } bot.textWithLabel("Project name:").setText(projectName); if (location == null) { bot.checkBox("Use default location").select(); } else { bot.checkBox("Use default location").deselect(); bot.textWithLabel("Location:").setText(location); } if (javaPackage != null) { bot.textWithLabel("Java package:").setText(javaPackage); } if (runtime != null) { if (runtime == AppEngineRuntime.STANDARD_JAVA_7) { bot.comboBoxWithLabel("Java version:").setSelection("Java 7, Servlet 2.5"); } else if (runtime == AppEngineRuntime.STANDARD_JAVA_8) { bot.comboBoxWithLabel("Java version:").setSelection("Java 8, Servlet 3.1"); } else { Assert.fail("Runtime not handled: " + runtime); } } // can take a loooong time to resolve jars (e.g. servlet-api.jar) from Maven Central int libraryResolutionTimeout = 300 * 1000/* ms */; SwtBotTimeoutManager.setTimeout(libraryResolutionTimeout); try { SwtBotTestingUtilities.clickButtonAndWaitForWindowClose(bot, bot.button("Finish")); } catch (TimeoutException ex) { System.err.println("FATAL: timed out while waiting for the wizard to close. Forcibly killing " + "all shells: https://github.com/GoogleCloudPlatform/google-cloud-eclipse/issues/1925"); System.err.println("FATAL: You will see tons of related errors: \"Widget is disposed\", " + "\"Failed to execute runnable\", \"IllegalStateException\", etc."); SwtBotWorkbenchActions.killAllShells(bot); throw ex; } SwtBotTimeoutManager.resetTimeout(); IProject project = waitUntilFacetedProjectExists(bot, getWorkspaceRoot().getProject(projectName)); SwtBotWorkbenchActions.waitForProjects(bot, project); return project; }