public boolean test() throws Exception { try { SWTBotTreeItem item = this.problemView.expandErrorItem (); SWTBotTreeItem[] child = item.getItems(); for (int i = 0; i < child.length; i++) { if (child[i].isSelected() && child[i].row().get(0).equalsIgnoreCase(checkedItem.row().get(0))) { return true; } } retry (); return false; } catch (WidgetNotFoundException e) { retry (); return false; } }
/** * Given a tree that contains an entry with <code>itemName</code> and a direct child with a name * matching <code>subchildName</code>, return its tree item. * * This method is useful when there is the possibility of a tree having two similarly-named * top-level nodes. * * @param mainTree the tree * @param itemName the name of a top-level node in the tree * @param subchildName the name of a direct child of the top-level node (used to uniquely select * the appropriate tree item for the given top-level node name) * @return the tree item corresponding to the top-level node with <code>itemName</code>that has a * direct child with <code>subchildName</code>. If there are multiple tree items that * satisfy this criteria, then the first one (in the UI) will be returned * * @throws WidgetNotFoundException if no such node can be found */ public static SWTBotTreeItem getUniqueTreeItem(final SWTBot bot, final SWTBotTree mainTree, String itemName, String subchildName) { for (SWTBotTreeItem item : mainTree.getAllItems()) { if (itemName.equals(item.getText())) { try { item.expand(); waitUntilTreeHasText(bot, item); if (item.getNode(subchildName) != null) { return item; } } catch (WidgetNotFoundException ex) { // Ignore } } } throw new WidgetNotFoundException( "The " + itemName + " node with a child of " + subchildName + " must exist in the tree."); }
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; } } }); }
/** * Given a tree that contains an entry with <code>itemName</code> and a direct child with a name * matching <code>subchildName</code>, return its tree item. * * This method is useful when there is the possibility of a tree having two similarly-named * top-level nodes. * * @param mainTree the tree * @param itemName the name of a top-level node in the tree * @param subchildName the name of a direct child of the top-level node (used to uniquely select * the appropriate tree item for the given top-level node name) * @return the tree item corresponding to the top-level node with <code>itemName</code>that has a * direct child with <code>subchildName</code>. If there are multiple tree items that * satisfy this criteria, then the first one (in the UI) will be returned * * @throws IllegalStateException if no such node can be found */ public static SWTBotTreeItem getUniqueTreeItem(final SWTBot bot, final SWTBotTree mainTree, String itemName, String subchildName) { for (SWTBotTreeItem item : mainTree.getAllItems()) { if (itemName.equals(item.getText())) { try { item.expand(); SwtBotTreeActions.waitUntilTreeHasText(bot, item); if (item.getNode(subchildName) != null) { return item; } } catch (WidgetNotFoundException e) { // Ignore } } } throw new IllegalStateException("The '" + itemName + "' node with a child of '" + subchildName + "' must exist in the tree."); }
/** * 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 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(); }
@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 } }
@BeforeClass public static void beforeClass() throws Exception { bot = new SWTWorkbenchBot(); try { bot.viewByTitle("Welcome").close(); } catch (WidgetNotFoundException e) { // OK, no Welcome view, that's fine :) } // Change the perspective via the Open Perspective dialog bot.menu("Window").menu("Open Perspective").menu("Other...").click(); SWTBotShell openPerspectiveShell = bot.shell("Open Perspective"); openPerspectiveShell.activate(); // select the dialog bot.table().select("Plug-in Development"); bot.button("OK").click(); // in Luna the Error Log is not shown by default in the Plug-in Development perspective // bot.viewByPartName("Error Log").close(); // in SwtBot 2.2.0 we must use viewByPartName instead of viewByTitle bot.viewByPartName("Problems").show(); }
public boolean test() throws Exception { try { return fileItem.isSelected() & fileItem.isVisible(); } catch (WidgetNotFoundException e) { return false; } }
public boolean test() throws Exception { try { return item.isExpanded(); } catch (WidgetNotFoundException e) { return false; } }
protected boolean isProjectCreated(String name) { try { getProjectTreeItem(name); return true; } catch (WidgetNotFoundException e) { return false; } }
public boolean test() throws Exception { try { return checkedItem.isSelected(); } catch (WidgetNotFoundException e) { return false; } }
private SWTBotToolbarButton findToolBarButton (String text) { List<SWTBotToolbarButton> items = this.botView.getToolbarButtons(); for (SWTBotToolbarButton button : items) { if (text.equals(button.getToolTipText())) { return button; } } throw new WidgetNotFoundException (text); }
@Override public boolean test() throws Exception { try { return botTree.contextMenu(mMenuText).isVisible(); } catch (WidgetNotFoundException e) { return false; } }
public boolean test() throws Exception { try { return pbView.countErrorWithText(text) == count; } catch (WidgetNotFoundException e) { return false; } }
public boolean test() throws Exception { try { this.problemView.findErrorItemWithText (error); return false; } catch (WidgetNotFoundException e) { return true; } }
public boolean test() throws Exception { try { SWTBotCTabItem tabItem = bot.cTabItem(title); return tabItem!=null; } catch (WidgetNotFoundException e) { return false; } }
public boolean test() throws Exception { try { boolean b = pbView.getDisplayedErrorCount() == 0; return b; } catch (WidgetNotFoundException e) { return false; } }
private static boolean flexDeployMenuVisible(IProject project) { SWTBotTreeItem selected = SwtBotProjectActions.selectProject( new SWTWorkbenchBot(), project.getName()); try { selected.contextMenu("Deploy to App Engine Flexible..."); return true; } catch (WidgetNotFoundException e) { 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."); }
@BeforeClass public static void setUp() throws Exception { // verify we can find the Google Cloud SDK new CloudSdk.Builder().build().validateCloudSdk(); bot = new SWTWorkbenchBot(); try { SwtBotWorkbenchActions.closeWelcome(bot); } catch (WidgetNotFoundException ex) { // may receive WNFE: "There is no active view" } }
public static void closeWelcomeView() { try { SWTWorkbenchBot bot = new SWTWorkbenchBot(); bot.viewByTitle("Welcome").close(); } catch (WidgetNotFoundException e) { } }
/** * Checks that the given function can supply a widget without throwing a {@link WidgetNotFoundException}. * * @param widgetNotFoundExceptionThrower * the supplier function, must not be {@code null} * @return {code true} if the function executes without throwing a {@link WidgetNotFoundException}, {@code false} otherwise */ private boolean widgetNotFoundExceptionToBoolean(final Supplier<? extends AbstractSWTBot<? extends Widget>> widgetNotFoundExceptionThrower) { try { widgetNotFoundExceptionThrower.get(); } catch (WidgetNotFoundException e) { return false; } return true; }
@Override public void waitUntilWidgetAppears(final ICondition waitForWidget) { try { waitUntil(waitForWidget, SHORT_TIME_OUT, SHORT_INTERVAL); } catch (TimeoutException e) { throw new WidgetNotFoundException("Could not find widget.", e); //$NON-NLS-1$ } }
/** * Clicks the context menu matching the given labels. * When a context menu 'Compile' exists with the sub context menu 'All Invalids', * then the context menu 'All Invalids' can be clicked by giving the labels 'Compile' and 'All Invalids'. * * @param bot * the {@link AbstractSWTBot} on which to infer the context menu * @param labels * the labels on the context menus * @throw {@link WidgetNotFoundException} if the context menu could not be found */ public static void clickContextMenu(final AbstractSWTBot<? extends Control> bot, final String... labels) { MenuItem menuItem = getContextMenuItem(bot, labels); if (menuItem == null) { long endTime = System.currentTimeMillis() + SWTBotPreferences.TIMEOUT; while (menuItem == null && System.currentTimeMillis() < endTime) { SWTUtils.sleep(SWTBotPreferences.DEFAULT_POLL_DELAY); menuItem = getContextMenuItem(bot, labels); } if (menuItem == null) { throw new WidgetNotFoundException("Could not find menu: " + Arrays.asList(labels)); } } click(menuItem); }
/** * Whether the context menu with the given labels is enabled. * * @param widgetBot * the bot representing the widget on which it should be checked, whether the context menu * with the given labels is enabled * @param labels * the labels on the context menus * @return {@code true} if the context menu is enabled, else {@code false} * @throw {@link WidgetNotFoundException} if the context menu could not be found */ public static boolean isEnabled(final AbstractSWTBot<? extends Control> widgetBot, final String... labels) { final MenuItem menuItem = getContextMenuItem(widgetBot, labels); if (menuItem == null) { throw new WidgetNotFoundException("Could not find menu: " + Arrays.asList(labels)); } return UIThreadRunnable.syncExec(new Result<Boolean>() { @Override public Boolean run() { return menuItem.isEnabled(); } }); }
/** * 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; }
/** * Tries to close the "Welcome" view if it is open. This only needs to be * done once, and nothing needs to be disposed afterward. */ @BeforeClass public static void beforeWorkbenchClass() { // Close the welcome view using a temporary SWTBot. SWTWorkbenchBot bot = new SWTWorkbenchBot(); try { bot.viewByTitle("Welcome").close(); } catch (WidgetNotFoundException e) { // Nothing to do. } return; }
@Test public void testPlotEditor() { IVizServiceFactory fakeFactory = new BasicVizServiceFactory(); fakeFactory.register(new CSVVizService()); factoryHolder.setVizServiceFactory(fakeFactory); // Close the initial eclipse welcome view, if one exists try { bot.viewByTitle("Welcome").close(); } catch (WidgetNotFoundException e) { // We expect that the SWTBot will throw an exception if Eclipse // doesn't start with a welcome view, so there is nothing to do here } // Open the fib8.csv file in the plot editor. SWTBotTreeItem node = bot.tree().getAllItems()[0]; node.expand(); node.getNode("fib8.csv").select(); node.getNode("fib8.csv").doubleClick(); // Test the plot series selection dialog. SWTBotToolbarButton button; button = bot.activeEditor().bot().toolbarButton(0); button.click(); bot.shell("Select a series").activate(); bot.tree().select("f(x)"); bot.button("OK").click(); // Check that the data tab is present bot.cTabItem("Data").activate(); bot.cTabItem("Plot").activate(); // Test the editor closing menu option. button = bot.activeEditor().bot().toolbarButton(1).click(); return; }
public static void closeWelcomePage(SWTWorkbenchBot bot) { try { bot.viewByTitle("Welcome").close(); } catch (WidgetNotFoundException e) { // Ignore if Welcome view already closed } }
/** * 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); }
/** * 设置记忆库 * @param from * 功能入口,请使用 TSUIConstants 类提供的常量; * @param nextAction * 下一步操作,请使用本类提供的常量; */ public void setTMDB(Entry from, NextAction nextAction) { if (dlgPrjSetting == null) { openPrjSettingDlg(from); } dlgPrjSetting.treiTmSetting().select(); if (!dlgPrjSetting.table().containsTextInColumn(tMDBName, dlgPrjSetting.tblColName())) { if (isTMDBExist) { dlgPrjSetting.btnAdd().click(); DBManagement dbMgmt = new DBManagement(row); dbMgmt.selectDB(tMDBName); } else { dlgPrjSetting.btnCreate().click(); // TODO 目前弹出的是数据库创建向导,而该向导有较大的改进余地,暂不实现 } try { InformationDialog dlgInfo = new InformationDialog(InformationDialog.dlgTitleTips, InformationDialog.msgNoMatchInDB); dlgInfo.btnOK().click(); Waits.shellClosed(dlgInfo); } catch (WidgetNotFoundException e) { // e.printStackTrace(); } assertTrue("未正确选择记忆库:" + tMDBName, dlgPrjSetting.table().containsTextInColumn(tMDBName, dlgPrjSetting.tblColName())); } nextAction(nextAction); }
/** * 设置术语库 * @param from * 功能入口,请使用 TSUIConstants 类提供的常量; * @param nextAction * 下一步操作,请使用本类提供的常量; */ public void setTBDB(Entry from, NextAction nextAction) { if (dlgPrjSetting == null) { openPrjSettingDlg(from); } dlgPrjSetting.treiTbSetting().select(); if (!dlgPrjSetting.table().containsTextInColumn(tBDBName, dlgPrjSetting.tblColName())) { if (isTBDBExist) { dlgPrjSetting.btnAdd().click(); DBManagement dbMgmt = new DBManagement(row); dbMgmt.selectDB(tBDBName); } else { dlgPrjSetting.btnCreate().click(); // TODO 同上 } try { InformationDialog dlgInfo = new InformationDialog(InformationDialog.dlgTitleTips, InformationDialog.msgNoMatchInDB); dlgInfo.btnOK().click(); Waits.shellClosed(dlgInfo); } catch (WidgetNotFoundException e) { e.printStackTrace(); } assertTrue("未正确选择术语库:" + tBDBName, dlgPrjSetting.table().containsTextInColumn(tBDBName, dlgPrjSetting.tblColName())); } nextAction(nextAction); }
/** * 预翻译 * @param from * 入口,请使用 TSUIConstants 类提供的常量; */ public void preTranslate(Entry from) { getDataPreTrans(); select(); openPreTransDlg(from); assertTrue("未正确添加选中的文件:" + fileFullPath, dlgPreTrans.table().containsTextInColumn(fileFullPath, dlgPreTrans.tblColFile())); dlgPreTrans.btnOK().click(); HSBot.bot().waitUntil(new DefaultCondition() { public boolean test() throws Exception { try { dlgPreTransResult = new PreTranslateResultDialog(); return dlgPreTransResult.isOpen(); } catch (WidgetNotFoundException e) { return false; } } public String getFailureMessage() { return "未正确显示预翻译结果对话框。"; } }, 3600000); assertTrue("未正确该文件的预翻译结果:" + fileFullPath, dlgPreTransResult.table().containsTextInColumn(fileFullPath, dlgPreTransResult.tblColFile())); dlgPreTransResult.btnOK().click(); }
/** * 关掉多余的对话框,以避免影响后面执行的用例; */ public static void closeDialogs() { SWTBotShell[] shells = HSBot.bot().shells(); int len = shells.length; if (len > 1) { org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences.TIMEOUT = 1000; // 减少等待时间 for (int i = len - 1; i >= 1; i--) { try { if (shells[i].bot().button(TsUIConstants.getString("btnCancel")).isActive()) { shells[i].bot().button(TsUIConstants.getString("btnCancel")).click(); } } catch (WidgetNotFoundException e1) { try { if (shells[i].bot().button(TsUIConstants.getString("btnOK")).isActive()) { shells[i].bot().button(TsUIConstants.getString("btnOK")).click(); } } catch (WidgetNotFoundException e2) { try { if (shells[i].bot().button(TsUIConstants.getString("btnClose")).isActive()) { shells[i].bot().button(TsUIConstants.getString("btnClose")).click(); } else { shells[i].close(); } } catch (WidgetNotFoundException e3) { shells[i].close(); } } } } org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences.TIMEOUT = 5000; // 恢复默认的超时时间 } }
/** * @return 是表示出现 out of sync 提示 */ public boolean isOutOfSync() { assertTrue("参数错误:未设置 name。", name != null); try { lblOutOfSync(name).isVisible(); return true; } catch (WidgetNotFoundException e) { return false; } }
/** * @return 是表示出现名称非法提示; */ public boolean isInvalidMsgVisible() { assertTrue("参数错误:未设置 name 或 invalidChar。", (name != null && invalidChar != null)); try { lblInvalidChar(name, invalidChar).isVisible(); return true; } catch (WidgetNotFoundException e) { return false; } }
/** * @return 是表示出现 out of sync 提示 */ public boolean isOutOfSync() { assertTrue("参数错误:未设置 oldName。", oldName != null); try { lblOutOfSync(oldName).isVisible(); return true; } catch (WidgetNotFoundException e) { return false; } }
/** * @return 是表示出现项目已存在提示; */ public boolean isProjectExistsMsgVisible() { assertTrue("参数错误:未设置 name。", name != null); try { lblProjectExists(name).isVisible(); return true; } catch (WidgetNotFoundException e) { return false; } }