/** * Pre flight initialization (run once for each test _case_) */ @Before public void setUp() throws Exception { // Force shell activation to counter, no active Shell when running SWTBot tests in Xvfb/Xvnc // see https://wiki.eclipse.org/SWTBot/Troubleshooting#No_active_Shell_when_running_SWTBot_tests_in_Xvfb Display.getDefault().syncExec(new Runnable() { public void run() { PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().forceActive(); } }); bot = new SWTWorkbenchBot(); // Wait for the Toolbox shell to be available final Matcher<Shell> withText = withText("TLA+ Toolbox"); bot.waitUntil(Conditions.waitForShell(withText), 30000); // Wait for the Toolbox UI to be fully started. final Matcher<MenuItem> withMnemonic = WidgetMatcherFactory.withMnemonic("File"); final Matcher<MenuItem> matcher = WidgetMatcherFactory.allOf(WidgetMatcherFactory.widgetOfType(MenuItem.class), withMnemonic); bot.waitUntil(Conditions.waitForMenu(bot.shell("TLA+ Toolbox"), matcher), 30000); }
@BeforeClass public static void beforeClass() throws Exception { RCPTestSetupHelper.beforeClass(); // Force shell activation to counter, no active Shell when running SWTBot tests in Xvfb/Xvnc // see https://wiki.eclipse.org/SWTBot/Troubleshooting#No_active_Shell_when_running_SWTBot_tests_in_Xvfb Display.getDefault().syncExec(new Runnable() { public void run() { PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().forceActive(); } }); bot = new SWTWorkbenchBot(); // Wait for the Toolbox shell to be available final Matcher<Shell> withText = withText("TLA+ Toolbox"); bot.waitUntil(Conditions.waitForShell(withText), 30000); // Wait for the Toolbox UI to be fully started. final Matcher<MenuItem> withMnemonic = WidgetMatcherFactory.withMnemonic("File"); final Matcher<MenuItem> matcher = WidgetMatcherFactory.allOf(WidgetMatcherFactory.widgetOfType(MenuItem.class), withMnemonic); bot.waitUntil(Conditions.waitForMenu(bot.shell("TLA+ Toolbox"), matcher), 30000); }
public GraphModelProperties(SWTBot bot, String project, String folder,String pkg, String filename) { super(); this.bot = bot; this.project = project; this.folder = folder; this.pkg = pkg; this.filename = filename; bot.tree().setFocus(); bot.tree().select("GW4E"); bot.waitUntil(Conditions.waitForWidget(WidgetMatcherFactory.withId(GraphModelPropertyPage.GW4E_LABEL_ID, GraphModelPropertyPage.GW4E_LABEL_ID))); }
public GW4EProjectProperties openPropertiesPage ( ) { SWTBotTree tree = getProjectTree(); SWTBotTreeItem item = tree.expandNode(this.projectName); item.setFocus(); item.select(); ICondition condition = new DefaultCondition () { @Override public boolean test() throws Exception { SWTBotTreeItem treeItem = tree.getTreeItem(projectName); return treeItem.isSelected(); } @Override public String getFailureMessage() { return "Project " + projectName + " not selected "; } }; bot.waitUntil(condition); bot.menu( "File").menu("Properties").click(); bot.waitUntil(Conditions.shellIsActive("Properties for " + projectName)); SWTBotShell shell = bot.shell("Properties for " + projectName).activate(); shell.bot().tree().select("GW4E"); bot.waitUntil(Conditions.waitForWidget(WidgetMatcherFactory.withId( ProjectPropertyPage.PROJECT_PROPERTY_PAGE_WIDGET_ID, ProjectPropertyPage.PROJECT_PROPERTY_PAGE_WIDGET_SECURITY_LEVEL_FOR_ABSTRACT_CONTEXT))); return new GW4EProjectProperties(bot,shell); }
@Override protected ICondition getWaitConditionWhenOpeningConfiguration() { ICondition condition = Conditions.waitForWidget( WidgetMatcherFactory.withId( GW4ELaunchConfigurationTab.GW4E_LAUNCH_CONFIGURATION_CONTROL_ID, GW4ELaunchConfigurationTab.GW4E_LAUNCH_CONFIGURATION_BUTTON_ID_OMIT_EMPTY_EDGE)); return condition; }
@Override protected ICondition getWaitConditionWhenOpeningConfiguration() { ICondition condition = Conditions.waitForWidget( WidgetMatcherFactory.withId( GW4ELaunchConfigurationTab.GW4E_LAUNCH_CONFIGURATION_CONTROL_ID, GW4ELaunchConfigurationTab.GW4E_LAUNCH_TEST_CONFIGURATION_PROJECT)); return condition; }
@Override protected ICondition getWaitConditionWhenOpeningConfiguration() { ICondition condition = Conditions.waitForWidget( WidgetMatcherFactory.withId( GW4ELaunchConfigurationTab.GW4E_LAUNCH_CONFIGURATION_CONTROL_ID, GW4ELaunchConfigurationTab.GW4E_LAUNCH_CONFIGURATION_TEXT_ID_PROJECT)); return condition; }
private static boolean appEngineMenuExists(IProject project) { SWTBotTreeItem selected = SwtBotProjectActions.selectProject( new SWTWorkbenchBot(), project.getName()); Menu runAsMenu = selected.contextMenu("Run As").widget.getMenu(); Matcher<MenuItem> matcher = WidgetMatcherFactory.withRegex("App Engine"); List<MenuItem> menuItems = new MenuFinder().findMenus(runAsMenu, matcher, false); return !menuItems.isEmpty(); }
/** * 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"); } }); }
private static Matcher<Widget> getConsoleMatcher () { Matcher<Widget> console = WidgetMatcherFactory.withMnemonic("Console"); return console; }
WaitForTreeItem(final Tree parent) { super(WidgetMatcherFactory.widgetOfType(TreeItem.class)); this.parent = parent; }
/** * Creates an {@link SwtBotRadio} with the given label and the given index. * <p> * <em>Note</em>: This method may throw a {@link org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException} if the widget is not found or is disposed. * </p> * * @param label * the label on the widget, must not be {@code null} * @param index * the index of the widget, must not be {@code null} * @return a {@link SwtBotRadio} with the specified {@Code label}, never {@code null} */ @Override @SuppressWarnings({"unchecked", "rawtypes"}) public SwtBotRadio radioWithLabel(final String label, final int index) { Matcher matcher = allOf(widgetOfType(Button.class), WidgetMatcherFactory.withLabel(label, finder), withStyle(SWT.RADIO, "SWT.RADIO")); return new SwtBotRadio((Button) widget(matcher, index), matcher); }
/** * Creates an {@link SwtBotRadio} with the given label, the given group and the given index. * <p> * <em>Note</em>: This method may throw a {@link org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException} if the widget is not found or is disposed. * </p> * * @param label * the label on the widget, must not be {@code null} * @param inGroup * the inGroup on the widget, must not be {@code null} * @param index * the index of the widget, must not be {@code null} * @return a {@link SwtBotRadio} with the specified {@code label} with the specified {@code inGroup}, never {@code null} */ @Override @SuppressWarnings({"unchecked", "rawtypes"}) public SwtBotRadio radioWithLabelInGroup(final String label, final String inGroup, final int index) { Matcher matcher = allOf(widgetOfType(Button.class), WidgetMatcherFactory.withLabel(label, finder), inGroup(inGroup), withStyle(SWT.RADIO, "SWT.RADIO")); return new SwtBotRadio((Button) widget(matcher, index), matcher); }