org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException Java Examples

The following examples show how to use org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException. 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: WidgetUtil.java    From saros with GNU General Public License v2.0 6 votes vote down vote up
public static SWTBotToolbarButton getToolbarButtonWithRegex(
    final SWTBotView view, final String regex) {

  try {
    new SWTBot()
        .waitUntil(
            new DefaultCondition() {
              @Override
              public String getFailureMessage() {
                return "Could not find toolbar button matching " + regex;
              }

              @Override
              public boolean test() throws Exception {
                return getToolbarButton(view, regex) != null;
              }
            });
    return getToolbarButton(view, regex);

  } catch (TimeoutException e) {
    throw new WidgetNotFoundException(
        "Timed out waiting for toolbar button matching " + regex, e); // $NON-NLS-1$
  }
}
 
Example #2
Source File: RemoteBotShell.java    From saros with GNU General Public License v2.0 6 votes vote down vote up
@Override
public String getMessage() throws RemoteException {
  activate();
  final String message =
      UIThreadRunnable.syncExec(
          new StringResult() {
            @Override
            public String run() {
              WizardDialog dialog = (WizardDialog) widget.widget.getData();
              return dialog.getMessage();
            }
          });
  if (message == null) {
    throw new WidgetNotFoundException("could not find message!");
  }
  return message;
}
 
Example #3
Source File: WidgetUtil.java    From saros with GNU General Public License v2.0 6 votes vote down vote up
public static SWTBotTreeItem getTreeItemWithRegex(
    final SWTBotTree tree, final String... regexNodes) {

  try {
    new SWTBot()
        .waitUntil(
            new DefaultCondition() {
              @Override
              public String getFailureMessage() {
                return "Could not find node matching " + Arrays.asList(regexNodes);
              }

              @Override
              public boolean test() throws Exception {
                return getTreeItem(tree.getAllItems(), regexNodes) != null;
              }
            });
    return getTreeItem(tree.getAllItems(), regexNodes);

  } catch (TimeoutException e) {
    throw new WidgetNotFoundException(
        "Timed out waiting for tree item matching " + Arrays.asList(regexNodes),
        e); //$NON-NLS-1$
  }
}
 
Example #4
Source File: RCPTestSetupHelper.java    From tlaplus with MIT License 6 votes vote down vote up
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;
			}
		}
	});
}
 
Example #5
Source File: SWTBotTableCombo.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Gets the table item matching the given name.
 *
 * @param itemText the text on the node.
 * @return the table item with the specified text.
 * @throws WidgetNotFoundException if the node was not found.
 * @since 1.3
 */
public SWTBotTableItem getTableItem(final String itemText) throws WidgetNotFoundException {
	try {
		new SWTBot().waitUntil(new DefaultCondition() {
			public String getFailureMessage() {
				return "Could not find node with text " + itemText; //$NON-NLS-1$
			}

			public boolean test() throws Exception {
				return getItem(itemText) != null;
			}
		});
	} catch (TimeoutException e) {
		throw new WidgetNotFoundException("Timed out waiting for table item " + itemText, e); //$NON-NLS-1$
	}
	return new SWTBotTableItem(getItem(itemText));
}
 
Example #6
Source File: SwtBotProjectHelper.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
protected static void fileNew(final SWTWorkbenchBot it, final String newWhat) {
  int retries = 3;
  ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, retries, true);
  for (final Integer i : _doubleDotLessThan) {
    try {
      it.menu("File").menu("New").menu(newWhat).click();
      return;
    } catch (final Throwable _t) {
      if (_t instanceof WidgetNotFoundException) {
        final WidgetNotFoundException e = (WidgetNotFoundException)_t;
        if (((i).intValue() == (retries - 1))) {
          throw e;
        }
        String _message = e.getMessage();
        String _plus = ("failed: " + _message);
        InputOutput.<String>println(_plus);
        InputOutput.<String>println("retrying...");
        it.sleep(1000);
      } else {
        throw Exceptions.sneakyThrow(_t);
      }
    }
  }
}
 
Example #7
Source File: SwtBotProjectActions.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #8
Source File: NewC.java    From saros with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void cls(String projectName, String pkg, String className) throws RemoteException {

  try {
    ContextMenuHelper.clickContextMenu(tree, MENU_NEW, MENU_CLASS);
    confirmShellNewJavaClass(projectName, pkg, className);
  } catch (WidgetNotFoundException e) {
    final String cause =
        "error creating new Java class '"
            + className
            + "' in package '"
            + pkg
            + "' and project '"
            + projectName
            + "'";
    log.error(cause, e);
    throw new RemoteException(cause, e);
  }
  // }
}
 
