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

The following examples show how to use org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot#waitUntil() . 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: SwtBotTreeUtilities.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
/**
 * Wait until the given tree has items, then return the first item.
 *
 * @throws TimeoutException if no items appear within the default timeout
 */
public static SWTBotTreeItem waitUntilTreeHasItems(SWTWorkbenchBot bot, SWTBotTree tree) {
  bot.waitUntil(
      new DefaultCondition() {
        @Override
        public String getFailureMessage() {
          return "Tree items never appeared";
        }

        @Override
        public boolean test() throws Exception {
          return tree.hasItems();
        }
      });
  return tree.getAllItems()[0];
}
 
Example 2
Source File: SwtBotTreeUtilities.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
/**
 * Wait until the given tree item has items, and return the first item.
 *
 * @throws TimeoutException if no items appear within the default timeout
 */
public static SWTBotTreeItem waitUntilTreeHasItems(SWTWorkbenchBot bot, SWTBotTreeItem treeItem) {
  bot.waitUntil(
      new DefaultCondition() {
        @Override
        public String getFailureMessage() {
          return "Tree items never appeared";
        }

        @Override
        public boolean test() throws Exception {
          SWTBotTreeItem[] children = treeItem.getItems();
          if (children.length == 1 && "".equals(children[0].getText())) {
            // Work around odd bug seen only on Windows and Linux.
            // https://github.com/GoogleCloudPlatform/google-cloud-eclipse/issues/2569
            treeItem.collapse();
            treeItem.expand();
            children = treeItem.getItems();
          }
          return children.length > 0;
        }
      });
  return treeItem.getItems()[0];
}
 
Example 3
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 4
Source File: SWTBotUtils.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Creates an experiment
 *
 * @param bot
 *            a given workbench bot
 * @param projectName
 *            the name of the project, creates the project if needed
 * @param expName
 *            the experiment name
 */
public static void createExperiment(SWTWorkbenchBot bot, String projectName, final @NonNull String expName) {
    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
    TmfProjectElement tmfProject = TmfProjectRegistry.getProject(project, true);
    TmfExperimentFolder expFolder = tmfProject.getExperimentsFolder();
    assertNotNull(expFolder);
    NewExperimentOperation operation = new NewExperimentOperation(expFolder, expName);
    operation.run(new NullProgressMonitor());

    bot.waitUntil(new DefaultCondition() {
        @Override
        public boolean test() throws Exception {
            TmfExperimentElement experiment = expFolder.getExperiment(expName);
            return experiment != null;
        }

        @Override
        public String getFailureMessage() {
            return "Experiment (" + expName + ") couldn't be created";
        }
    });
}
 
Example 5
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 6
Source File: AddSpecWizardTest.java    From tlaplus with MIT License 6 votes vote down vote up
@BeforeClass
public static void beforeClass() throws Exception {
	RCPTestSetupHelper.beforeClass();
	
	// Force shell activation to counter, no active Shell when running SWTBot tests in Xvfb/Xvnc
	// see https://wiki.eclipse.org/SWTBot/Troubleshooting#No_active_Shell_when_running_SWTBot_tests_in_Xvfb
	Display.getDefault().syncExec(new Runnable() {
		public void run() {
			PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().forceActive();
		}
	});
	
	bot = new SWTWorkbenchBot();

	// Wait for the Toolbox shell to be available
	final Matcher<Shell> withText = withText("TLA+ Toolbox");
	bot.waitUntil(Conditions.waitForShell(withText), 30000);
	
	// Wait for the Toolbox UI to be fully started.
	final Matcher<MenuItem> withMnemonic = WidgetMatcherFactory.withMnemonic("File");
	final Matcher<MenuItem> matcher = WidgetMatcherFactory.allOf(WidgetMatcherFactory.widgetOfType(MenuItem.class),
			withMnemonic);
	bot.waitUntil(Conditions.waitForMenu(bot.shell("TLA+ Toolbox"), matcher), 30000);
}
 
Example 7
Source File: ShellUiTestUtil.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Tests if a shell with a specific type of data contained (e.g. Window).
 * 
 * @param bot
 *          to use
 * @param clazz
 *          class of data contained to check for
 */
