private ConvertDialog prepareConvertTo(String project, String packageRootFragment, String pkg, String targetFilename, String targetFormat, String... nodes) { SWTBotTree tree = getProjectTree(); SWTBotTreeItem item = tree.expandNode(nodes); item.select(); item.setFocus(); SWTBotMenu menu = item.contextMenu("GW4E").contextMenu("Convert to..."); menu.click(); bot.waitUntil(Conditions.shellIsActive("GW4E Conversion File")); SWTBotShell shell = bot.shell("GW4E Conversion File"); ConvertDialog cd = new ConvertDialog(shell); return cd; }
public void validateRun (String configurationName,String projectName,String filepath,boolean printUnvisited,boolean verbose,String startElement,String generator) { SWTBotShell shell = openExistingRun (configurationName); SWTBotText projectText = shell.bot().textWithId(GW4ELaunchConfigurationTab.GW4E_LAUNCH_CONFIGURATION_CONTROL_ID,GW4ELaunchConfigurationTab.GW4E_LAUNCH_CONFIGURATION_TEXT_ID_PROJECT); assertEquals("Wrong project name",projectName,projectText.getText()); SWTBotText modelText = shell.bot().textWithId(GW4ELaunchConfigurationTab.GW4E_LAUNCH_CONFIGURATION_CONTROL_ID,GW4ELaunchConfigurationTab.GW4E_LAUNCH_CONFIGURATION_TEXT_ID_MODEL); assertEquals("Wrong model name",filepath,modelText.getText()); SWTBotCheckBox verboseButton = shell.bot().checkBoxWithId(GW4ELaunchConfigurationTab.GW4E_LAUNCH_CONFIGURATION_CONTROL_ID,GW4ELaunchConfigurationTab.GW4E_LAUNCH_CONFIGURATION_BUTTON_ID_VERBOSE); assertEquals("Wrong verbose value",verbose,verboseButton.isChecked()); SWTBotCheckBox unvisitedButton = shell.bot().checkBoxWithId(GW4ELaunchConfigurationTab.GW4E_LAUNCH_CONFIGURATION_CONTROL_ID,GW4ELaunchConfigurationTab.GW4E_LAUNCH_CONFIGURATION_BUTTON_ID_PRINT_UNVISITED); assertEquals("Wrong verbose value",verbose,unvisitedButton.isChecked()); SWTBotText startElementText = shell.bot().textWithId(GW4ELaunchConfigurationTab.GW4E_LAUNCH_CONFIGURATION_CONTROL_ID,GW4ELaunchConfigurationTab.GW4E_LAUNCH_CONFIGURATION_TEXT_ID_START_ELEMENT); assertEquals("Wrong start element",startElement,startElementText.getText()); SWTBotCombo generatorCombo = shell.bot().comboBoxWithId(GW4ELaunchConfigurationTab.GW4E_LAUNCH_CONFIGURATION_CONTROL_ID,GW4ELaunchConfigurationTab.GW4E_LAUNCH_CONFIGURATION_COMBO_PATH_GENERATOR_ID_MODEL); assertEquals("Wrong generator value",generator,generatorCombo.getText()); SWTBotButton closeButton = bot.button("Close"); closeButton.click(); bot.waitUntil(Conditions.shellCloses(shell)); }
/** * Tests if a shell with a specific type of data contained (e.g. Window). * * @param bot * to use * @param clazz * class of data contained to check for */ @SuppressWarnings("rawtypes") public static void assertShellWithDataTypeVisible(final SWTWorkbenchBot bot, final Class clazz) { bot.waitUntil(Conditions.waitForShell(new BaseMatcher<Shell>() { @SuppressWarnings("unchecked") public boolean matches(final Object item) { return UIThreadRunnable.syncExec(new Result<Boolean>() { public Boolean run() { if (item instanceof Shell) { Object shellData = ((Shell) item).getData(); if (shellData != null) { return clazz.isAssignableFrom(shellData.getClass()); } } return false; } }); } public void describeTo(final Description description) { description.appendText("Shell for " + clazz.getName()); } })); }
public static void openPerspective(SWTWorkbenchBot bot, String perspectiveLabel) { SwtBotUtils.print("Opening Perspective: " + perspectiveLabel); SWTBotShell shell = null; try { menu(bot, "Window").menu("Open Perspective").menu("Other...").click(); shell = bot.shell("Open Perspective"); bot.waitUntil(ActiveWidgetCondition.widgetMakeActive(shell)); shell.bot().table().select(perspectiveLabel); shell.bot().button("OK").click(); bot.waitUntil(Conditions.shellCloses(shell)); } catch (Exception e) { if (shell != null && shell.isOpen()) shell.close(); SwtBotUtils.printError("Couldn't open perspective '" + perspectiveLabel + "'\n" + "trying to activate already open perspective instead"); // maybe somehow the perspective is already opened (by another test before us) SWTBotPerspective perspective = bot.perspectiveByLabel(perspectiveLabel); perspective.activate(); } SwtBotUtils.print("Opened Perspective: " + perspectiveLabel); }
private void closeWizard () { try { SWTBotShell shell = bot.shell("Generate a GraphWalker Offline Test"); Conditions.shellCloses(shell); } catch (Exception e) { } }
public GraphModelProperties getGraphmlProperties(String folder, String pkg, String filename) { SWTBotTreeItem pti = getProjectTreeItem(this.projectName); pti.expand(); SWTBotTreeItem fileItem = null; if (pkg == null) { fileItem = pti.expandNode(folder, filename); } else { fileItem = pti.expandNode(folder, pkg, filename); } bot.waitUntil(new isItemExpandedInTree(pti.getNode(folder))); fileItem.setFocus(); fileItem.select(); bot.waitUntil(new isItemSelectedInTree(fileItem)); fileItem.click(); bot.waitUntil(new isItemSelected(fileItem)); SWTBotMenu fileMenu = bot.menu("File"); fileMenu.menu("Properties").click(); bot.waitUntil(Conditions.shellIsActive("Properties for " + filename)); SWTBotShell shell = bot.shell("Properties for " + filename); GraphModelProperties gp = new GraphModelProperties(shell.bot(), this.projectName, folder, pkg, filename); return gp; }
public boolean convertTo(String project, String packageRootFragment, String pkg, String targetFilename, String targetFormat, String checkTestBox, String... nodes) { ConvertDialog cd = prepareConvertTo(project, packageRootFragment, pkg, targetFilename, targetFormat, nodes); boolean ret = cd.create(project, packageRootFragment, pkg, targetFilename, targetFormat, checkTestBox); if (!ret) { SWTBotShell shell = bot.shell("GW4E Conversion File"); shell.bot().button("Cancel").click(); bot.waitUntil(Conditions.shellCloses(shell)); return false; } return true; }
public boolean walkToToOfflinePage(String project, String packageRootFragment, String pkg, String targetFilename, String targetFormat, String checkTestBox, String... nodes) { ConvertDialog cd = prepareConvertTo(project, packageRootFragment, pkg, targetFilename, targetFormat, nodes); ICondition convertPageCompletedCondition = new DefaultCondition () { @Override public boolean test() throws Exception { boolean ret = cd.create(project, packageRootFragment, pkg, targetFilename, targetFormat, checkTestBox,false); if (!ret) { SWTBotShell shell = bot.shell("GW4E Conversion File"); shell.bot().button("Cancel").click(); bot.waitUntil(Conditions.shellCloses(shell)); return false; } return true; } @Override public String getFailureMessage() { return "Unable to complete the wizard page."; } }; bot.waitUntil(convertPageCompletedCondition); bot.button("Next >").click(); return true; }
public boolean prepareconvertTo(String project, String packageRootFragment, String pkg, String targetFilename, String targetFormat, String checkTestBox,String annotationStartElement, String targetvertex,String startElement,String [] contexts, String... nodes) { ConvertDialog cd = prepareConvertTo(project, packageRootFragment, pkg, targetFilename, targetFormat, nodes); boolean ret = cd.create(project, packageRootFragment, pkg, targetFilename, targetFormat, checkTestBox, false); if (!ret) { SWTBotShell shell = bot.shell("GW4E Conversion File"); shell.bot().button("Cancel").click(); bot.waitUntil(Conditions.shellCloses(shell)); return false; } SWTBotButton fbutton = bot.button("Next >"); fbutton.click(); GraphWalkerTestUIPageTest gwid = new GraphWalkerTestUIPageTest(cd.getShell()); gwid.completeFullPage("random(edge_coverage(100))", "GROUP1;GROUP2", annotationStartElement); gwid.nextPage(); JUnitGraphWalkerTestUIPageTest jugw = new JUnitGraphWalkerTestUIPageTest(cd.getShell()); jugw.completeFullPage(targetvertex, startElement, contexts); jugw.nextPage(); GraphWalkerTestHookPageTest gwth = new GraphWalkerTestHookPageTest(cd.getShell()); gwth.completeFullPage(); gwth.finish(); bot.waitUntil(Conditions.shellCloses(cd.getShell()), 6 * SWTBotPreferences.TIMEOUT); return true; }
@Override public boolean test() throws Exception { Matcher<Shell> matcher = WidgetMatcherFactory.withText(title); bot.waitUntil(Conditions.waitForShell(matcher)); SWTBotShell shell = bot.shell(title); return shell!=null; }
public boolean create (String project,String packageRootFragment, String pkg,String targetFilename,String targetFormat,String checkTestBox,boolean finish) { try { prepare (project,packageRootFragment,pkg,targetFilename,targetFormat, checkTestBox); if (!finish) return true; SWTBotButton fbutton = bot.button("Finish"); fbutton.click(); bot.waitUntil(Conditions.shellCloses(this.shell), 10 * SWTBotPreferences.TIMEOUT); return true; } catch (TimeoutException e) { return false; } }
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 static void importProjectFromZip(SWTWorkbenchBot bot, String path) { int timeout = 10000; bot.menu("File").menu("Import...").click(); bot.waitUntil(Conditions.shellIsActive("Import")); SWTBotShell shell = bot.shell("Import").activate(); shell.bot().tree().expandNode("General").select("Existing Projects into Workspace"); shell.bot().button("Next >").click(); shell.bot().radio("Select archive file:").click(); shell.bot().comboBox(1).setText(path); shell.bot().comboBox(1).pressShortcut(SWT.CR, SWT.LF); SWTBotButton finishButton = shell.bot().button("Finish"); ICondition buttonEnabled = new DefaultCondition() { @Override public boolean test() throws Exception { return finishButton.isEnabled(); } @Override public String getFailureMessage() { return "Finish button not enabled"; } }; shell.bot().waitUntil(buttonEnabled, timeout); finishButton.click(); bot.waitUntil(Conditions.shellCloses(shell), timeout); }
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); }
private SWTBotShell getPreferenceDialog() { Matcher<Shell> matcher = WidgetMatcherFactory.withText("Preferences"); bot.waitUntil(Conditions.waitForShell(matcher)); SWTBotShell shell = bot.shell("Preferences"); shell.activate(); return shell; }
public void refactorModelName (String newName,String [] nodes) { SWTBotTree tree = getProjectTree(); SWTBotTreeItem item = tree.expandNode(nodes); item.select(); item.setFocus(); SWTBotMenu menu = item.contextMenu("Refactor").contextMenu("Rename..."); menu.click(); bot.waitUntil(Conditions.shellIsActive("Rename Resource")); SWTBotShell shell = bot.shell("Rename Resource"); SWTBotText text = shell.bot().textWithLabel("New name:"); text.setText(newName); ICondition condition = new DefaultCondition () { @Override public boolean test() throws Exception { return shell.bot().button("OK").isEnabled(); } @Override public String getFailureMessage() { return "OK button not enabled"; } }; bot.waitUntil(condition); shell.bot().button("OK").click(); bot.waitUntil(Conditions.shellCloses(shell)); }
public void refactorRenameFolder (String [] nodes, String name) { SWTBotTree tree = getProjectTree(); SWTBotTreeItem item = tree.expandNode(nodes); item.select(); item.setFocus(); SWTBotMenu menu = item.contextMenu("Refactor").contextMenu("Rename..."); menu.click(); bot.waitUntil(Conditions.shellIsActive("Rename Package")); SWTBotShell shell = bot.shell("Rename Package"); SWTBotText text = shell.bot().textWithLabel("New name:"); text.setText(name); ICondition condition = new DefaultCondition () { @Override public boolean test() throws Exception { return shell.bot().button("OK").isEnabled(); } @Override public String getFailureMessage() { return "OK button not enabled"; } }; bot.waitUntil(condition); shell.bot().button("OK").click(); bot.waitUntil(Conditions.shellCloses(shell), 30 * 1000); }
public void refactorMoveModel (String [] nodes,String [] destination, String name) { SWTBotTree tree = getProjectTree(); SWTBotTreeItem item = tree.expandNode(nodes); item.select(); item.setFocus(); SWTBotMenu menu = item.contextMenu("Refactor").contextMenu("Move..."); menu.click(); bot.waitUntil(Conditions.shellIsActive("Move")); SWTBotShell shell = bot.shell("Move"); SWTBotTree packageTree = shell.bot().treeWithLabel("Choose destination for '"+ name + "':"); SWTBotTreeItem target = packageTree.expandNode(destination); target.select(); target.setFocus(); ICondition condition = new DefaultCondition () { @Override public boolean test() throws Exception { return shell.bot().button("OK").isEnabled(); } @Override public String getFailureMessage() { return "OK button not enabled"; } }; bot.waitUntil(condition); shell.bot().button("OK").click(); bot.waitUntil(Conditions.shellCloses(shell)); }
protected SWTBotShell openRun () { ICondition condition = new DefaultCondition () { @Override public boolean test() throws Exception { try { bot.menu("Run").menu("Run Configurations...").click(); return true; } catch (Exception e) { return false; } } @Override public String getFailureMessage() { return "Unable to find the 'Run -> Run Configurations...' menu"; } }; bot.waitUntil(condition, RUN_TIMEOUT); bot.waitUntil(Conditions.shellIsActive("Run Configurations")); SWTBotShell shell = bot.shell("Run Configurations"); SWTBotTreeItem item = shell.bot().tree().getTreeItem(getLauncherName()).select(); item.select(); return shell; }
private SWTBotView waitForConsoleBeDisplayed () { getConsoleView(bot); Matcher<Widget> console = getConsoleMatcher () ; bot.waitUntil(Conditions.waitForWidget(console)); SWTBotView consoleView = getConsoleView(bot); consoleView.setFocus(); return consoleView; }
@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; }
/** * Waits until the grammar field combo box is enabled. * * @param wizard * the wizard */ public static void waitForGrammarFieldEnabled(final SwtWizardBot wizard) { boolean wizardIsActive = syncExec(new BoolResult() { @Override public Boolean run() { SWTBotShell wizardShell = wizard.activeShell(); return wizardShell.widget.getData() instanceof WizardDialog; } }); assertTrue("Wizard is active before waiting on grammar field", wizardIsActive); wizard.waitUntil(Conditions.widgetIsEnabled(wizard.comboBoxWithLabel(Messages.GRAMMAR_FIELD_NAME_LABEL)), 2 * SwtWizardBot.SWTBOT_TIMEOUT); }
protected <T extends Widget> List<T> widget(final Matcher<T> matcher) { WaitForObjectCondition<T> waiWidget = Conditions.waitForWidget(matcher); bot.waitUntilWidgetAppears(waiWidget); return waiWidget.getAllMatches(); }
public void executeQuickFixForErrorMessage(String expectedErrorMessageInProblemView, String quickfixmessage, ICondition[] conditions) throws CoreException { print (); bot.waitUntil(new ErrorIsInProblemView(this, expectedErrorMessageInProblemView)); SWTBotTreeItem item = findErrorItemWithText(expectedErrorMessageInProblemView); item.setFocus(); item.click(); bot.waitUntil(new IsItemSelectedInErrors(this, item)); ICondition condition = new DefaultCondition () { @Override public boolean test() throws Exception { item.contextMenu().menu("Quick Fix").click(); try { bot.waitUntil(Conditions.shellIsActive("Quick Fix"), 2 * 1000 ); } catch (Exception e) { return false; } return true; } @Override public String getFailureMessage() { return "Unable to open the Quick fix"; } }; bot.waitUntil(condition, 15 * 1000); SWTBotShell shell = bot.shell("Quick Fix"); SWTBotTable table = shell.bot().tableWithLabel("Select a fix:"); SWTBotTableItem thequickFixItem = table.getTableItem(quickfixmessage); thequickFixItem.click(); thequickFixItem.select(); SWTBotButton button = shell.bot().button("Finish"); button.click(); bot.waitUntil(Conditions.shellCloses(shell),TIMEOUT); bot.saveAllEditors(); GW4EProject.fullBuild(); if (conditions != null) { for (int i = 0; i < conditions.length; i++) { bot.waitUntil(conditions[i], TIMEOUT); } } }
private void cancelGW4EPreference (String title) { SWTBotButton cancelButton = bot.button("Cancel"); cancelButton.click(); bot.waitWhile(Conditions.shellIsActive(title)); }
private void showGW4EPreference(SWTBotShell shell) { bot.tree().select("GW4E Preferences"); Matcher<Shell> matcher = WidgetMatcherFactory.withId("id", PreferenceManager.AUTHORIZED_FOLDERS_FOR_GRAPH_DEFINITION); bot.waitUntil(Conditions.waitForWidget(matcher, shell.widget)); }
public void createPackage (String [] nodes,String [] parent, String name , String pkg) { SWTBotTree tree = getProjectTree(); SWTBotTreeItem item = tree.expandNode(nodes); item.select(); item.setFocus(); SWTBotMenu menu = item.contextMenu("Refactor").contextMenu("Move..."); menu.click(); bot.waitUntil(Conditions.shellIsActive("Move")); SWTBotShell shell = bot.shell("Move"); SWTBotTree packageTree = shell.bot().treeWithLabel("Choose destination for '"+ name + "':"); SWTBotTreeItem target = packageTree.expandNode(parent); target.select(); target.setFocus(); shell.bot().button("Create Package...").click(); bot.waitUntil(Conditions.shellIsActive("New Java Package")); SWTBotShell shellNewPackage = bot.shell("New Java Package"); SWTBotText text = shellNewPackage.bot().textWithLabel("Name:"); text.setText(pkg); ICondition condition = new DefaultCondition () { @Override public boolean test() throws Exception { return shellNewPackage.bot().button("Finish").isEnabled(); } @Override public String getFailureMessage() { return "Finish button not enabled"; } }; bot.waitUntil(condition); shellNewPackage.bot().button("Finish").click(); bot.waitUntil(Conditions.shellCloses(shellNewPackage)); shell.bot().button("Cancel").click(); }
public void run (String configurationName, long timeout) { SWTBotShell shell = openExistingRun (configurationName); SWTBotButton runButton = shell.bot().button("Run"); runButton.click(); bot.waitUntil(Conditions.shellCloses(shell)); waitForConsoleBeDisplayed(); waitForRunCompleted (configurationName,timeout); }
/** * Opens the preference dialog and unfolds the tree to the given path. * * @param bot * the workbench bot which opens the dialog, must not be {@code null}. * @param preferencePath * the path to the preference one wants to open, must not be {@code null} or empty. */ public static void openPreferenceDialog(final SWTWorkbenchBot bot, final String... preferencePath) { bot.activeView(); bot.menu("Window").menu(SHELL_PREFERENCES).click(); bot.waitUntil(Conditions.shellIsActive(SHELL_PREFERENCES)); CoreSwtbotTools.expandNode(bot.tree(0), preferencePath).select(); }
@Test public void canCreateNewModelFile() throws Exception { createTestProject(); SWTBotShell shell = createNewOrmModelFileWizard(ORM_WIZARD_CATEGORY, MY_TEST_PROJECT, "Orm Model", "My.orm"); bot.waitUntil(Conditions.shellCloses(shell)); }
/** * Closes the preference dialog. * * @param bot * the workbench bot which closes the dialog, must not be {@code null}. */ public static void closePreferenceDialog(final SWTWorkbenchBot bot) { bot.shell(SHELL_PREFERENCES).activate(); bot.waitUntil(Conditions.shellIsActive(SHELL_PREFERENCES)); bot.button("OK").click(); }