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

The following examples show how to use org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot#viewById() . 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: SwtBotWorkbenchActions.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
/** Open the view with the given ID. */
public static SWTBotView openViewById(SWTWorkbenchBot bot, String viewId) {
  UIThreadRunnable.syncExec(
      bot.getDisplay(),
      () -> {
        IWorkbenchWindow activeWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        assertNotNull(activeWindow);
        try {
          activeWindow.getActivePage().showView(viewId);
        } catch (PartInitException ex) {
          // viewById() will fail in calling thread
          logger.log(Level.SEVERE, "Unable to open view " + viewId, ex);
        }
      });
  return bot.viewById(viewId);
}
 
Example 2
Source File: SWTBotUtils.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Opens a trace in an editor and get the TmfEventsEditor
 *
 * @param bot
 *            the workbench bot
 * @param projectName
 *            the name of the project that contains the trace
 * @param elementPath
 *            the trace element path (relative to Traces folder)
 * @return TmfEventsEditor the opened editor
 */
public static TmfEventsEditor openEditor(SWTWorkbenchBot bot, String projectName, IPath elementPath) {
    final SWTBotView projectExplorerView = bot.viewById(IPageLayout.ID_PROJECT_EXPLORER);
    projectExplorerView.setFocus();
    SWTBot projectExplorerBot = projectExplorerView.bot();

    final SWTBotTree tree = projectExplorerBot.tree();
    projectExplorerBot.waitUntil(ConditionHelpers.isTreeNodeAvailable(projectName, tree));
    final SWTBotTreeItem treeItem = tree.getTreeItem(projectName);
    treeItem.expand();

    SWTBotTreeItem tracesNode = getTraceProjectItem(projectExplorerBot, treeItem, "Traces");
    tracesNode.expand();

    SWTBotTreeItem currentItem = tracesNode;
    for (String segment : elementPath.segments()) {
        currentItem = getTraceProjectItem(projectExplorerBot, currentItem, segment);
        currentItem.doubleClick();
    }

    SWTBotEditor editor = bot.editorByTitle(elementPath.toString());
    IEditorPart editorPart = editor.getReference().getEditor(false);
    assertTrue(editorPart instanceof TmfEventsEditor);
    return (TmfEventsEditor) editorPart;
}
 
Example 3
Source File: FlameGraphTest.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Open a flamegraph
 */
@Before
public void before() {
    fBot = new SWTWorkbenchBot();
    SWTBotUtils.openView(FLAMEGRAPH_ID);
    SWTBotView view = fBot.viewById(FLAMEGRAPH_ID);
    assertNotNull(view);
    fView = view;
    FlameGraphView flamegraph = UIThreadRunnable.syncExec((Result<FlameGraphView>) () -> {
        IViewPart viewRef = fView.getViewReference().getView(true);
        return (viewRef instanceof FlameGraphView) ? (FlameGraphView) viewRef : null;
    });
    assertNotNull(flamegraph);
    fTimeGraphViewer = flamegraph.getTimeGraphViewer();
    assertNotNull(fTimeGraphViewer);
    SWTBotUtils.maximize(flamegraph);
    fFg = flamegraph;
}
 
Example 4
Source File: CallGraphDensityViewTest.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Setup for the test
 */
@Before
public void before() {
    fBot = new SWTWorkbenchBot();
    SWTBotUtils.openView(CALLGRAPHDENSITY_ID);
    SWTBotView view = fBot.viewById(CALLGRAPHDENSITY_ID);
    assertNotNull(view);
    fView = view;
    CallGraphDensityView funcDensityView = UIThreadRunnable.syncExec((Result<CallGraphDensityView>) () -> {
        IViewPart viewRef = fView.getViewReference().getView(true);
        return (viewRef instanceof CallGraphDensityView) ? (CallGraphDensityView) viewRef : null;
    });
    assertNotNull(funcDensityView);
    fTableBot = fView.bot().table();
    assertNotNull(fTableBot);
    fDensityViewer = funcDensityView.getDensityViewer();
    assertNotNull(fDensityViewer);
    fLatch = new CountDownLatch(1);
    fDensityViewer.removeDataListener(fSyncListener);
    fDensityViewer.addDataListener(fSyncListener);
    fTableViewer = funcDensityView.getTableViewer();
    assertNotNull(fTableViewer);
    SWTBotUtils.maximize(funcDensityView);
    fFuncDensityView = funcDensityView;
    fDensityViewer.setNbPoints(100);
}
 
Example 5
Source File: SystemCallLatencyStatisticsTableAnalysisTest.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Opens a latency table
 */
