Java Code Examples for org.eclipse.swtbot.swt.finder.SWTBot#sleep()
The following examples show how to use
org.eclipse.swtbot.swt.finder.SWTBot#sleep() .
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: SwtBotTreeActions.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
/** * Blocks the caller until the tree item has the given item text. * * @param tree the tree item to search * @param nodeText the item text to look for * @throws org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException if the item could not * be found within the timeout period */ private static void waitUntilTreeItemHasItem(SWTBot bot, final SWTBotTreeItem tree, final String nodeText) { // Attempt #1 if (!waitUntilTreeHasItemImpl(bot, tree.widget, nodeText)) { // Attempt #2: Something went wrong, try to cautiously reopen it. bot.sleep(1000); // There isn't a method to collapse, so double-click instead tree.doubleClick(); bot.waitUntil(new TreeCollapsedCondition(tree.widget)); bot.sleep(1000); tree.expand(); bot.waitUntil(new TreeExpandedCondition(tree.widget)); if (!waitUntilTreeHasItemImpl(bot, tree.widget, nodeText)) { printTree(tree.widget); throw new TimeoutException( String.format("Timed out waiting for %s, giving up...", nodeText)); } } }
Example 2
Source File: SwtBotTreeActions.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
/** * Blocks the caller until all of the direct children of the tree have text. The assumption is * that the tree does not have any "empty" children. * * TODO: Refactor some of this logic; it follows the same general pattern as * {@link #waitUntilTreeItemHasItem(SWTBot, SWTBotTreeItem, String)}. * * @param tree the tree to search * @throws TimeoutException if all of the direct children of the tree do not have text within the * timeout period */ public static void waitUntilTreeHasText(SWTBot bot, final SWTBotTreeItem tree) throws TimeoutException { // Attempt #1 if (!waitUntilTreeHasTextImpl(bot, tree.widget)) { // Attempt #2: Something went wrong, try to cautiously reopen it. bot.sleep(1000); // There isn't a method to collapse, so double-click instead tree.doubleClick(); bot.waitUntil(new TreeCollapsedCondition(tree.widget)); bot.sleep(1000); tree.expand(); bot.waitUntil(new TreeExpandedCondition(tree.widget)); if (!waitUntilTreeHasTextImpl(bot, tree.widget)) { printTree(tree.widget); throw new TimeoutException( "Timed out waiting for text of the tree's children, giving up..."); } } }
Example 3
Source File: SuperBot.java From saros with GNU General Public License v2.0 | 6 votes |
@Override public void confirmShellAddProjectsToSession(String... projectNames) throws RemoteException { SWTBot bot = new SWTBot(); SWTBotShell shell = bot.shell(SHELL_ADD_PROJECTS_TO_SESSION); shell.activate(); // wait for tree update bot.sleep(500); SWTBotTree tree = shell.bot().tree(); for (String projectName : projectNames) tree.getTreeItem(projectName).check(); shell.bot().button(FINISH).click(); bot.waitUntil(Conditions.shellCloses(shell)); }
Example 4
Source File: SuperBot.java From saros with GNU General Public License v2.0 | 6 votes |
@Override public void confirmShellAddProjectToSession(String project, String[] files) throws RemoteException { SWTBot bot = new SWTBot(); SWTBotShell shell = bot.shell(SHELL_ADD_PROJECTS_TO_SESSION); shell.activate(); // wait for tree update bot.sleep(500); SWTBotTree tree = shell.bot().tree(); selectProjectFiles(tree, project, files); shell.bot().button(FINISH).click(); bot.waitUntil(Conditions.shellCloses(shell)); }
Example 5
Source File: SwtBotWorkbenchActions.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
private static void openPreferencesDialogViaEvents(SWTBot bot) { Display display = bot.getDisplay(); Event event = new Event(); // Move to the "Apple" menu item (it catches 0, 0) event.type = SWT.MouseMove; event.x = 0; event.y = 0; display.post(event); bot.sleep(OPEN_PREFERENCES_DIALOG_DELAY_MS); // Click event.type = SWT.MouseDown; event.button = 1; display.post(event); bot.sleep(SwtBotTestingUtilities.EVENT_DOWN_UP_DELAY_MS); event.type = SWT.MouseUp; display.post(event); bot.sleep(OPEN_PREFERENCES_DIALOG_DELAY_MS); // Right to the "Eclipse" menu item SwtBotTestingUtilities.sendKeyDownAndUp(bot, SWT.ARROW_RIGHT, '\0'); bot.sleep(OPEN_PREFERENCES_DIALOG_DELAY_MS); // Down two to the "Preferences..." menu item SwtBotTestingUtilities.sendKeyDownAndUp(bot, SWT.ARROW_DOWN, '\0'); bot.sleep(OPEN_PREFERENCES_DIALOG_DELAY_MS); SwtBotTestingUtilities.sendKeyDownAndUp(bot, SWT.ARROW_DOWN, '\0'); bot.sleep(OPEN_PREFERENCES_DIALOG_DELAY_MS); // Press enter SwtBotTestingUtilities.sendKeyDownAndUp(bot, 0, '\r'); bot.sleep(OPEN_PREFERENCES_DIALOG_DELAY_MS); }
Example 6
Source File: SwtBotTestingUtilities.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
/** * Injects a key or character via down and up events. Only one of {@code keyCode} or * {@code character} must be provided. Use * * @param keyCode the keycode of the key (use {@code 0} if unspecified) * @param character the character to press (use {@code '\0'} if unspecified) */ public static void sendKeyDownAndUp(SWTBot bot, int keyCode, char character) { Event ev = new Event(); ev.keyCode = keyCode; ev.character = character; ev.type = SWT.KeyDown; bot.getDisplay().post(ev); bot.sleep(EVENT_DOWN_UP_DELAY_MS); ev.type = SWT.KeyUp; bot.getDisplay().post(ev); }
Example 7
Source File: SwtBotWorkbenchActions.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
/** * Wait until all background tasks are complete. */ public static void waitForIdle(SWTBot bot) { SwtBotUtils.print("\t\tWaiting for idle"); while (!Job.getJobManager().isIdle()) { bot.sleep(500); } SwtBotUtils.print("\t\tNow idle"); }
Example 8
Source File: SwtBotWorkbenchActions.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
private static void openPreferencesDialogViaEvents(SWTBot bot) { Display display = bot.getDisplay(); Event ev = new Event(); // Move to the "Apple" menu item (it catches 0, 0) ev.type = SWT.MouseMove; ev.x = 0; ev.y = 0; display.post(ev); bot.sleep(OPEN_PREFERENCES_DIALOG_DELAY_MS); // Click ev.type = SWT.MouseDown; ev.button = 1; display.post(ev); bot.sleep(SwtBotUtils.EVENT_DOWN_UP_DELAY_MS); ev.type = SWT.MouseUp; display.post(ev); bot.sleep(OPEN_PREFERENCES_DIALOG_DELAY_MS); // Right to the "Eclipse" menu item SwtBotUtils.sendKeyDownAndUp(bot, SWT.ARROW_RIGHT, '\0'); bot.sleep(OPEN_PREFERENCES_DIALOG_DELAY_MS); // Down two to the "Preferences..." menu item SwtBotUtils.sendKeyDownAndUp(bot, SWT.ARROW_DOWN, '\0'); bot.sleep(OPEN_PREFERENCES_DIALOG_DELAY_MS); SwtBotUtils.sendKeyDownAndUp(bot, SWT.ARROW_DOWN, '\0'); bot.sleep(OPEN_PREFERENCES_DIALOG_DELAY_MS); // Press enter SwtBotUtils.sendKeyDownAndUp(bot, 0, '\r'); bot.sleep(OPEN_PREFERENCES_DIALOG_DELAY_MS); }
Example 9
Source File: SwtBotUtils.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
/** * Injects a key or character via down and up events. * * @param keyCode the keycode of the key (only this or character have to be provided.) * @param character the character to press (only this or keyCode have to be provided.) */ public static void sendKeyDownAndUp(SWTBot bot, int keyCode, char character) { Event ev = new Event(); ev.keyCode = keyCode; ev.character = character; ev.type = SWT.KeyDown; bot.getDisplay().post(ev); bot.sleep(EVENT_DOWN_UP_DELAY_MS); ev.type = SWT.KeyUp; bot.getDisplay().post(ev); }
Example 10
Source File: SuperBot.java From saros with GNU General Public License v2.0 | 5 votes |
@Override public void confirmShellAddContact(JID jid) throws RemoteException { SWTBot bot = new SWTBot(); SWTBotShell shell = bot.shell(SHELL_ADD_CONTACT_WIZARD); shell.activate(); shell.bot().comboBoxWithLabel(LABEL_XMPP_JABBER_ID).setText(jid.getBase()); shell.bot().button(FINISH).click(); try { bot.waitUntil(Conditions.shellCloses(shell)); } catch (TimeoutException e) { // If the dialog didn't close in time, close any message boxes that // a you can answer with "Yes, I want to add the contact anyway" // FIXME Hard-coded message titles (see AddContactWizard) List<String> messagesToIgnore = Arrays.asList( "Contact Unknown", "Server Not Found", "Unsupported Contact Status Check", "Unknown Contact Status", "Server Not Responding", "Unknown Error"); for (SWTBotShell currentShell : bot.shells()) { String text = currentShell.getText(); if (messagesToIgnore.contains(text)) { currentShell.bot().button(YES).click(); } } } // wait for tree update in the saros session view bot.sleep(500); }
Example 11
Source File: SuperBot.java From saros with GNU General Public License v2.0 | 5 votes |
@Override public void confirmShellRequestOfSubscriptionReceived() throws RemoteException { SWTBot bot = new SWTBot(); SWTBotShell shell = bot.shell(SHELL_REQUEST_OF_SUBSCRIPTION_RECEIVED); shell.activate(); shell.bot().button(OK).click(); bot.waitUntil(Conditions.shellCloses(shell)); // wait for tree update in the saros session view bot.sleep(500); }
Example 12
Source File: SWTBotTestUtil.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
/** * add data with option wizard configuration (only for defined types as String Integer Boolean etc.) * * @param bot * @param name * @param type * @param multiplicity * @param defaultValue */ public static void addListOfOptionData(final SWTBot bot, final String name, final String type, final Map<String, List<String>> options, final boolean isMultiple, final String defaultValue) { bot.waitUntil(Conditions.shellIsActive("New variable")); bot.textWithLabel(org.bonitasoft.studio.properties.i18n.Messages.name + " *").setText(name); bot.comboBoxWithLabel(org.bonitasoft.studio.properties.i18n.Messages.datatypeLabel).setSelection(type); SWTBotShell activeShell = bot.activeShell(); bot.button("List of options...").click(); bot.waitUntil(Conditions.shellIsActive("List of options")); int i = 0; for (final String optionsName : options.keySet()) { bot.button("Add", 0).click(); bot.table(0).click(i, 0); bot.text().setText(optionsName); int j = 0; for (final String option : options.get(optionsName)) { bot.button("Add", 1).click(); bot.table(1).click(j, 0); bot.text().setText(option); j++; } i++; } bot.button(IDialogConstants.OK_LABEL).click(); activeShell.setFocus(); if (isMultiple) { bot.checkBox("Is multiple").select(); } if (defaultValue != null) { bot.textWithLabel(org.bonitasoft.studio.properties.i18n.Messages.defaultValueLabel).setText(defaultValue); bot.sleep(1000); } bot.button(IDialogConstants.FINISH_LABEL).click(); }
Example 13
Source File: SwtBotWorkbenchActions.java From google-cloud-eclipse with Apache License 2.0 | 4 votes |
/** * Wait until all background tasks are complete. */ public static void waitForProjects(SWTBot bot, IProject... projects) { Runnable delayTactic = () -> bot.sleep(300); ProjectUtils.waitForProjects(delayTactic, projects); }
Example 14
Source File: SuperBot.java From saros with GNU General Public License v2.0 | 4 votes |
@Override public void confirmShellAddProjectUsingExistProject(String projectName) throws RemoteException { SWTBot bot = new SWTBot(); bot.waitUntil( Conditions.shellIsActive(SHELL_ADD_PROJECTS), SarosSWTBotPreferences.SAROS_LONG_TIMEOUT); SWTBotShell shell = bot.shell(SHELL_ADD_PROJECTS); shell.activate(); // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=344484 // FIXME fix the bug in the SWTBot Framework, do not use a workaround final Button radioButton = shell.bot().radio(RADIO_CREATE_NEW_PROJECT).widget; UIThreadRunnable.syncExec( new VoidResult() { @Override public void run() { radioButton.setSelection(false); } }); shell.bot().radio(RADIO_USING_EXISTING_PROJECT).click(); shell.bot().textWithLabel("Project name", 1).setText(projectName); shell.bot().button(FINISH).click(); // prevent STF from entering an endless loop int timeout = 5; confirmDialogs: while (timeout-- > 0) { bot.sleep(2000); for (SWTBotShell currentShell : bot.shells()) { if (currentShell.getText().equals(SHELL_WARNING_LOCAL_CHANGES_DELETED) || currentShell.getText().equals(SHELL_SAVE_RESOURCE)) { currentShell.activate(); currentShell.bot().button(YES).click(); currentShell.bot().waitUntil(Conditions.shellCloses(currentShell)); break confirmDialogs; } else if (currentShell.getText().equals(SHELL_CONFIRM_SAVE_UNCHANGED_CHANGES)) { currentShell.activate(); currentShell.bot().button(YES).click(); currentShell.bot().waitUntil(Conditions.shellCloses(currentShell)); shell.bot().button(FINISH).click(); continue confirmDialogs; } } } shell.bot().waitUntil(Conditions.shellCloses(shell)); }
Example 15
Source File: SuperBot.java From saros with GNU General Public License v2.0 | 4 votes |
@Override public void confirmShellAddContactsToSession(String... baseJIDOfinvitees) throws RemoteException { SWTBot bot = new SWTBot(); SWTBotShell shell = bot.shell(SHELL_ADD_CONTACT_TO_SESSION); shell.activate(); // wait for tree update bot.sleep(500); SWTBotTree tree = shell.bot().tree(); for (String baseJID : baseJIDOfinvitees) WidgetUtil.getTreeItemWithRegex(tree, Pattern.quote(baseJID) + ".*").check(); shell.bot().button(FINISH).click(); bot.waitUntil(Conditions.shellCloses(shell)); // wait for tree update in the saros session view bot.sleep(500); }
Example 16
Source File: SuperBot.java From saros with GNU General Public License v2.0 | 3 votes |
public void confirmShellShareProjectFiles(String project, String[] files, JID[] jids) { SWTBot bot = new SWTBot(); SWTBotShell shell = bot.shell(SHELL_SHARE_PROJECT); shell.activate(); // wait for tree update bot.sleep(500); SWTBotTree tree = shell.bot().tree(); selectProjectFiles(tree, project, files); shell.bot().button(NEXT).click(); // wait for tree update bot.sleep(500); tree = shell.bot().tree(); for (SWTBotTreeItem item : tree.getAllItems()) while (item.isChecked()) item.uncheck(); for (JID jid : jids) WidgetUtil.getTreeItemWithRegex(tree, Pattern.quote(jid.getBase()) + ".*").check(); shell.bot().button(FINISH).click(); bot.waitUntil(Conditions.shellCloses(shell)); }