Java Code Examples for org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView#close()

The following examples show how to use org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView#close() . 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: LamiChartViewerTest.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Reset the current perspective
 */
@After
public void resetPerspective() {
    SWTBotView viewBot = fViewBot;
    if (viewBot != null) {
        viewBot.close();
    }
    /*
     * UI Thread executes the reset perspective action, which opens a shell
     * to confirm the action. The current thread will click on the 'Yes'
     * button
     */
    Runnable runnable = () -> SWTBotUtils.anyButtonOf(fBot, "Yes", "Reset Perspective").click();
    UIThreadRunnable.asyncExec(() -> {
        IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getWorkbenchWindows()[0];
        ActionFactory.RESET_PERSPECTIVE.create(activeWorkbenchWindow).run();
    });
    runnable.run();
}
 
Example 2
Source File: SwtBotWorkbenchActions.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
/** Close the Welcome/Intro view, if found. Usually required on the first launch. */
public static void closeWelcome(SWTWorkbenchBot bot) {
  SWTBotView activeView = bot.activeView();
  if (activeView != null && activeView.getTitle().equals("Welcome")) {
    activeView.close();
  }
}
 
Example 3
Source File: SwtBotProjectHelper.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public static SWTBotShell newXtendProject(final SWTWorkbenchBot it, final String projectName) {
  SWTBotShell _xblockexpression = null;
  {
    final SWTBotShell shell = it.activeShell();
    final Function1<SWTBotView, Boolean> _function = (SWTBotView it_1) -> {
      String _title = it_1.getTitle();
      return Boolean.valueOf(Objects.equal(_title, "Welcome"));
    };
    SWTBotView _findFirst = IterableExtensions.<SWTBotView>findFirst(it.views(), _function);
    if (_findFirst!=null) {
      _findFirst.close();
    }
    it.perspectiveByLabel("Java").activate();
    SwtBotProjectHelper.fileNew(it, "Project...");
    it.shell("New Project").activate();
    SwtBotProjectHelper.expandNode(it.tree(), "Java").select("Java Project");
    it.button("Next >").click();
    SWTBotText _textWithLabel = it.textWithLabel("Project name:");
    _textWithLabel.setText(projectName);
    it.button("Next >").click();
    it.tabItem("Libraries").activate();
    it.button("Add Library...").click();
    it.shell("Add Library").activate();
    it.list().select("Xtend Library");
    it.button("Next >").click();
    it.button("Finish").click();
    it.button("Finish").click();
    _xblockexpression = shell.activate();
  }
  return _xblockexpression;
}
 
Example 4
Source File: SwtWorkbenchBot.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Close welcome page.
 */
public void closeWelcomePage() {
  final List<SWTBotView> introViews = views(withPartId("org.eclipse.ui.internal.introview"));
  for (SWTBotView introView : introViews) {
    introView.close();
  }
}
 
Example 5
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 6
Source File: KernelTimeGraphViewTestBase.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Test that re-opening a view repoopulates it properly.
 */
@Test
public void testOpenCloseOpen() {
    SWTBotView viewBot = openView();
    SWTBotTimeGraph tgBot = new SWTBotTimeGraph(viewBot.bot());
    Map<String, List<String>> before = getItemNames(tgBot);
    viewBot.close();
    viewBot = openView();
    tgBot = new SWTBotTimeGraph(viewBot.bot());
    Map<String, List<String>> after = getItemNames(tgBot);
    assertEquals(before, after);
}
 
