public static boolean hasErrorsInProblemsView(SWTWorkbenchBot bot) { // Open Problems View by Window -> show view -> Problems bot.menu("Window").menu("Show View").menu("Problems").click(); SWTBotView view = bot.viewByTitle("Problems"); view.show(); SWTBotTree tree = view.bot().tree(); for (SWTBotTreeItem item : tree.getAllItems()) { String text = item.getText(); if (text != null && text.startsWith("Errors")) { return true; } } return false; }
@Test public void error_message_should_contain_delegate_shortcut_id() throws Exception { final LogListener logListener = new LogListener(); Platform.addLogListener(logListener); final String projectName = "ContextualLaunchableTesterTest"; new JavaProjectKit(projectName); final SWTBotView view = bot.viewByTitle("Project Explorer"); view.show(); final SWTBotTree tree = view.bot().tree(); tree.setFocus(); tree.select(projectName).contextMenu("Coverage As").click(); Platform.removeLogListener(logListener); final IStatus actualStatus = logListener.statuses.get(1); assertEquals(EclEmmaUIPlugin.ID, actualStatus.getPlugin()); assertEquals( "Launch shortcut 'org.eclipse.eclemma.ui.ContextualLaunchableTesterTest.fakeShortcut' enablement expression caused exception.", actualStatus.getMessage()); assertEquals( "No property tester contributes a property org.eclipse.eclemma.unknownProperty to type class org.eclipse.core.internal.resources.Project", actualStatus.getException().getMessage()); }
@Test public void testImportSession() { // given UIThreadRunnable.syncExec(new VoidResult() { public void run() { try { PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("org.eclipse.eclemma.ui.CoverageView"); } catch (PartInitException e) { e.printStackTrace(); } } }); // when SWTBotView view = bot.viewByTitle("Coverage"); view.bot().tree().contextMenu("Import Session...").click(); // then bot.shell("Import").activate(); bot.text(" Please select an existing execution data file."); }
@Test public void dumpDialog_should_abort_without_errors_when_nothing_was_selected() throws Exception { final LogListener logListener = new LogListener(); Platform.addLogListener(logListener); SWTBotView coverageView = bot.viewByTitle("Coverage"); coverageView.show(); coverageView.toolbarButton("Dump Execution Data").click(); bot.shell("Dump Execution Data").activate(); bot.button("Cancel").click(); // On Linux one element will be selected by default, however for some reason // nothing is selected on Mac OS X and Windows: coverageView.toolbarButton("Dump Execution Data").click(); bot.shell("Dump Execution Data").activate(); bot.button("OK").click(); Platform.removeLogListener(logListener); assertEquals(0, logListener.errors); }
/** * Wait until the contents of the given {@link SWTBotView} are loaded. * * @param view * the view to be loaded */ public static void waitUntilViewIsLoaded(final SWTBotView view) { view.bot().waitUntil(new DefaultCondition() { @Override public boolean test() { SWTBotTreeItem[] allItems = view.bot().tree().getAllItems(); return allItems.length == 0 || !allItems[0].getText().equals(LOADING_VIEW_MESSAGE); } @Override public String getFailureMessage() { return "View must be loaded: " + view.getTitle(); } }, TIMEOUT_FOR_VIEW_TO_LOAD); }
public static void beforeClass() { UIThreadRunnable.syncExec(new VoidResult() { public void run() { resetWorkbench(); resetToolbox(); // close browser-based welcome screen (if open) SWTWorkbenchBot bot = new SWTWorkbenchBot(); try { SWTBotView welcomeView = bot.viewByTitle("Welcome"); welcomeView.close(); } catch (WidgetNotFoundException e) { return; } } }); }
/** * Returns true if the specified project can be found in the 'Package Explorer' or 'Project View', * otherwise returns false. Throws a WidgetNotFoundException exception if the 'Package Explorer' * or 'Project Explorer' view cannot be found. * * @param bot The SWTWorkbenchBot. * @param projectName The name of the project to be found. * @return if the project exists */ public static boolean doesProjectExist(final SWTWorkbenchBot bot, String projectName) { SWTBotView explorer = getPackageExplorer(bot); if (explorer == null) { throw new WidgetNotFoundException( "Could not find the 'Package Explorer' or 'Project Explorer' view."); } // Select the root of the project tree in the explorer view Widget explorerWidget = explorer.getWidget(); Tree explorerTree = bot.widget(widgetOfType(Tree.class), explorerWidget); SWTBotTreeItem[] allItems = new SWTBotTree(explorerTree).getAllItems(); for (int i = 0; i < allItems.length; i++) { if (allItems[i].getText().equals(projectName)) { return true; } } return false; }
/** * Returns true if there are errors in the Problem view. Returns false otherwise. */ public static boolean hasErrorsInProblemsView(SWTWorkbenchBot bot) { // Open Problems View by Window -> show view -> Problems bot.menu("Window").menu("Show View").menu("Problems").click(); SWTBotView view = bot.viewByTitle("Problems"); view.show(); SWTBotTree tree = view.bot().tree(); for (SWTBotTreeItem item : tree.getAllItems()) { String text = item.getText(); if (text != null && text.startsWith("Errors")) { return true; } } return false; }
/** * Returns the specified project. Throws a WidgetNotFoundException if the 'Package Explorer' or * 'Project Explorer' view cannot be found or if the specified project cannot be found. * * @param bot The SWTWorkbenchBot. * @param projectName The name of the project to select. * @return the tree */ public static SWTBotTreeItem selectProject(final SWTWorkbenchBot bot, String projectName) { /* * Choose either the Package Explorer View or the Project Explorer view. Eclipse 3.3 and 3.4 * start with the Java Perspective, which has the Package Explorer View open by default, whereas * Eclipse 3.5 starts with the Resource Perspective, which has the Project Explorer View open. */ SWTBotView explorer = getPackageExplorer(bot); for (SWTBotView view : bot.views()) { if (view.getTitle().equals("Package Explorer") || view.getTitle().equals("Project Explorer")) { explorer = view; break; } } if (explorer == null) { throw new WidgetNotFoundException( "Could not find the 'Package Explorer' or 'Project Explorer' view."); } // Select the root of the project tree in the explorer view Widget explorerWidget = explorer.getWidget(); Tree explorerTree = bot.widget(widgetOfType(Tree.class), explorerWidget); return new SWTBotTree(explorerTree).getTreeItem(projectName).select(); }
@Override @Test public void testController() throws ESException { final Player player = createPlayerAndCommit(); UIThreadRunnable.asyncExec(new VoidResult() { public void run() { final UIShowHistoryController showHistoryController = new UIShowHistoryController(bot.getDisplay().getActiveShell(), player); showHistoryController.execute(); } }); final SWTBotView historyView = bot.viewById( "org.eclipse.emf.emfstore.client.ui.views.historybrowserview.HistoryBrowserView"); assertNotNull(historyView); }
@Override @Test public void testController() throws ESException { createPlayerAndCommit(); UIThreadRunnable.asyncExec(new VoidResult() { public void run() { final UIShowHistoryController showHistoryController = new UIShowHistoryController(bot.getDisplay().getActiveShell(), localProject); showHistoryController.execute(); } }); final SWTBotView historyView = bot.viewById( "org.eclipse.emf.emfstore.client.ui.views.historybrowserview.HistoryBrowserView"); assertNotNull(historyView); }
@Before public void baseBeforeTest() { // Sets codenvy fake API CodenvyAPI.setClient(new FakeCodenvyClient()); UIThreadRunnable.syncExec(new VoidResult() { @Override public void run() { final Shell eclipseShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); eclipseShell.forceFocus(); } }); try { final SWTBotView welcomeView = bot.viewByTitle("Welcome"); welcomeView.close(); } catch (WidgetNotFoundException e) { // ignore the exception } }
public SWTBotView getBotView() { if (botView == null) { List<SWTBotView> views = bot.views(); for (SWTBotView swtBotView : views) { String title = swtBotView.getTitle(); if (PROPERTIES.equalsIgnoreCase(title)) { botView = swtBotView; } } } return botView; }
public SWTBotView getBotView() { if (botView == null) { List<SWTBotView> views = bot.views(); for (SWTBotView swtBotView : views) { String title = swtBotView.getTitle(); if (OUTLINE.equalsIgnoreCase(title)) { botView = swtBotView; } } } return botView; }
protected SWTBotView getPackageExplorer() { Display.getDefault().syncExec(() -> { try { PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("org.eclipse.jdt.ui.PackageExplorer"); } catch (PartInitException e1) { e1.printStackTrace(); } }); SWTBotView view = bot.viewByTitle("Package Explorer"); return view; }
public SWTBotView getBotView() { if (botView == null) { List<SWTBotView> views = bot.views(); for (SWTBotView swtBotView : views) { String title = swtBotView.getTitle(); if ("Console".equalsIgnoreCase(title)) { botView = swtBotView; } } } return botView; }
public SWTBotView getBotView() { if (botView == null) { List<SWTBotView> views = bot.views(); for (SWTBotView swtBotView : views) { String title = swtBotView.getTitle(); if ("Problems".equalsIgnoreCase(title)) { botView = swtBotView; } } } return botView; }
public SWTBotView getBotView() { if (botView == null) { List<SWTBotView> views = bot.views(); for (SWTBotView swtBotView : views) { String title = swtBotView.getTitle(); if (VIEW_TITLE.equalsIgnoreCase(title)) { botView = swtBotView; } } } return botView; }
public boolean test() throws Exception { List<SWTBotView> views = bot.views(); for (SWTBotView swtBotView : views) { String title = swtBotView.getTitle(); if (viewTitle.equalsIgnoreCase(title)) { return true; } } return false; }
private SWTBotView waitForConsoleBeDisplayed () { getConsoleView(bot); Matcher<Widget> console = getConsoleMatcher () ; bot.waitUntil(Conditions.waitForWidget(console)); SWTBotView consoleView = getConsoleView(bot); consoleView.setFocus(); return consoleView; }
/** * 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(); } }
/** * Returns true if the specified project is found in the 'Package Explorer' or 'Project View', * otherwise returns false. Throws a WidgetNotFoundException exception if the 'Package Explorer' * or 'Project Explorer' view cannot be found. * * @param projectName the name of the project to be found * @return true if the project is found, and false if not found */ public static boolean projectFound(final SWTWorkbenchBot bot, String projectName) { SWTBotView explorer = getExplorer(bot); // Select the root of the project tree in the explorer view Widget explorerWidget = explorer.getWidget(); Tree explorerTree = bot.widget(widgetOfType(Tree.class), explorerWidget); for (SWTBotTreeItem item : new SWTBotTree(explorerTree).getAllItems()) { if (item.getText().equals(projectName)) { return true; } } return false; }
/** * Choose either the Package Explorer View or the Project Explorer view. Some perspectives have * the Package Explorer View open by default, whereas others use the Project Explorer View. * * @throws WidgetNotFoundException if an explorer is not found */ public static SWTBotView getExplorer(final SWTWorkbenchBot bot) { for (SWTBotView view : bot.views()) { if (view.getTitle().equals("Package Explorer") || view.getTitle().equals("Project Explorer")) { return view; } } throw new WidgetNotFoundException( "Could not find the 'Package Explorer' or 'Project Explorer' view."); }
/** * Returns the specified project. * * @param projectName the name of the project to select * @return the selected tree item * @throws WidgetNotFoundException if the 'Package Explorer' or 'Project Explorer' view cannot be * found or if the specified project cannot be found. */ public static SWTBotTreeItem selectProject(final SWTWorkbenchBot bot, String projectName) { SWTBotView explorer = getExplorer(bot); // Select the root of the project tree in the explorer view Widget explorerWidget = explorer.getWidget(); Tree explorerTree = bot.widget(widgetOfType(Tree.class), explorerWidget); return new SWTBotTree(explorerTree).getTreeItem(projectName).select(); }
@Test public void testViewHasDefaultFolderAndAllVirtualFolders() { // Given SWTBotView botView = bookmarksViewDriver.view(); assertEquals("Mes Favoris", botView.getTitle()); // When List<SWTBotTreeItem> items = Arrays.asList(bookmarksViewDriver.tree().getAllItems()); // Then assertThat(items).extracting(item -> item.getText()).containsOnly("default", "Most visited", "Latest visited", "Recent bookmarks", "Numbered bookmarks"); }
/** * Close welcome page. */ public void closeWelcomePage() { final List<SWTBotView> introViews = views(withPartId("org.eclipse.ui.internal.introview")); for (SWTBotView introView : introViews) { introView.close(); } }
/** * Checks if a {@link SWTBotView} exist. * * @param swtBotView * the {@link SWTBotView} * @return {@code true} if the view was found, {@code false} otherwise */ public boolean hasView(final SWTBotView swtBotView) { for (SWTBotView view : views()) { if (view.getReference().equals(swtBotView.getReference())) { return true; } } return false; }
/** * Returns the {@link SWTBotView} with the given view identifier. * * @param viewId * the id of the view * @return the {@code SWTBotView} with the given view identifier, {@code null} if no such view exists */ public SWTBotView getView(final String viewId) { for (SWTBotView view : views()) { if (view.getReference().getId().equals(viewId)) { return view; } } return null; }
/** * Select a folder in a project. * * @param bot * the bot * @param folderName * the folder name */ public static void selectProjectFolder(final SwtWorkbenchBot bot, final String folderName) { SWTBotView packageExplorer = bot.viewByTitle("Project Explorer"); packageExplorer.show(); Composite comp = (Composite) packageExplorer.getWidget(); final Tree tree = bot.widget(WidgetMatcherFactory.widgetOfType(Tree.class), comp); PlatformUI.getWorkbench().getDisplay().syncExec(() -> { SWTBotTree botTree = new SWTBotTree(tree); if (!selectItem(botTree, folderName)) { fail("folder was not found"); } }); }
/** * Opens the outline view of the currently active editor. * * @return the {@link SWTBotView} representing the outline view * @throw WidgetNotFoundException if there is no active editor */ // CHECKSTYLE:CONSTANTS-OFF protected SWTBotView openOutlineViewOfActiveEditor() { getBot().menu("Window").menu("Show View").menu("Outline").click(); SWTBotView outlineView = getBot().viewById("org.eclipse.ui.views.ContentOutline"); assertNotNull("outline view present", outlineView); SwtBotViewUtil.waitUntilViewIsLoaded(outlineView); outlineView.setFocus(); return outlineView; }
private void openSpecExplorer() { SWTBotMenu windowMenu = bot.menu("Window"); SWTBotMenu specExplorerMenu = windowMenu.menu(SPEC_EXPLORER); specExplorerMenu.click(); // spec context menu SWTBotView packageExplorerView = bot.viewByTitle(SPEC_EXPLORER); packageExplorerView.setFocus(); }
@Override public boolean test() throws Exception { msg = "Could not open Console view"; SWTBotView consoleView = bot.viewById("org.eclipse.ui.console.ConsoleView"); msg = "Could not find textWidget in Console view"; SWTBotStyledText textWidget = consoleView.bot().styledText(); msg = "Could not get the text from the Console view"; String text = textWidget.getText(); msg = "Looking for: '" + searchString + "' but found \n\t------\n\t" + text + "\n\t-----"; return text.contains(searchString); }
public static SWTBotView getPackageExplorer(final SWTWorkbenchBot bot) { SWTBotView explorer = null; for (SWTBotView view : bot.views()) { if (view.getTitle().equals("Package Explorer") || view.getTitle().equals("Project Explorer")) { explorer = view; break; } } return explorer; }
/** * Returns the project root tree in Package Explorer. */ public static SWTBotTree getProjectRootTree(SWTWorkbenchBot bot) { SWTBotView explorer = getPackageExplorer(bot); if (explorer == null) { throw new WidgetNotFoundException("Cannot find Package Explorer or Project Explorer"); } Tree tree = bot.widget(widgetOfType(Tree.class), explorer.getWidget()); return new SWTBotTree(tree); }
private static void closeWelcomeView() { for (final SWTBotView swtBotView : bot.views()) { if (swtBotView.getTitle().equals(WELCOME)) { swtBotView.close(); return; } } }
/** * @return 文档属性视图实例; */ public static SWTBotView getInstance() { if (view == null) { view = new DocumentPropertiesView(); } return view; }
/** * @param bot * @return isWelcomeClosed */ public static boolean closeWelcomeView(SWTWorkbenchBot bot) { List<SWTBotView> swtBotViews = bot.views(); for (SWTBotView tmpSwtBotView : swtBotViews) { if (tmpSwtBotView.getTitle().contentEquals(Properties.VIEW_WELCOME)) { tmpSwtBotView.close(); } } return true; }
public void deleteProject(String projectName) { final SWTBotView packageExplorerView = bot.viewByTitle("Package Explorer"); packageExplorerView.show(); packageExplorerView.bot().tree().select(projectName); bot.menu("Edit").menu("Delete").click(); // the project deletion confirmation dialog final SWTBotShell shell = bot.shell("Delete Resources").activate(); bot.checkBox("Delete project contents on disk (cannot be undone)").select(); bot.button("OK").click(); bot.waitUntil(shellCloses(shell)); }
@Test public void testThatImportedProjectIsAvailableInPackageExplorerView() throws CoreException { importCodenvyProject(MOCK_WORKSPACE_NAME, MOCK_PROJECT_NAME); final SWTBotView packageExplorerView = bot.viewByTitle("Package Explorer"); packageExplorerView.show(); packageExplorerView.bot().tree().getTreeItem(MOCK_PROJECT_NAME); }