@SuppressWarnings("rawtypes")
public static void assertShellWithDataTypeVisible(final SWTWorkbenchBot bot, final Class clazz) {
  bot.waitUntil(Conditions.waitForShell(new BaseMatcher<Shell>() {
    @SuppressWarnings("unchecked")
    public boolean matches(final Object item) {
      return UIThreadRunnable.syncExec(new Result<Boolean>() {
        public Boolean run() {
          if (item instanceof Shell) {
            Object shellData = ((Shell) item).getData();
            if (shellData != null) {
              return clazz.isAssignableFrom(shellData.getClass());
            }
          }
          return false;
        }
      });
    }

    public void describeTo(final Description description) {
      description.appendText("Shell for " + clazz.getName());
    }
  }));
}
 
Example 8
Source File: DeleteSpecHandlerTest.java    From tlaplus with MIT License 6 votes vote down vote up
@BeforeClass
public static void beforeClass() throws Exception {
	RCPTestSetupHelper.beforeClass();
	
	// Force shell activation to counter, no active Shell when running SWTBot tests in Xvfb/Xvnc
	// see https://wiki.eclipse.org/SWTBot/Troubleshooting#No_active_Shell_when_running_SWTBot_tests_in_Xvfb
	Display.getDefault().syncExec(new Runnable() {
		public void run() {
			PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().forceActive();
		}
	});
	
	bot = new SWTWorkbenchBot();

	// Wait for the Toolbox shell to be available
	final Matcher<Shell> withText = withText("TLA+ Toolbox");
	bot.waitUntil(Conditions.waitForShell(withText), 30000);
	
	// Wait for the Toolbox UI to be fully started.
	final Matcher<MenuItem> withMnemonic = WidgetMatcherFactory.withMnemonic("File");
	final Matcher<MenuItem> matcher = WidgetMatcherFactory.allOf(WidgetMatcherFactory.widgetOfType(MenuItem.class),
			withMnemonic);
	bot.waitUntil(Conditions.waitForMenu(bot.shell("TLA+ Toolbox"), matcher), 30000);
}
 
Example 9
Source File: SWTBotUtils.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Close a view with a title
 *
 * @param title
 *            the title, like "welcome"
 * @param bot
 *            the workbench bot
 */
public static void closeView(String title, SWTWorkbenchBot bot) {
    final List<SWTBotView> openViews = bot.views();
    for (SWTBotView view : openViews) {
        if (view.getTitle().equalsIgnoreCase(title)) {
            view.close();
            bot.waitUntil(ConditionHelpers.viewIsClosed(view));
        }
    }
}
 
Example 10
Source File: FetchRemoteTracesTest.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private static SWTBotTreeItem getTreeItem(SWTWorkbenchBot bot, SWTBotTree tree, String... nodeNames) {
    if (nodeNames.length == 0) {
        return null;
    }

    SWTBotTreeItem currentNode = tree.getTreeItem(nodeNames[0]);
    for (int i = 1; i < nodeNames.length; i++) {
        String nodeName = nodeNames[i];
        bot.waitUntil(ConditionHelpers.isTreeChildNodeAvailable(nodeName, currentNode));
        SWTBotTreeItem newNode = currentNode.getNode(nodeName);
        currentNode = newNode;
    }

    return currentNode;
}
 
Example 11
Source File: AbstractSyntaxColoringTest.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Checks the given offset for the given {@link TextStyle}.
 *
 * @param editor
 *          the {@link XtextEditor}
 * @param offset
 *          the position to check
 * @param textStyle
 *          the expected {@link TextStyle}
 * @param bot
 *          instance of swt bot
 */
public static void assertTextStyle(final XtextEditor editor, final int offset, final TextStyle textStyle, final SWTWorkbenchBot bot) {
  bot.waitUntil(new DefaultCondition() {
    @Override
    public boolean test() {
      return areEqualStyleRanges(createStyleRange(offset, 1, createTextAttribute(textStyle)), getStyleRange(editor, offset));
    }

    @Override
    public String getFailureMessage() {
      return STYLE_ASSERTION_FAILURE_MESSAGE;
    }
  });
}
 