Example 7
Source File: ImportAndReadKernelSmokeTest.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private void testHV(IViewPart vp) {
    SWTBotView hvBot = (new SWTWorkbenchBot()).viewById(HistogramView.ID);
    List<SWTBotToolbarButton> hvTools = hvBot.getToolbarButtons();
    for (SWTBotToolbarButton hvTool : hvTools) {
        if (hvTool.getToolTipText().toLowerCase().contains("lost")) {
            hvTool.click();
        }
    }
    HistogramView hv = (HistogramView) vp;
    final TmfSelectionRangeUpdatedSignal signal = new TmfSelectionRangeUpdatedSignal(hv, fDesired1.getTimestamp());
    final TmfSelectionRangeUpdatedSignal signal2 = new TmfSelectionRangeUpdatedSignal(hv, fDesired2.getTimestamp());
    hvBot.close();
    hv = (HistogramView) UIThreadRunnable.syncExec(() -> {
        try {
            return (PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(HistogramView.ID));
        } catch (PartInitException e) {
            // Do nothing, returning null fails
        }
        return null;
    });
    assertNotNull(hv);
    hvBot = (new SWTWorkbenchBot()).viewById(HistogramView.ID);
    hv.updateTimeRange(100000);
    WaitUtils.waitForJobs();
    hv.selectionRangeUpdated(signal);
    hv.broadcast(signal);
    WaitUtils.waitForJobs();
    SWTBotUtils.delay(1000);

    hv.updateTimeRange(1000000000);
    WaitUtils.waitForJobs();
    hv.selectionRangeUpdated(signal2);
    hv.broadcast(signal2);
    WaitUtils.waitForJobs();
    SWTBotUtils.delay(1000);
    assertNotNull(hv);
}
 
Example 8
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 9
Source File: TimeGraphViewTest.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Before the test is run, make the view see the items.
 *
 * Reset the perspective and close all the views.
 *
 * @throws TmfTraceException
 *             could not load a trace
 */
@Before
public void before() throws TmfTraceException {
    fBot = new SWTWorkbenchBot();
    fBot.closeAllEditors();
    for (SWTBotView viewBot : fBot.views()) {
        viewBot.close();
    }
    SWTBotUtils.openView(TimeGraphViewStub.ID);
    fViewBot = fBot.viewById(TimeGraphViewStub.ID);

    fViewBot.show();
    fTrace = new TmfTraceStub() {

        @Override
        public @NonNull String getName() {
            return "Stub";
        }

        @Override
        public TmfContext seekEvent(ITmfLocation location) {
            return new TmfContext();
        }

        @Override
        public ITmfTimestamp getInitialRangeOffset() {
            return TmfTimestamp.fromNanos(80);
        }
    };
    fTrace.setStartTime(TmfTimestamp.fromNanos(0));

    fTrace.setEndTime(TmfTimestamp.fromNanos(180));

    TmfTraceStub trace = fTrace;
    trace.initialize(null, "", ITmfEvent.class);
    assertNotNull(trace);
    fTimeGraph = new SWTBotTimeGraph(fViewBot.bot());

    // Wait for trace to be loaded
    fViewBot.bot().waitUntil(new TgConditionHelper(t -> fTimeGraph.getEntries().length == 0));
    fBounds = getBounds();
    UIThreadRunnable.syncExec(() -> TmfSignalManager.dispatchSignal(new TmfTraceOpenedSignal(this, trace, null)));
    // Wait for trace to be loaded
    fViewBot.bot().waitUntil(new TgConditionHelper(t -> fTimeGraph.getEntries().length >= 2));

    resetTimeRange();
    // Make sure the thumb is over 1 in size
    fBot.waitUntil(new TgConditionHelper(t -> fViewBot.bot().slider().getThumb() > 1));
}
 
Example 10
Source File: XYChartViewTest.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Before the test is run, make the view see the items.
 *
 * Reset the perspective and close all the views.
 *
 * @throws TmfTraceException
 *             could not load a trace
 */