@Before
public void createTree() {
    /*
     * Open latency view
     */
    SWTBotUtils.openView(PRIMARY_VIEW_ID, SECONDARY_VIEW_ID);
    SWTWorkbenchBot bot = new SWTWorkbenchBot();
    SWTBotView viewBot = bot.viewById(PRIMARY_VIEW_ID);
    final IViewReference viewReference = viewBot.getViewReference();
    IViewPart viewPart = UIThreadRunnable.syncExec(new Result<IViewPart>() {
        @Override
        public IViewPart run() {
            return viewReference.getView(true);
        }
    });
    assertTrue("Could not instanciate view", viewPart instanceof SegmentStoreStatisticsView);
    fTreeBot = viewBot.bot().tree();
    assertNotNull(fTreeBot);
}
 
Example 6
Source File: SWTBotUtils.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Deletes a project
 *
 * @param projectName
 *            the name of the tracing project
 * @param deleteResources
 *            whether or not to deleted resources under the project
 * @param bot
 *            the workbench bot
 */
public static void deleteProject(final String projectName, boolean deleteResources, SWTWorkbenchBot bot) {
    // Wait for any analysis to complete because it might create
    // supplementary files
    WaitUtils.waitForJobs();
    try {
        ResourcesPlugin.getWorkspace().getRoot().getProject(projectName).refreshLocal(IResource.DEPTH_INFINITE, null);
    } catch (CoreException e) {
    }

    WaitUtils.waitForJobs();

    closeSecondaryShells(bot);
    WaitUtils.waitForJobs();

    if (!ResourcesPlugin.getWorkspace().getRoot().getProject(projectName).exists()) {
        return;
    }

    focusMainWindow(bot.shells());

    final SWTBotView projectViewBot = bot.viewById(IPageLayout.ID_PROJECT_EXPLORER);
    projectViewBot.setFocus();

    SWTBotTree treeBot = projectViewBot.bot().tree();
    SWTBotTreeItem treeItem = treeBot.getTreeItem(projectName);
    SWTBotMenu contextMenu = treeItem.contextMenu("Delete");
    contextMenu.click();

    handleDeleteDialog(deleteResources, bot);
    WaitUtils.waitForJobs();
}
 
Example 7
Source File: TmfAlignTimeAxisTest.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Test for the "Align Views" menu item
 */
@Test
public void testMenuItem() {
    fBot = new SWTWorkbenchBot();
    switchToPerspective(AlignPerspectiveFactory1.ID);
    SWTBotView viewBot = fBot.viewById(TimeGraphViewStub.ID);
    SWTBotRootMenu viewMenu = viewBot.viewMenu();

    SWTBotMenu menuItems = viewMenu.menu(ALIGN_VIEWS_ACTION_NAME);
    assertTrue("Align views", menuItems.isChecked());
}
 
Example 8
Source File: SystemCallLatencyStatisticsTableAnalysisTest.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Test with an actual trace, this is more of an integration test than a
 * unit test. This test is a slow one too. If some analysis are not well
 * configured, this test will also generates null pointer exceptions. These
 * are will be logged.
 *
 * @throws IOException
 *             trace not found?
 * @throws SecurityException
 *             Reflection error
 * @throws NoSuchMethodException
 *             Reflection error
 * @throws IllegalArgumentException
 *             Reflection error
 */
@Test
public void testWithTrace() throws IOException, NoSuchMethodException, SecurityException, IllegalArgumentException {
    String tracePath = FileUtils.toFile(FileLocator.toFileURL(CtfTestTrace.ARM_64_BIT_HEADER.getTraceURL())).getAbsolutePath();
    SWTWorkbenchBot bot = new SWTWorkbenchBot();
    SWTBotView view = bot.viewById(PRIMARY_VIEW_ID);
    SWTBotUtils.closeViewById(PRIMARY_VIEW_ID, fBot);

    SWTBotUtils.createProject(PROJECT_NAME);
    SWTBotUtils.openTrace(PROJECT_NAME, tracePath, TRACE_TYPE);
    WaitUtils.waitForJobs();
    createTree();
    WaitUtils.waitForJobs();
    SWTBotTreeItem totalEntry = fTreeBot.getTreeItem("bug446190").getNode("Total");
    validate(totalEntry, "Total", "1 µs", "5.904 s", "15.628 ms", "175.875 ms", "1801");
    assertEquals(55, totalEntry.getNodes().size());
    validate(totalEntry.getNode(2), "select", "13.6 µs", "1.509 s", "192.251 ms", "386.369 ms", "58");
    validate(totalEntry.getNode(3), "poll", "6.3 µs", "6.8 µs", "6.55 µs", "---", "2");
    validate(totalEntry.getNode(5), "set_tid_address", "2.3 µs", "2.3 µs", "2.3 µs", "---", "1");
    validate(totalEntry.getNode(7), "pipe", "27.9 µs", "29.7 µs", "28.8 µs", "---", "2");
    testToTsv(view);
    SWTBotMenu menuBot = view.viewMenu().menu("Export to TSV...");
    assertTrue(menuBot.isEnabled());
    assertTrue(menuBot.isVisible());

    fBot.closeAllEditors();
    SWTBotUtils.deleteProject(PROJECT_NAME, fBot);
}
 