Example 12
Source File: ImportAndReadKernelSmokeTest.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private static void testStateSystemExplorer(String tracePath) {

        // Set up
        SWTWorkbenchBot bot = new SWTWorkbenchBot();
        SWTBotUtils.openView(CpuUsageView.ID);
        SWTBotView cpuUsageBot = bot.viewById(CpuUsageView.ID);

        // Open the view
        SWTBotUtils.openView(TmfStateSystemExplorer.ID);
        SWTBotView sseBot = bot.viewByTitle("State System Explorer");
        sseBot.show();
        Set<@NonNull Entry<String, Set<String>>> actualAnalyses = getSsNames(sseBot);
        assertTrue("Wrong state systems: expected: " + EXPECTED_ANALYSES + ", actual: " + actualAnalyses, actualAnalyses.containsAll(EXPECTED_ANALYSES));
        // Re-open the view and make sure it has the same results
        sseBot.close();
        SWTBotUtils.openView(TmfStateSystemExplorer.ID);
        sseBot = bot.viewByTitle("State System Explorer");
        sseBot.show();
        actualAnalyses = getSsNames(sseBot);
        assertTrue("Wrong state systems: expected: " + EXPECTED_ANALYSES + ", actual: " + actualAnalyses, actualAnalyses.containsAll(EXPECTED_ANALYSES));
        // Close the trace, and re-open it, let's compare one last time
        bot.closeAllEditors();
        bot.waitUntil(treeHasRows(sseBot.bot().tree(), 0));
        // re-open the trace
        SWTBotUtils.openTrace(TRACE_PROJECT_NAME, tracePath, KERNEL_TRACE_TYPE);
        actualAnalyses = getSsNames(sseBot);
        assertTrue("Wrong state systems: expected: " + EXPECTED_ANALYSES + ", actual: " + actualAnalyses, actualAnalyses.containsAll(EXPECTED_ANALYSES));
        sseBot.close();
        cpuUsageBot.close();
    }
 
Example 13
Source File: SWTBotActorFilterUtil.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * use it to access to the wizard "Export connector" (menu
 * Development<Connector>Export)
 */
public static void activateExportActorFilterShell(final SWTWorkbenchBot bot) {
    SWTBotTestUtil.waitUntilRootShellIsActive(bot);
    final Matcher<MenuItem> matcher = withMnemonic("Development");
    bot.waitUntil(Conditions.waitForMenu(bot.activeShell(), matcher), 40000);
    bot.menu("Development").menu("Actor filters").menu("Export...").click();
    bot.waitUntil(Conditions.shellIsActive(Messages.exportActorFilterTitle));
    bot.activeShell().setFocus();
}
 
Example 14
Source File: SwtBotTreeUtilities.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
/**
 * Wait until the given tree has not items.
 *
 * @throws TimeoutException if no items appear within the default timeout
 */
public static void waitUntilTreeHasNoItems(SWTWorkbenchBot bot, final SWTBotTree tree) {
  bot.waitUntil(
      new DefaultCondition() {
        @Override
        public String getFailureMessage() {
          return "Tree items never disappeared";
        }

        @Override
        public boolean test() throws Exception {
          return !tree.hasItems();
        }
      });
}
 
Example 15
Source File: ProjectExplorerAnalysisTest.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Test Class setup
 */
@BeforeClass
public static void init() {
    SWTBotUtils.initialize();

    /* Set up for swtbot */
    SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
    SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US";
    fLogger.removeAllAppenders();
    fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT));
    fBot = new SWTWorkbenchBot();

    /* Close welcome view */
    SWTBotUtils.closeView("Welcome", fBot);

    /* Switch perspectives */
    SWTBotUtils.switchToTracingPerspective();

    /* Finish waiting for eclipse to load */
    WaitUtils.waitForJobs();
    SWTBotUtils.createProject(TRACE_PROJECT_NAME);

    File kernelTraceFile = new File(CtfTmfTestTraceUtils.getTrace(CtfTestTrace.ARM_64_BIT_HEADER).getPath());
    CtfTmfTestTraceUtils.dispose(CtfTestTrace.ARM_64_BIT_HEADER);

    File ustTraceFile = new File(CtfTmfTestTraceUtils.getTrace(CtfTestTrace.DEBUG_INFO_SYNTH_EXEC).getPath());
    CtfTmfTestTraceUtils.dispose(CtfTestTrace.DEBUG_INFO_SYNTH_EXEC);

    fKernelTraceFile = kernelTraceFile.getName();
    fUstTraceFile = ustTraceFile.getName();

    /* Open Traces*/
    SWTBotUtils.openTrace(TRACE_PROJECT_NAME, kernelTraceFile.getAbsolutePath(), "org.eclipse.linuxtools.lttng2.kernel.tracetype");
    fBot.waitUntil(ConditionHelpers.isEditorOpened(fBot, fKernelTraceFile));

    SWTBotUtils.openTrace(TRACE_PROJECT_NAME, ustTraceFile.getAbsolutePath(), "org.eclipse.linuxtools.lttng2.ust.tracetype");
    fBot.waitUntil(ConditionHelpers.isEditorOpened(fBot, fUstTraceFile));

    /* Create experiment and open experiment */
    SWTBotUtils.createExperiment(fBot, TRACE_PROJECT_NAME, EXPERIMENT_NAME);

    SWTBotTreeItem project = SWTBotUtils.selectProject(fBot, TRACE_PROJECT_NAME);

    SWTBotTreeItem tracesFolder = SWTBotUtils.getTraceProjectItem(fBot, project, "Traces");
    tracesFolder.expand();

    SWTBotTreeItem ustTrace = tracesFolder.getNode(fUstTraceFile);
    SWTBotTreeItem kernelTrace = tracesFolder.getNode(fKernelTraceFile);
    SWTBotTreeItem experiment = SWTBotUtils.getTraceProjectItem(fBot, project, "Experiments", EXPERIMENT_NAME);

    ustTrace.dragAndDrop(experiment);
    kernelTrace.dragAndDrop(experiment);
    experiment.doubleClick();
}
 