@Before
public void before() throws TmfTraceException {
    fBot = new SWTWorkbenchBot();
    fBot.closeAllEditors();
    for (SWTBotView viewBot : fBot.views()) {
        viewBot.close();
    }
    fTrace = new TmfTraceStub() {

        @Override
        public @NonNull String getName() {
            return "Stub";
        }

        @Override
        public TmfContext seekEvent(ITmfLocation location) {
            return new TmfContext();
        }
    };
    fTrace.setStartTime(TmfTimestamp.fromNanos(0));

    fTrace.setEndTime(TmfTimestamp.fromNanos(180));

    TmfTraceStub trace = fTrace;
    trace.initialize(null, "", ITmfEvent.class);
    assertNotNull(trace);

    // Register trace to trace manager
    UIThreadRunnable.syncExec(() -> TmfSignalManager.dispatchSignal(new TmfTraceOpenedSignal(this, trace, null)));

    // Open view
    SWTBotUtils.openView(XYChartViewStub.ID);
    fViewBot = fBot.viewById(XYChartViewStub.ID);
    fViewBot.show();

    TmfChartView viewPart = (TmfChartView) fViewBot.getViewReference().getView(true);
    fXyViewer = viewPart.getChartViewer();

    // Wait till SWT chart is constructed
    fViewBot.bot().waitUntil(new DefaultCondition() {
        @Override
        public boolean test() throws Exception {
            return fXyViewer.getSwtChart() != null;
        }
        @Override
        public String getFailureMessage() {
            return "SWT Chart is null";
        }
    });

    // Wait for trace to be loaded
    resetTimeRange();
}
 
Example 11
Source File: XYChartViewTest.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Before the test is run, make the view see the items.
 *
 * Reset the perspective and close all the views.
 *
 * @throws TmfTraceException
 *             could not load a trace
 */
@Before
public void before() throws TmfTraceException {
    fBot = new SWTWorkbenchBot();
    fBot.closeAllEditors();
    for (SWTBotView viewBot : fBot.views()) {
        viewBot.close();
    }
    fTrace = new TmfTraceStub() {

        @Override
        public @NonNull String getName() {
            return "Stub";
        }

        @Override
        public TmfContext seekEvent(ITmfLocation location) {
            return new TmfContext();
        }
    };
    fTrace.setStartTime(TmfTimestamp.fromNanos(0));

    fTrace.setEndTime(TmfTimestamp.fromNanos(180));

    TmfTraceStub trace = fTrace;
    trace.initialize(null, "", ITmfEvent.class);
    assertNotNull(trace);

    // Register trace to trace manager
    UIThreadRunnable.syncExec(() -> TmfSignalManager.dispatchSignal(new TmfTraceOpenedSignal(this, trace, null)));

    // Open view
    SWTBotUtils.openView(XYChartViewStub.ID);
    fViewBot = fBot.viewById(XYChartViewStub.ID);
    fViewBot.show();

    TmfChartView viewPart = (TmfChartView) fViewBot.getViewReference().getView(true);
    fXyViewer = viewPart.getChartViewer();

    // Wait till SWT chart is constructed
    fViewBot.bot().waitUntil(new DefaultCondition() {
        @Override
        public boolean test() throws Exception {
            return fXyViewer.getSwtChart() != null;
        }
        @Override
        public String getFailureMessage() {
            return "SWT Chart is null";
        }
    });

    // Wait for trace to be loaded
    resetTimeRange();
}
 
Example 12
Source File: PinAndCloneTest.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Test the cloning feature.
 */