Example #9
Source File: PluginTest.java    From CodeCheckerEclipsePlugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Test that after adding nature to a C project, the add nature menu item
 * disappears.
 */
@Test
public void testAddNatureDisappears() {

    SWTBotTreeItem project = bot.tree().getTreeItem(CPP_PROJ).doubleClick();
    SWTBotMenu menu = project.contextMenu(ADD_NATURE_MENU);

    assertThat("Add CodeChecker Nature menu item wasn't enabled", menu.isEnabled(), is(true));

    menu.click();

    // Widget should be missing now.
    thrown.expect(WidgetNotFoundException.class);
    thrown.expectMessage(containsString("Could not find"));
    project.contextMenu(ADD_NATURE_MENU);
}
 
Example #10
Source File: SwtBotTreeActions.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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.");
}
 
Example #11
Source File: CopyToClipboardTest.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
private static void assertContextMenuAbsent(final SWTBotTable tableBot, final String text) {
    fBot.waitUntil(new DefaultCondition() {
        @Override
        public boolean test() throws Exception {
            try {
                SWTBotPreferences.TIMEOUT = 0;
                tableBot.contextMenu(text);
            } catch (WidgetNotFoundException e) {
                return true;
            } finally {
                SWTBotPreferences.TIMEOUT = TIMEOUT;
            }
            return false;
        }
        @Override
        public String getFailureMessage() {
            return text + " context menu present, absent expected.";
        }
    });
}
 
Example #12
Source File: TestValidSelectionExport.java    From aCute with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testValidSelectionExport() {
openExportWizard();
SWTBotButton finishButton = bot.button("Finish");
assertTrue("Should be able to Finish an export with a valid Project selected.", finishButton.isEnabled());
finishButton.click();

bot.waitUntil(Conditions.waitForWidget(withText("<terminated> .NET Core Export")),30000);

SWTBotView view = bot.viewByTitle("Project Explorer");
SWTBotTree tree = new SWTBot(view.getWidget()).tree(0);
SWTBotTreeItem projectItem = tree.getTreeItem(project.getName());

try {
	projectItem.expand().getNode("bin");
}catch (WidgetNotFoundException e) {
	SWTBotView consoleView = bot.viewByPartName("Console");
	fail("Export failed: "+ consoleView.bot().styledText().getText());
}
}
 
Example #13
Source File: BotBdmQueriesEditor.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
private void selectCustomQuery(String queryName) {
    SWTBotTree tree = getQueryListTree();
    tree.select(Messages.customQueriesOption);
    tree.expandNode(Messages.customQueriesOption);
    bot.waitUntil(new ConditionBuilder()
            .withTest(() -> {
                try {
                    tree.getTreeItem(Messages.customQueriesOption).getNode(queryName);
                    return true;
                } catch (WidgetNotFoundException e) {
                    return false;
                }
            })
            .withFailureMessage(() -> String.format("Can't find custom query %s", queryName))
            .create());
    tree.getTreeItem(Messages.customQueriesOption).getNode(queryName).select();
}
 
Example #14
Source File: ProjectExistsDialog.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @return 是表示出现项目已存在提示;
 */
public boolean isProjectExistsMsgVisible() {
	assertTrue("参数错误:未设置 name。", name != null);
	try {
		lblProjectExists(name).isVisible();
		return true;
	} catch (WidgetNotFoundException e) {
		return false;
	}
}
 
Example #15
Source File: Share3UsersLeavingSessionTest.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Steps:
 *
 * <ol>
 *   <li>Alice share project with Bob.
 *   <li>Alice invites Carl.
 *   <li>Alice and Bob leave the session.
 *   <li>Carl accepts the session.
 * </ol>
 *
 * Result: Alice, Bob and Carl are not in a session.
 */