Example 9
Source File: SegmentTableTest.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Test creating a tsv
 *
 * @throws NoSuchMethodException
 *             Error creating the tsv
 * @throws IOException
 *             no such file or the file is locked.
 */
@Test
public void testWriteToTsv() throws NoSuchMethodException, IOException {

    ISegmentStore<@NonNull ISegment> fixture = SegmentStoreFactory.createSegmentStore();
    for (int i = 1; i <= 20; i++) {
        int start = i;
        final int delta = i;
        int end = start + delta * delta;
        fixture.add(createSegment(start, end));
    }
    assertNotNull(getTable());
    getTable().updateModel(fixture);
    SWTBotTable tableBot = new SWTBotTable(getTable().getTableViewer().getTable());
    fBot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "1", 0, 2));
    SWTWorkbenchBot swtWorkbenchBot = new SWTWorkbenchBot();
    SWTBotView viewBot = swtWorkbenchBot.viewById(getTableView().getSite().getId());
    String[] lines = extractTsv(viewBot);
    testTsv(lines);
    List<String> actionResult = Arrays.asList(lines);
    String absolutePath = TmfTraceManager.getTemporaryDirPath() + File.separator + "syscallLatencyTest.testWriteToTsv.tsv";
    TmfFileDialogFactory.setOverrideFiles(absolutePath);
    SWTBotMenu menuBot = viewBot.viewMenu().menu("Export to TSV...");
    try {
        assertTrue(menuBot.isEnabled());
        assertTrue(menuBot.isVisible());
        menuBot.click();

        try (BufferedReader br = new BufferedReader(new FileReader(absolutePath))) {
            List<String> actual = br.lines().collect(Collectors.toList());
            assertEquals("Both reads", actionResult, actual);
        }
    } finally {
        new File(absolutePath).delete();
    }

}
 
Example 10
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 11
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 12
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 13
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 14
Source File: StandardImportGzipTraceTest.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Import a gzip trace
 */
@Test
public void testGzipImport() {
    final String traceType = "Test trace : TMF Tests";
    final String tracesNode = "Traces [1]";
    final SWTWorkbenchBot bot = getSWTBot();

    /*
     * Actual importing
     */
    openImportWizard();
    SWTBotImportWizardUtils.selectImportFromArchive(bot, fGzipTrace.getAbsolutePath());
    SWTBotImportWizardUtils.selectFolder(bot, true, ROOT_FOLDER);
    SWTBotCheckBox checkBox = bot.checkBox(Messages.ImportTraceWizard_CreateLinksInWorkspace);
    assertFalse(checkBox.isEnabled());
    SWTBotCombo comboBox = bot.comboBoxWithLabel(Messages.ImportTraceWizard_TraceType);
    comboBox.setSelection(traceType);
    importFinish();
    /*
     * Remove .gz extension
     */
    assertNotNull(fGzipTrace);
    String name = fGzipTrace.getName();
    assertNotNull(name);
    assertTrue(name.length() > 3);
    String traceName = name.substring(0, name.length() - 3);
    assertNotNull(traceName);
    assertFalse(traceName.isEmpty());

    /*
     * Open trace
     */
    SWTBotView projectExplorer = bot.viewById(IPageLayout.ID_PROJECT_EXPLORER);
    projectExplorer.setFocus();
    final SWTBotTree tree = projectExplorer.bot().tree();
    /*
     * This appears to be problematic due to the length of the file name and
     * the resolution in our CI.
     */
    SWTBotTreeItem treeItem = SWTBotUtils.getTreeItem(projectExplorer.bot(), tree, PROJECT_NAME, tracesNode, traceName);
    treeItem.doubleClick();
    WaitUtils.waitForJobs();
    /*
     * Check results
     */
    SWTBot editorBot = SWTBotUtils.activeEventsEditor(bot).bot();
    SWTBotTable editorTable = editorBot.table();
    final String expectedContent1 = "Type-1";
    final String expectedContent2 = "";
    editorBot.waitUntil(ConditionHelpers.isTableCellFilled(editorTable, expectedContent1, 2, 2));
    editorBot.waitUntil(ConditionHelpers.isTableCellFilled(editorTable, expectedContent2, 1, 0));
    String c22 = editorTable.cell(2, 2);
    String c10 = editorTable.cell(1, 0);
    assertEquals(expectedContent1, c22);
    assertEquals(expectedContent2, c10);
}
 
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));
}