Java Code Examples for org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot#shell()

The following examples show how to use org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot#shell() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractNewWizardTest.java    From aCute with Eclipse Public License 2.0 6 votes vote down vote up
protected SWTBotShell openWizard() {
	bot = new SWTWorkbenchBot();
	bot.menu("File").menu("New").menu("Other...").click();
	bot.waitUntil(Conditions.shellIsActive("New"));
	SWTBotShell shell = bot.shell("New");
	shell.activate();
	bot.tree().expandNode(".NET Core").select(".NET Core Project");
	bot.button("Next >").click();

	while (!bot.list(0).itemAt(0).equals("No available templates") && !bot.list(0).isEnabled()) {
		try {
			Thread.sleep(500);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	return shell;
}
 
Example 2
Source File: GuiUtils.java    From CodeCheckerEclipsePlugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Changes to CDT project.
 * 
 * @param perspective
 *            The perspective to be changed to.
 * @param bot
 *            the workbench bot to be used.
 */
public static void changePerspectiveTo(String perspective, SWTWorkbenchBot bot) {
    UIThreadRunnable.syncExec(new VoidResult() {
        public void run() {
            PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().forceActive();
        }
    });

    // Change the perspective via the Open Perspective dialog
    bot.menu(WINDOW_MENU).menu(PERSP_MENU).menu(OPEN_PERSP).menu(OTHER_MENU).click();
    SWTBotShell openPerspectiveShell = bot.shell(OPEN_PERSP);
    openPerspectiveShell.activate();

    // select the dialog
    bot.table().select(perspective);
    bot.button("Open").click();

}
 
Example 3
Source File: SwtBotMenuActions.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
public static void openPerspective(SWTWorkbenchBot bot, String perspectiveLabel) {
  SwtBotUtils.print("Opening Perspective: " + perspectiveLabel);

  SWTBotShell shell = null;
  try {
    menu(bot, "Window").menu("Open Perspective").menu("Other...").click();

    shell = bot.shell("Open Perspective");

    bot.waitUntil(ActiveWidgetCondition.widgetMakeActive(shell));
    shell.bot().table().select(perspectiveLabel);

    shell.bot().button("OK").click();
    bot.waitUntil(Conditions.shellCloses(shell));
  } catch (Exception e) {
    if (shell != null && shell.isOpen()) shell.close();
    SwtBotUtils.printError("Couldn't open perspective '" + perspectiveLabel + "'\n"
        + "trying to activate already open perspective instead");
    // maybe somehow the perspective is already opened (by another test before us)
    SWTBotPerspective perspective = bot.perspectiveByLabel(perspectiveLabel);
    perspective.activate();
  }

  SwtBotUtils.print("Opened Perspective: " + perspectiveLabel);
}
 
Example 4
Source File: SwtBotProjectActions.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
/**
 * Create a Maven project based on an archetype.
 */
public static IProject createMavenProject(SWTWorkbenchBot bot, String groupId, String artifactId,
    String archetypeGroupId, String archetypeArtifactId, String archetypeVersion,
    String archetypeUrl, String javaPackage) {
  bot.menu("File").menu("New").menu("Project...").click();

  SWTBotShell shell = bot.shell("New Project");
  shell.activate();

  SwtBotTreeUtilities.select(bot, bot.tree(), "Maven", "Maven Project");
  bot.button("Next >").click();

  // we want to specify an archetype
  bot.checkBox("Create a simple project (skip archetype selection)").deselect();
  bot.button("Next >").click();

  // open archetype dialog
  SwtBotTestingUtilities.clickButtonAndWaitForWindowChange(bot, bot.button("Add Archetype..."));

  bot.comboBox(0).setText(archetypeGroupId);
  bot.comboBox(1).setText(archetypeArtifactId);
  bot.comboBox(2).setText(archetypeVersion);
  bot.comboBox(3).setText(archetypeUrl);

  // close archetype dialog
  // After OK, it will take a minute to download
  SwtBotTestingUtilities.clickButtonAndWaitForWindowChange(bot, bot.button("OK"));

  // move to last wizard
  bot.button("Next >").click();

  // set archetype inputs
  bot.comboBoxWithLabel("Group Id:").setText(groupId);
  bot.comboBoxWithLabel("Artifact Id:").setText(artifactId);
  bot.comboBoxWithLabel("Package:").setText(javaPackage);

  SwtBotTestingUtilities.clickButtonAndWaitForWindowClose(bot, bot.button("Finish"));
  return getWorkspaceRoot().getProject("testartifact");
}
 
Example 5
Source File: SwtBotAppEngineActions.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
private static void openImportProjectsWizard(
    SWTWorkbenchBot bot, String wizardCategory, String importWizardName) {
  bot.menu("File").menu("Import...").click();
  SWTBotShell shell = bot.shell("Import");
  shell.activate();
  SwtBotTreeUtilities.select(bot, bot.tree(), wizardCategory, importWizardName);
}
 
Example 6
Source File: GuiUtils.java    From CodeCheckerEclipsePlugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Deletes a project from workspace.
 * 
 * @param projectName
 *            The project to be deleted.
 * @param deleteFromDisk
 *            Delete from the disk.
 * @param bot
 *            The workbench bot to be used.
 */
public static void deleteProject(String projectName, boolean deleteFromDisk, SWTWorkbenchBot bot) {
    bot.tree().getTreeItem(projectName).contextMenu("Delete").click();
    bot.waitUntil(Conditions.shellIsActive(DELETE_RESOURCES));
    SWTBotShell shell = bot.shell(DELETE_RESOURCES);
    shell.activate();
    if (deleteFromDisk)
        bot.checkBox("Delete project contents on disk (cannot be undone)").select();
    bot.button(OK).click();
    bot.waitUntil(Conditions.shellCloses(shell), LONG_TIME_OUT);
}
 
Example 7
Source File: CoreSwtbotTools.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns {@code true} if the SWTBot finds the specified window.
 *
 * @param bot
 *          the {@link SWTWorkbenchBot}, must not be {@code null}
 * @param windowName
 *          the name of the window to search for, must not be {@code null}
 * @return {@code true} if a window was found, {@code false} otherwise
 */
public static boolean checkOpenWindow(final SWTWorkbenchBot bot, final String windowName) {
  Assert.isNotNull(bot, ARGUMENT_BOT);
  Assert.isNotNull(windowName, "windowName");
  Boolean windowFound = false;
  try {
    final SWTBotShell shell = bot.shell(windowName);
    shell.isActive();
    windowFound = true;
  } catch (WidgetNotFoundException exception) {
    throw new WrappedException("Error during searching for window", exception);
  }
  return windowFound;
}
 
Example 8
Source File: CoreSwtbotTools.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Switching to a new Perspective.
 *
 * @param bot
 *          to work with, must not be {@code null}
 * @param perspective
 *          the new perspective to open, must not be {@code null}
 */
public static void switchPerspective(final SWTWorkbenchBot bot, final String perspective) {
  Assert.isNotNull(bot, ARGUMENT_BOT);
  Assert.isNotNull(perspective, "perspective");
  // Change the perspective via the Open Perspective dialog
  bot.menu("Window").menu("Open Perspective").menu("Other...").click();
  final SWTBotShell shell = bot.shell("Open Perspective");
  shell.activate();

  // select the dialog
  bot.table().select(perspective);
  bot.button("OK").click();
}
 
Example 9
Source File: CoreSwtbotTools.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Open a specific Avaloq Prefrences Page.
 *
 * @param bot
 *          to work with, must not be {@code null}
 * @param section
 *          the name of the desired page (e.g. 'Database'), must not be {@code null}
 */
public static void openAvaloqPreferencesSection(final SWTWorkbenchBot bot, final String section) {
  Assert.isNotNull(bot, ARGUMENT_BOT);
  Assert.isNotNull(section, "section");
  bot.menu("Window").menu("Preferences").click();
  final SWTBotShell shell = bot.shell("Preferences");
  shell.activate();
  final SWTBotTreeItem item = bot.tree().getTreeItem("Avaloq");
  CoreSwtbotTools.waitForItem(bot, item);
  CoreSwtbotTools.expandNode(bot.tree(), "Avaloq").select(section);
}
 
Example 10
Source File: StandardImportWizardTest.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private static void selectSyslog() throws Exception {
    SWTWorkbenchBot workbenchBot = getSWTBot();
    SWTBotShell shell = workbenchBot.shell("Trace Import");
    shell.setFocus();
    SWTBot bot = shell.bot();
    URL resource = TmfCoreTestPlugin.getDefault().getBundle().getResource(TEST_FOLDER_NAME);
    String path = FileLocator.toFileURL(resource).toURI().getPath();
    SWTBotImportWizardUtils.selectImportFromDirectory(bot, path);
    for (int i = 1; i <= 6; i++) {
        SWTBotImportWizardUtils.selectFile(bot, "syslog" + i, TEST_FOLDER_NAME);
    }
}
 
Example 11
Source File: SwtBotAppEngineActions.java    From google-cloud-eclipse with Apache License 2.0 4 votes vote down vote up
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.select(
      bot, bot.tree(), "Google Cloud Platform", "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_8) {
      bot.comboBoxWithLabel("Java version:").setSelection("Java 8, Servlet 3.1");
    } else if (runtime == AppEngineRuntime.STANDARD_JAVA_8_SERVLET_25) {
      bot.comboBoxWithLabel("Java version:").setSelection("Java 8, Servlet 2.5");
    } 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;
}
 
Example 12
Source File: GuiUtils.java    From CodeCheckerEclipsePlugin with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Open desired dialog specified by it's title in preferences dialog.
 * 
 * @param tab
 *            The desired preferences tab.
 * @param bot
 *            The workbench bot to be used.
 * @return The newly opened shell.
 */
public static SWTBotShell getPreferencesTab(String tab, SWTWorkbenchBot bot) {
    bot.menu(WINDOW_MENU).menu(PREFERENCES).click();
    SWTBotShell shell = bot.shell(PREFERENCES);
    shell.activate();
    bot.tree().getTreeItem(tab).select();
    return shell;
}