@Test
public void testShare3UsersLeavingSession() throws Exception {
  ALICE
      .superBot()
      .views()
      .packageExplorerView()
      .tree()
      .newC()
      .javaProjectWithClasses(Constants.PROJECT1, Constants.PKG1, Constants.CLS1);

  Util.buildSessionSequentially(Constants.PROJECT1, TypeOfCreateProject.NEW_PROJECT, ALICE, BOB);

  assertTrue(BOB.superBot().views().sarosView().isInSession());
  assertTrue(ALICE.superBot().views().sarosView().isInSession());

  ALICE.superBot().views().sarosView().selectSession().addContactsToSession(CARL.getBaseJid());

  CARL.remoteBot().waitLongUntilShellIsOpen(SHELL_SESSION_INVITATION);

  ALICE.superBot().views().sarosView().leaveSession();

  ALICE.superBot().views().sarosView().waitUntilIsNotInSession();
  BOB.superBot().views().sarosView().waitUntilIsNotInSession();

  Thread.sleep(2000);

  try {
    CARL.remoteBot().shell("Invitation Canceled").confirm(OK);
  } catch (WidgetNotFoundException e) {
    fail("Invitation Canceled is not open: " + e.getMessage());
  }
  assertFalse(
      CARL + " is in a closed session", CARL.superBot().views().sarosView().isInSession());
  assertFalse(
      ALICE + " is in a closed session", ALICE.superBot().views().sarosView().isInSession());
  assertFalse(BOB + " is in a closed session", BOB.superBot().views().sarosView().isInSession());
}
 
Example #16
Source File: RemoteBot.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean existsTable() throws RemoteException {
  try {
    swtBot.table();
    return true;
  } catch (WidgetNotFoundException e) {
    return false;
  }
}
 
Example #17
Source File: RemoteBot.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean existsLabelInGroup(String groupName) throws RemoteException {

  try {
    swtBot.labelInGroup(groupName);
    return true;
  } catch (WidgetNotFoundException e) {
    return false;
  }
}
 
Example #18
Source File: AbstractBotWizardPage.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
public boolean canFlipToPreviousPage() {
    try {
        bot.button(IDialogConstants.BACK_LABEL);
    } catch (final WidgetNotFoundException e) {
        return false;
    }
    return bot.button(IDialogConstants.BACK_LABEL).isEnabled();
}
 
Example #19
Source File: AbstractWorkbenchTester.java    From ice with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #20
Source File: RemoteBot.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean existsLabel(String text) throws RemoteException {

  try {
    swtBot.label(text);
    return true;
  } catch (WidgetNotFoundException e) {
    return false;
  }
}
 
Example #21
Source File: RenameResourceDialog.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @return 是表示出现 out of sync 提示
 */
public boolean isOutOfSync() {
	assertTrue("参数错误:未设置 oldName。", oldName != null);
	try {
		lblOutOfSync(oldName).isVisible();
		return true;
	} catch (WidgetNotFoundException e) {
		return false;
	}
}
 
Example #22
Source File: PreTranslate.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 预翻译
 * @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();
}
 
Example #23
Source File: RenameProblemsDialog.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @return 是表示出现 out of sync 提示
 */
public boolean isOutOfSync() {
	assertTrue("参数错误:未设置 name。", name != null);
	try {
		lblOutOfSync(name).isVisible();
		return true;
	} catch (WidgetNotFoundException e) {
		return false;
	}
}
 
Example #24
Source File: TsTasks.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 *  关掉多余的对话框,以避免影响后面执行的用例;
 */
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; // 恢复默认的超时时间
	}
}
 
Example #25
Source File: PreTranslate.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 预翻译
 * @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();
}
 
Example #26
Source File: SwtBotWorkbenchActions.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
public static void closeWelcomePage(SWTWorkbenchBot bot) {
  try {
    bot.viewByTitle("Welcome").close();
  } catch (WidgetNotFoundException e) {
    // Ignore if Welcome view already closed
  }
}
 
Example #27
Source File: ProjectSetting.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 设置术语库
 * @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);
}
 
Example #28
Source File: ProjectSetting.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 设置记忆库
 * @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);
}
 
Example #29
Source File: SWTBotTableComboColumn.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a new instance of this object.
 * 
 * @param w the widget.
 * @throws WidgetNotFoundException if the widget is <code>null</code> or widget has been disposed.
 * @since 2.0
 */
public SWTBotTableComboColumn(final TableColumn w) throws WidgetNotFoundException {
	this(w, UIThreadRunnable.syncExec(new WidgetResult<Table>() {
		public Table run() {
			return w.getParent();
		}
	}));
}
 
Example #30
Source File: SwtBotProjectActions.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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);
}