@Test
public void testCloneSingleTrace() {
    // single trace.
    SWTBotMenu cloneMenu = fOriginalViewBot.viewMenu().menu(NEW_VIEW_MENU);

    /*
     * assert that the original editor was not renamed and that the cloned one
     * exists and is pinned to the UST trace.
     */
    cloneMenu.menu(PINNED_TO_PREFIX + fUstTestTrace.getName()).click();
    assertOriginalViewTitle(TIME_GRAPH_VIEW_TITLE);
    SWTBotView clonedView = fBot.viewByTitle(PINNED_TO_UST_TIME_GRAPH_VIEW_TITLE);
    assertEquals("Should not have created a new instance", 1, fBot.editors().size());
    clonedView.close();

    /*
     * Assert that a new instance is created.
     */
    cloneMenu.menu(PINNED_TO_PREFIX + fUstTestTrace.getName() + " | new instance").click();
    assertOriginalViewTitle(TIME_GRAPH_VIEW_TITLE);
    clonedView = fBot.viewByTitle(PINNED_TO_UST_TIME_GRAPH_VIEW_TITLE2);
    assertEquals("Should have created a new instance", 2, fBot.editors().size());
    SWTBotEditor cloneEditor = fBot.editorByTitle(fUstTestTrace.getName() + CLONED_TRACE_SUFFIX);

    // Get the window range of the cloned trace
    TmfTraceManager traceManager = TmfTraceManager.getInstance();
    ITmfTrace cloneTrace = traceManager.getActiveTrace();
    assertNotNull(cloneTrace);

    // go back to original trace, pin it
    SWTBotUtils.activateEditor(fBot, fUstTestTrace.getName());
    fOriginalViewBot.toolbarButton(PIN_VIEW_BUTTON_NAME).click();
    ITmfTrace ust = traceManager.getActiveTrace();
    TmfSignalManager.dispatchSignal(new TmfWindowRangeUpdatedSignal(this, RANGE, ust));

    // assert that the cloned trace's window range did not change
    SWTBotUtils.activateEditor(fBot, cloneTrace.getName() + CLONED_TRACE_SUFFIX);
    IWorkbenchPart part = clonedView.getViewReference().getPart(false);
    assertTrue(part instanceof AbstractTimeGraphView);
    AbstractTimeGraphView abstractTimeGraphView = (AbstractTimeGraphView) part;
    fBot.waitUntil(ConditionHelpers.timeGraphRangeCondition(abstractTimeGraphView, cloneTrace, INITIAL_UST_RANGE));
    cloneEditor.close();
}
 
Example 13
Source File: CounterViewPinAndCloneTest.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Test the cloning feature.
 */
@Test
public void testCloneSingleTrace() {
    SWTBotView originalViewBot = getSWTBotView();
    SWTBotMenu cloneMenu = originalViewBot.viewMenu().menu(NEW_COUNTER_STACK_MENU);

    /*
     * Assert that the original editor was not renamed and that the cloned one
     * exists and is pinned to the kernel_vm trace.
     */
    cloneMenu.menu(PINNED_TO_PREFIX + getTestTrace().getName()).click();
    assertOriginalViewTitle(COUNTERS_VIEW_TITLE);
    SWTBotView clonedView = fBot.viewByTitle(PINNED_TO_TRACE_COUNTERS_VIEW_TITLE);
    assertEquals("Should not have created a new instance", 1, fBot.editors().size());
    clonedView.close();

     // Assert that a new instance is created.
    cloneMenu.menu(PINNED_TO_PREFIX + getTestTrace().getName() + " | new instance").click();
    assertOriginalViewTitle(COUNTERS_VIEW_TITLE);
    clonedView = fBot.viewByTitle(CLONED_VIEW_TITLE_NAME);
    assertEquals("Should have created a new instance", 2, fBot.editors().size());
    SWTBotEditor cloneEditor = fBot.editorByTitle(getTestTrace().getName() + CLONED_TRACE_SUFFIX);

    // Get the window range of the cloned trace
    TmfTraceManager traceManager = TmfTraceManager.getInstance();
    ITmfTrace cloneTrace = traceManager.getActiveTrace();
    assertNotNull(cloneTrace);

    // Go back to original trace, pin it
    SWTBotUtils.activateEditor(fBot, getTestTrace().getName());
    originalViewBot.toolbarButton(PIN_VIEW_BUTTON_NAME).click();

    // Assert that the cloned trace's window range did not change
    SWTBotUtils.activateEditor(fBot, cloneTrace.getName() + CLONED_TRACE_SUFFIX);
    IViewPart viewPart = clonedView.getViewReference().getView(false);
    assertTrue(viewPart instanceof TmfChartView);
    final TmfCommonXAxisChartViewer chartViewer = (TmfCommonXAxisChartViewer) getChartViewer(viewPart);
    assertNotNull(chartViewer);

    fBot.waitUntil(ConditionHelpers.xyViewerIsReadyCondition(chartViewer));
    TmfSignalManager.dispatchSignal(new TmfWindowRangeUpdatedSignal(this, RANGE, getTestTrace()));
    fBot.waitUntil(ConditionHelpers.xyViewerIsReadyCondition(chartViewer));
    SWTBotUtils.waitUntil(v -> (v.getWindowStartTime() == KERNEL_START && v.getWindowEndTime() == KERNEL_INITIAL_END), chartViewer, "Range of cloned view changed");

    cloneEditor.close();
}
 