Example 16
Source File: SWTBotUtils.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Clear the traces folder
 *
 * @param bot
 *            a given workbench bot
 * @param projectName
 *            the name of the project (needs to exist)
 */
public static void clearTracesFolder(SWTWorkbenchBot bot, String projectName) {
    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
    TmfProjectElement tmfProject = TmfProjectRegistry.getProject(project, false);
    TmfTraceFolder tracesFolder = tmfProject.getTracesFolder();
    if (tracesFolder == null) {
        return;
    }
    try {
        for (TmfTraceElement traceElement : tracesFolder.getTraces()) {
            traceElement.delete(null);
        }

        final IFolder resource = tracesFolder.getResource();
        resource.accept(new IResourceVisitor() {
            @Override
            public boolean visit(IResource visitedResource) throws CoreException {
                if (visitedResource != resource) {
                    visitedResource.delete(true, null);
                }
                return true;
            }
        }, IResource.DEPTH_ONE, 0);
    } catch (CoreException e) {
        fail(e.getMessage());
    }

    bot.waitUntil(new DefaultCondition() {
        private int fTraceNb = 0;

        @Override
        public boolean test() throws Exception {
            List<TmfTraceElement> traces = tracesFolder.getTraces();
            fTraceNb = traces.size();
            return fTraceNb == 0;
        }

        @Override
        public String getFailureMessage() {
            return "Traces Folder not empty (" + fTraceNb + ")";
        }
    });
}
 
Example 17
Source File: ConsoleViewContains.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 4 votes vote down vote up
public static void waitForConsoleOutput(SWTWorkbenchBot bot, String string, long timeout) {
  bot.waitUntil(waitForConsoleContains(string), timeout);
}
 
Example 18
Source File: SWTBotUtils.java    From tracecompass with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Close a view with an id
 *
 * @param viewId
 *            the view id, like
 *            "org.eclipse.linuxtools.tmf.ui.views.histogram"
 * @param bot
 *            the workbench bot
 */
public static void closeViewById(String viewId, SWTWorkbenchBot bot) {
    final SWTBotView view = bot.viewById(viewId);
    view.close();
    bot.waitUntil(ConditionHelpers.viewIsClosed(view));
}
 
Example 19
Source File: PreferenceUtil.java    From dsl-devkit with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Closes the preference dialog.
 *
 * @param bot
 *          the workbench bot which closes the dialog, must not be {@code null}.
 */
public static void closePreferenceDialog(final SWTWorkbenchBot bot) {
  bot.shell(SHELL_PREFERENCES).activate();
  bot.waitUntil(Conditions.shellIsActive(SHELL_PREFERENCES));
  bot.button("OK").click();
}
 
Example 20
Source File: SWTBotUtils.java    From tracecompass with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Get the active events editor. Note that this will wait until such editor
 * is available.
 *
 * @param workbenchBot
 *            a given workbench bot
 * @return the active events editor
 */
public static SWTBotEditor activeEventsEditor(final SWTWorkbenchBot workbenchBot) {
    ConditionHelpers.ActiveEventsEditor condition = new ConditionHelpers.ActiveEventsEditor(workbenchBot, null);
    workbenchBot.waitUntil(condition, ACTIVE_EDITOR_TIMEOUT);
    return condition.getActiveEditor();
}