Example 14
Source File: NewCounterViewPinAndCloneTest.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Test the cloning feature.
 */
@Test
public void testCloneSingleTrace() {
    SWTBotView originalViewBot = getSWTBotView();
    SWTBotMenu cloneMenu = originalViewBot.viewMenu().menu(NEW_COUNTER_STACK_MENU);

    /*
     * Assert that the original editor was not renamed and that the cloned one
     * exists and is pinned to the kernel_vm trace.
     */
    cloneMenu.menu(PINNED_TO_PREFIX + getTestTrace().getName()).click();
    assertOriginalViewTitle(COUNTERS_VIEW_TITLE);
    SWTBotView clonedView = fBot.viewByTitle(PINNED_TO_TRACE_COUNTERS_VIEW_TITLE);
    assertEquals("Should not have created a new instance", 1, fBot.editors().size());
    clonedView.close();

     // Assert that a new instance is created.
    cloneMenu.menu(PINNED_TO_PREFIX + getTestTrace().getName() + " | new instance").click();
    assertOriginalViewTitle(COUNTERS_VIEW_TITLE);
    clonedView = fBot.viewByTitle(CLONED_VIEW_TITLE_NAME);
    assertEquals("Should have created a new instance", 2, fBot.editors().size());
    SWTBotEditor cloneEditor = fBot.editorByTitle(getTestTrace().getName() + CLONED_TRACE_SUFFIX);

    // Get the window range of the cloned trace
    TmfTraceManager traceManager = TmfTraceManager.getInstance();
    ITmfTrace cloneTrace = traceManager.getActiveTrace();
    assertNotNull(cloneTrace);

    // Go back to original trace, pin it
    SWTBotUtils.activateEditor(fBot, getTestTrace().getName());
    originalViewBot.toolbarButton(PIN_VIEW_BUTTON_NAME).click();

    // Assert that the cloned trace's window range did not change
    SWTBotUtils.activateEditor(fBot, cloneTrace.getName() + CLONED_TRACE_SUFFIX);
    IViewPart viewPart = clonedView.getViewReference().getView(false);
    assertTrue(viewPart instanceof TmfChartView);
    final TmfCommonXAxisChartViewer chartViewer = (TmfCommonXAxisChartViewer) getChartViewer(viewPart);
    assertNotNull(chartViewer);

    fBot.waitUntil(ConditionHelpers.xyViewerIsReadyCondition(chartViewer));
    TmfSignalManager.dispatchSignal(new TmfWindowRangeUpdatedSignal(this, RANGE, getTestTrace()));
    fBot.waitUntil(ConditionHelpers.xyViewerIsReadyCondition(chartViewer));
    SWTBotUtils.waitUntil(v -> (v.getWindowStartTime() == KERNEL_START && v.getWindowEndTime() == KERNEL_INITIAL_END), chartViewer, "Range of cloned view changed");

    cloneEditor.close();
}
 
Example 15
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));
}