@Test public void testOfflineAppendMode() throws Exception { GW4EProject project = new GW4EProject(bot, gwproject); FileParameters fp = project.createSimpleProject (); fp.setTargetFilename("SimpleOffLineImpl"); OfflineTestUIPageTest page = walkToToOfflinePage(gwproject,fp); page.selectAppendMode("com.company.SimpleImpl.java - gwproject/src/main/java"); page.selectGenerators(new String [] {"random(edge_coverage(100))"}); page.finish(); ICondition condition = new DefaultCondition () { @Override public boolean test() throws Exception { IFile resource = (IFile) ResourceManager.getResource("gwproject/src/main/java/com/company/SimpleImpl.java"); boolean methodAppended = IOHelper.findInFile(resource, "Generated with : random(edge_coverage(100))"); return methodAppended; } @Override public String getFailureMessage() { return "method not generated "; } }; bot.waitUntil(condition, 3 * 6 * SWTBotPreferences.TIMEOUT); //3mn closeWizard (); }
@Test public void testOfflineStandAloneMode() throws Exception { GW4EProject project = new GW4EProject(bot, gwproject); FileParameters fp = project.createSimpleProject (); fp.setTargetFilename("SimpleOffLineImpl"); OfflineTestUIPageTest page = walkToToOfflinePage(gwproject,fp); page.selectStandAloneMode("MyClazz"); page.selectGenerators(new String [] {"random(edge_coverage(100))"}); page.finish(); ICondition condition = new DefaultCondition () { @Override public boolean test() throws Exception { IFile resource = (IFile) ResourceManager.getResource("gwproject/src/main/java/com/company/MyClazz.java"); boolean methodAppended = IOHelper.findInFile(resource, "Generated with : random(edge_coverage(100))"); return methodAppended; } @Override public String getFailureMessage() { return "method not generated "; } }; bot.waitUntil(condition, 3 * 6 * SWTBotPreferences.TIMEOUT); //3mn closeWizard (); }
private OfflineTestUIPageTest walkToToOfflinePage(String gwproject,FileParameters fp) throws CoreException, FileNotFoundException, BuildPolicyConfigurationException { String targetFormat="offline"; String checkTestBox="Java Offline Test Based"; GW4EProject project = new GW4EProject(bot, gwproject); ICondition convertPageReachedCondition = new DefaultCondition () { @Override public boolean test() throws Exception { boolean b = project.walkToToOfflinePage(fp.getProject(),fp.getPackageFragmentRoot(),fp.getPackage(), fp.getTargetFilename(), targetFormat,checkTestBox,fp.getGraphmlFilePath()); return b; } @Override public String getFailureMessage() { return "Unable to complete the wizard page."; } }; bot.waitUntil(convertPageReachedCondition, 3 * SWTBotPreferences.TIMEOUT); SWTBotShell shell = bot.shell("GW4E Conversion File"); return new OfflineTestUIPageTest(shell); }
public void convertToExisting(String project, String packageRootFragment, String pkg, String targetFilename, String targetFormat, String checkTestBox, String... nodes) { ICondition condition = new DefaultCondition() { @Override public boolean test() throws Exception { ConvertDialog cd = prepareConvertTo(project, packageRootFragment, pkg, targetFilename, targetFormat, nodes); boolean b = cd.createExisting(project, packageRootFragment, pkg, targetFilename, targetFormat, checkTestBox); return b; } @Override public String getFailureMessage() { return "Unable to complete the convert to wizard"; } }; bot.waitUntil(condition, 3 * SWTBotPreferences.TIMEOUT); }
/** * Sets common SWTBot preferences. */ public static void initializePreferences() { // -Dorg.eclipse.swtbot.playback.delay=2 SWTBotPreferences.PLAYBACK_DELAY = BOT_PLAYBACK_DELAY; // System.setProperty("org.eclipse.swtbot.keyboardLayout", "EN_US"); SWTBotPreferences.KEYBOARD_LAYOUT = "org.eclipse.swtbot.swt.finder.keyboard.EN_US"; // SWTBot Keyboard strategies SWTBotPreferences.KEYBOARD_STRATEGY = "org.eclipse.swtbot.swt.finder.keyboard.SWTKeyboardStrategy"; // keyboard type interval SWTBotPreferences.TYPE_INTERVAL = KEYBOARD_TYPE_INTERVAL; // Waiting for Widgets SWTBotPreferences.TIMEOUT = BOT_WIDGET_TIMEOUT; // screenshot directory SWTBotPreferences.SCREENSHOTS_DIR = System.getProperty(SWTBotPreferenceConstants.KEY_SCREENSHOTS_DIR, "target/screenshots"); // test window focus policy workbenchFocusPolicy = WorkbenchFocusPolicy.valueOf(System.getProperty(PROPERTY_COM_AVALOQ_TEST_WORKBENCHFOCUSPOLICY, WorkbenchFocusPolicy.REFOCUS.toString())); preferencesInitialized = true; }
/** * Tests com.avaloq.test.swtbot.DE_CH. */ @Test public void testDeChKeyboardLayout() { SWTBotPreferences.KEYBOARD_LAYOUT = "com.avaloq.test.swtbot.DE_CH"; SWTBotPreferences.KEYBOARD_STRATEGY = "org.eclipse.swtbot.swt.finder.keyboard.MockKeyboardStrategy"; SwtWorkbenchBot bot = new SwtWorkbenchBot(); bot.closeWelcomePage(); bot.menu("File").menu("New").menu("Untitled Text File").click(); SWTBotEclipseEditor editor = bot.activeEditor().toTextEditor(); editor.setFocus(); editor.typeText(EXPECTED_RESULT); String actualResult = editor.getText(); bot.closeAllEditors(); assertEquals("Written and read characters must exactly match", EXPECTED_RESULT, actualResult); }
/** * 每个测试开始之前执行 */ @Before public void setUp() { if (SLOW_PLAYBACK) { SWTBotPreferences.PLAYBACK_DELAY = 500; } SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US"; INVISIBLE_CHAR = XlfEditor.INVISIBLE_CHAR; reTag = "(" + INVISIBLE_CHAR + "\\d+)?" + INVISIBLE_CHAR + "(x|bx|ex|g|bpt|ept|mrk|sub|ph|it)" + INVISIBLE_CHAR + "(\\d+" + INVISIBLE_CHAR + ")?"; bot = HSBot.bot(); bot.closeAllEditors(); ts = TS.getInstance(); prjName = "swtBot-Project-001"; fileName = "HSCAT8-3.xlf"; ProjectTreeView.doubleClickXlfFile(prjName, fileName); xe = new XlfEditor(bot.editorByTitle(fileName)); }
@BeforeClass public static void closeWelcomePage() { try { SWTBotPreferences.TIMEOUT = 6000; new SWTGefBot().viewByTitle("Welcome").close(); } catch (Exception e) { e.printStackTrace(); } }
@BeforeClass public static void closeWelcomePage() { try { SWTBotPreferences.TIMEOUT = 6000; } catch (Exception e) { e.printStackTrace(); } }
@Test public void testOfflineExpandedMode() throws CoreException, BuildPolicyConfigurationException, IOException, InterruptedException { GW4EProject project = new GW4EProject(bot, gwproject); FileParameters fp = project.createSimpleProject (); fp.setTargetFilename("SimpleOffLineImpl"); OfflineTestUIPageTest page = walkToToOfflinePage(gwproject,fp); page.selectExtendedMode("com.company.SimpleImpl.java - gwproject/src/main/java","MyClazz"); page.selectGenerators(new String [] {"random(edge_coverage(100))"}); page.finish(); ICondition condition = new DefaultCondition () { @Override public boolean test() throws Exception { IFile resource = (IFile) ResourceManager.getResource("gwproject/src/main/java/com/company/MyClazz.java"); boolean methodAppended = IOHelper.findInFile(resource, "Generated with : random(edge_coverage(100))"); return methodAppended; } @Override public String getFailureMessage() { return "method not generated "; } }; bot.waitUntil(condition, 3 * 6 * SWTBotPreferences.TIMEOUT); //3mn closeWizard (); }
private void testConvertTo(String targetFormat,String checkTestBox) throws CoreException, FileNotFoundException, BuildPolicyConfigurationException { GW4EProject project = new GW4EProject(bot, gwproject); project.createInitialProjectWithoutError(TEST_RESOURCE_FOLDER, PACKAGE_NAME, graphMLFilename); FileParameters fp = FileParameters.create(targetFormat); IFolder folder = ResourceManager.createFolder(fp.getMainSourceFolder(), PACKAGE_NAME); ICondition folderExistsCondition = new FolderExists (folder); bot.waitUntil(folderExistsCondition, SWTBotPreferences.TIMEOUT); ICondition convertPageCompletedCondition = new DefaultCondition () { @Override public boolean test() throws Exception { boolean b = project.convertTo(fp.getProject(),fp.getPackageFragmentRoot(),fp.getPackage(), fp.getTargetFilename(), targetFormat,checkTestBox,fp.getGraphmlFilePath()); return b; } @Override public String getFailureMessage() { return "Unable to complete the wizard page."; } }; bot.waitUntil(convertPageCompletedCondition, 3 * SWTBotPreferences.TIMEOUT); IProject pj = ResourceManager.getProject(fp.getProject()); bot.waitUntil(new PathFoundCondition(pj,fp.getPath()),30 * 1000); }
@BeforeClass public static void beforeClass() throws Exception { SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US"; SWTBotPreferences.TIMEOUT = 10000; bot = new SWTWorkbenchBot(); try { bot.viewByTitle("Welcome").close(); } catch (Exception e) { e.printStackTrace(); } }
@Before public void setUp() throws CoreException { long timeout = SWTBotPreferences.TIMEOUT; try { SWTBotPreferences.TIMEOUT = 3 * 60 * 1000; bot.resetWorkbench(); GW4EProject.cleanWorkspace(); GW4EPerspective.openGWPerspective(bot); } finally { SWTBotPreferences.TIMEOUT = timeout; } }
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; }
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; } }
/** * Click the given button as soon as it is enabled. * * @param button * the {@link SWTBotButton} to be clicked * @param timeout * the timeout to wait for. When timeout is reached, a WrappedException is thrown. */ public void clickButton(final SWTBotButton button, final long timeout) { final long endTimeMillis = System.currentTimeMillis() + timeout; while (!button.isEnabled() && System.currentTimeMillis() < endTimeMillis) { sleep(SWTBotPreferences.DEFAULT_POLL_DELAY); } if (button.isEnabled()) { new SwtBotButton(button).click(); } else { throw new WrappedException(NLS.bind(TIMEOUT_MSG, timeout, button.getText()), null); } }
/** * 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); }
/** * Shows the provided {@link Menu} and returns the {@link MenuItem} matching the given {@link Matcher} criteria. * * @param menu * the {@link Menu} to show * @param matcher * the {@link Matcher} to use to find the {@link MenuItem} * @return * the {@link MenuItem} matching the given {@link Matcher} criteria */ private static MenuItem show(final Menu menu, final Matcher<?> matcher) { if (menu != null) { menu.notifyListeners(SWT.Show, new Event()); MenuItem item = null; final long start = System.currentTimeMillis(); while ((item = getMenuItem(menu, matcher)) != null) { if (ICE_CTX_LABEL_LOADING.equals(item.getText())) { try { while (Display.getDefault().readAndDispatch()) { // Allow Lazy Loading items to modify the menu } Thread.sleep(SWTBotPreferences.PLAYBACK_DELAY); } catch (InterruptedException exception) { Thread.currentThread().interrupt(); } } else { return item; } if (System.currentTimeMillis() - start > SWTBotPreferences.TIMEOUT) { return null; } } menu.notifyListeners(SWT.Hide, new Event()); return item; } return null; }
/** * Initialize the bot's preferences. */ public static void initializeBotPreferences() { // NOTE: the keyboard layout must match the keyboard used for the OS. // The default keyboard layouts are: EN_US, MAC_EN_US, EN_GB, MAC_EN_GB, FR_FR, DE_DE. // TF-69: "com.avaloq.test.swtbot.DE_CH" is a custom keyboard layout, saved in the package "com.avaloq.test.swtbot" SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US"; SWTBotPreferences.KEYBOARD_STRATEGY = System.getProperty("org.eclipse.swtbot.keyboard.strategy", "org.eclipse.swtbot.swt.finder.keyboard.SWTKeyboardStrategy"); SWTBotPreferences.PLAYBACK_DELAY = PLAYBACK_DELAY; SWTBotPreferences.TIMEOUT = TIMEOUT; }
/** * Adds a new spec to the toolbox, opens it and tests if parsing is done on * a non-UI thread * * @see Bug #103 in general/bugzilla/index.html */ @Test public void parseSpecInNonUIThread() { // Open specA SWTBotMenu fileMenu = bot.menu("File"); SWTBotMenu openSpecMenu = fileMenu.menu("Open Spec"); SWTBotMenu addNewSpecMenu = openSpecMenu.menu("Add New Spec..."); addNewSpecMenu.click(); bot.textWithLabel("Root-module file:").setText(specB); bot.button("Finish").click(); assertNoBackendCodeInUIThread(); // Open specB addNewSpecMenu.click(); bot.textWithLabel("Root-module file:").setText(specA); bot.button("Finish").click(); assertNoBackendCodeInUIThread(); final String specName = getSpecName(new File(specB)); // increase timeout since farsite spec takes a long time to parse final long timeout = SWTBotPreferences.TIMEOUT * 4; // specs are created in non-UI thread asynchronously which causes a // delay before the menu entry becomes available bot.waitUntil(Conditions.waitForMenu(waitForToolboxShell(), WithText.<MenuItem> withText(specName)), timeout); // Go back to previous spec openSpecMenu.menu(specName); assertNoBackendCodeInUIThread(); }
/** * 每个测试开始之前执行 */ @Before public void setUp() { // SWTBotPreferences.PLAYBACK_DELAY = 500; SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US"; INVISIBLE_CHAR = XlfEditor.INVISIBLE_CHAR; reTag = "(" + INVISIBLE_CHAR + "\\d+)?" + INVISIBLE_CHAR + "(x|bx|ex|g|bpt|ept|mrk|sub|ph|it)" + INVISIBLE_CHAR + "(\\d+" + INVISIBLE_CHAR + ")?"; bot = HSBot.bot(); bot.closeAllEditors(); ts = TS.getInstance(); prjName = "prjBot-001"; fileName = "HSCAT8-2T.xlf"; ProjectTreeView.doubleClickXlfFile(prjName, fileName); xe = new XlfEditor(bot.editorByTitle(fileName)); }
@BeforeClass public static void startTest() { if (DEBUG_MODE == 2) { SWTBotPreferences.PLAYBACK_DELAY = 500; } SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US"; bot = HSBot.bot(); }
public EditorConfigTestContext(final SWTWorkbenchBot bot, final String projectName) { this.bot = bot; this.projectName = projectName; closeWelcomePageIfPresent(); createJavaProjectIfNotExists(projectName); configureEditors(); SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US"; }
protected ESPrimaryVersionSpec updateCopy() { SWTBotPreferences.PLAYBACK_DELAY = 100; didUpdate = false; final ESUpdateObserver updateObserver = createUpdateObserver(); ESWorkspaceProviderImpl.getInstance(); ESWorkspaceProviderImpl.getObserverBus().register(updateObserver); UIThreadRunnable.asyncExec(new VoidResult() { public void run() { final UIUpdateProjectController updateProjectController = new UIUpdateProjectController( bot.getDisplay().getActiveShell(), getCopy()); updateProjectController.execute(); } }); final Matcher<Shell> matcher = withText("Update"); bot.waitUntil(waitForShell(matcher)); bot.button("OK").click(); bot.waitUntil(new DefaultCondition() { // BEGIN SUPRESS CATCH EXCEPTION public boolean test() throws Exception { return didUpdate; } // END SUPRESS CATCH EXCEPTION public String getFailureMessage() { return "Update did not succeed."; } }, timeout()); ESWorkspaceProviderImpl.getInstance(); ESWorkspaceProviderImpl.getObserverBus().unregister(updateObserver); return getCopy().getBaseVersion(); }
/** * Use the Properties file to set Preferences: KEYBOARD_STRATEGY, * KEYBOARD_LAYOUT, TIMEOUT * * @return isSWTBotPreferencesSet */ public static boolean setSWTBotPreferences() { SWTBotPreferences.KEYBOARD_STRATEGY = Properties.KEYBOARD_STRATEGY_ORG_ECLIPSE_SWTBOT_SWT_FINDER_KEYBOARD_SWT_KEYBOARD_STRATEGY; SWTBotPreferences.KEYBOARD_LAYOUT = Properties.KEYBOARD_LAYOUT_EN_US; SWTBotPreferences.TIMEOUT = Properties.TIME_OUT; return true; }
@Test public void testOfflineStandAloneModeWithTimeout() throws Exception { boolean[] result = new boolean [] {false}; ILogListener listener = new ILogListener() { @Override public void logging(IStatus status, String plugin) { if (status.getMessage().indexOf("Operation cancelled either manually or a timeout occured.")!=-1) { result[0] = true; } } }; GW4EProject project = new GW4EProject(bot, gwproject); project.createSimpleProjectWithoutGeneration (); IFile buildPolicyFile = (IFile) ResourceManager.getResource("gwproject/src/main/resources/com/company/build.policies"); BuildPolicyManager.setPolicies(buildPolicyFile, "Simple.json", "random(never);I", new NullProgressMonitor ()); buildPolicyFile.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor ()); FileParameters fp = project.generateForSimpleProject (); fp.setTargetFilename("SimpleOffLineImpl"); OfflineTestUIPageTest page = walkToToOfflinePage(gwproject,fp); page.selectTimeout("1"); page.selectStandAloneMode("MyClazz"); page.selectGenerators(new String [] {"random(never)"}); try { ErrorDialog.AUTOMATED_MODE = true; ResourceManager.addLogListener(listener); page.finish(); ICondition condition = new DefaultCondition () { @Override public boolean test() throws Exception { return result[0]; } @Override public String getFailureMessage() { return "Operation not cancelled"; } }; bot.waitUntil(condition,3 * 6 * SWTBotPreferences.TIMEOUT); //3mn } finally { ErrorDialog.AUTOMATED_MODE = false; ResourceManager.removeLogListener(listener); } closeWizard (); }
@Test public void testConvertToExistingTestBasedJava( ) throws CoreException, IOException, BuildPolicyConfigurationException { long start = System.currentTimeMillis(); String targetFormat = "test"; String checkFormatText = "Java Test Based"; testPrepareConvertTo(targetFormat,checkFormatText); FileParameters fp = FileParameters.create(targetFormat); String spath = PreferenceManager.getTargetFolderForTestInterface(fp.getProject(),true); IPath path = ResourceManager.getProject(gwproject).getFullPath().append(spath); File cacheFile = new File (ResourceManager.toFile(path),"cache.json"); assertTrue("Cache '" + cacheFile.getAbsolutePath() + "' does not exist ", cacheFile.exists()); String key = fp.getGraphFile().getAbsolutePath(); assertFileInCache (cacheFile,key); assertFileGenerationTime (cacheFile,key,start, System.currentTimeMillis()); // Graph file has not been modified, Generation should not happen... long before = readModifedTimeInCacheForFile (cacheFile,key); GW4EProject project = new GW4EProject(bot, gwproject); String [] contexts = new String [0]; ICondition convertPageCompletedCondition = new DefaultCondition () { @Override public boolean test() throws Exception { boolean b = project.prepareconvertTo( fp.getProject(), fp.getPackageFragmentRoot(), fp.getPackage(), fp.getTargetFilename(), targetFormat, checkFormatText, "e_StartBrowser","v_ShoppingCart", "e_ShoppingCart",contexts, fp.getGraphmlFilePath()); return b; } @Override public String getFailureMessage() { return "Unable to complete the wizard page."; } }; bot.waitUntil(convertPageCompletedCondition,3 * SWTBotPreferences.TIMEOUT); long after = readModifedTimeInCacheForFile (cacheFile,key); assertTrue("Files have been modified. It should not", before==after); // Simulate the graph has been updated fp.getGraphFile().setLastModified(System.currentTimeMillis()); start = System.currentTimeMillis(); project.prepareconvertTo( fp.getProject(), fp.getPackageFragmentRoot(), fp.getPackage(), fp.getTargetFilename(), targetFormat, checkFormatText, "e_StartBrowser","v_ShoppingCart", "e_ShoppingCart",contexts, fp.getGraphmlFilePath()); long after2 = readModifedTimeInCacheForFile (cacheFile,key); assertTrue("Files have not been modified. It should. ", after2!=after); }
private static long getSwtBotPrefsTimeoutFieldValue() { return SWTBotPreferences.TIMEOUT; }
private static void setSwtBotPrefsTimeoutFieldValue(long timeout) { if (timeout == UNSET_TIMEOUT_VALUE) { return; } SWTBotPreferences.TIMEOUT = timeout; }
/** * Wait until the tree item contains the given text with the * timeout {@link SWTBotPreferences#TIMEOUT}. */ public static void waitUntilTreeContainsText(SWTWorkbenchBot bot, final SWTBotTreeItem treeItem, final String text) { waitUntilTreeContainsText(bot, treeItem, text, SWTBotPreferences.TIMEOUT); }
@Test public void testNewModel() { // Open specA SWTBotMenu fileMenu = bot.menu("File"); SWTBotMenu openSpecMenu = fileMenu.menu("Open Spec"); SWTBotMenu addNewSpecMenu = openSpecMenu.menu("Add New Spec..."); addNewSpecMenu.click(); bot.textWithLabel("Root-module file:").setText(specA); bot.button("Finish").click(); final String specName = getSpecName(new File(specA)); // specs are created in non-UI thread asynchronously which causes a // delay before the menu entry becomes available bot.waitUntil(Conditions.waitForMenu(bot.activeShell(), WithText.<MenuItem> withText(specName))); // create a new model final SWTBotMenu modelMenu = bot.menu("TLC Model Checker"); final SWTBotMenu newModelMenu = modelMenu.menu("New Model..."); newModelMenu.click(); bot.button("OK").click(); // wait for model editor to show up and parse bot.waitUntil(new ModelEditorOpenCondition("Model_")); // register job listener who listens for the model checker job final String modelName = UIHelper.getActiveEditor().getTitle(); final Model model = ToolboxHandle.getCurrentSpec().getAdapter(TLCSpec.class).getModel(modelName); final IJobChangeListener listener = new DummyJobChangeListener(model); Job.getJobManager().addJobChangeListener(listener); // start model checking by clicking the menu. This is more robust // compared to the f11 keystroke which can get lost when fired during // initialization of the model editor. bot.menu("TLC Model Checker").menu("Run model").click(); // make unit test wait for model checker job to finish bot.waitUntil((ICondition) listener, SWTBotPreferences.TIMEOUT * 3); // Do some unregistration prior to model deletion: Job.getJobManager().removeJobChangeListener(listener); // close corresponding editor if open final IEditorPart editorWithModelOpened = model.getAdapter(ModelEditor.class); if (editorWithModelOpened != null) { UIHelper.runUISync(new Runnable() { public void run() { UIHelper.getActivePage().closeEditor(editorWithModelOpened, false); } }); } // Delete the newly created model again. It does not use the UI because // SWTBot cannot handle the modal confirmation dialog do delete the // model. // Deleting the model is necessary because repeated test execution would // leave huge numbers of model leftovers contributing to slowed down test // execution (see SizeControlContribution for reason why). try { model.delete(new NullProgressMonitor()); } catch (CoreException e) { e.printStackTrace(); } }
/** * @see Bug #58 in general/bugzilla/index.html */ @Test public void renameSpec() throws InterruptedException { openSpecExplorer(); SWTBotTreeItem treeItem = bot.tree().getTreeItem(TEST_SPEC + " [ " + TEST_SPEC + TLA_SUFFIX + " ]"); checkForModelExistenceUI(treeItem); SWTBotMenu contextMenu = treeItem.contextMenu("Rename"); contextMenu.click(); // rename to ..._Copy bot.button("OK").click(); // wait for rename to be done bot.waitUntil(new SpecEditorOpenCondition(TEST_SPEC)); // verify (via API) checkSpecAndModelExistenceAPI(TEST_SPEC + "_Copy"); // try to find the renamed file (via UI) openSpecExplorer(); treeItem = bot.tree().getTreeItem(TEST_SPEC + "_Copy [ " + TEST_SPEC + TLA_SUFFIX + " ]"); /* * try to launch the model */ SWTBotTreeItem modelTreeItem = checkForModelExistenceUI(treeItem); modelTreeItem.contextMenu("Open").click(); Assert.assertNotNull("UI tree item (model) could not be found", modelTreeItem); // register job listener who listens for the model checker job final String modelName = UIHelper.getActiveEditor().getTitle(); final Model model = ToolboxHandle.getCurrentSpec().getAdapter(TLCSpec.class).getModel(modelName); final IJobChangeListener listener = new DummyJobChangeListener(model); Job.getJobManager().addJobChangeListener(listener); // start model checking by clicking the menu. This is more robust // compared to the f11 keystroke which can get lost when fired during // initialization of the model editor. bot.menu("TLC Model Checker").menu("Run model").click(); // make unit test wait for model checker job to finish bot.waitUntil((ICondition) listener, SWTBotPreferences.TIMEOUT * 3); // Do some unregistration prior to model deletion: Job.getJobManager().removeJobChangeListener(listener); // close corresponding editor if open final IEditorPart editorWithModelOpened = model.getAdapter(ModelEditor.class); if (editorWithModelOpened != null) { UIHelper.runUISync(new Runnable() { public void run() { UIHelper.getActivePage().closeEditor(editorWithModelOpened, false); } }); } }
@BeforeClass public static void beforeClass() throws Exception { bot = new SWTWorkbenchBot(); realFactory = VizServiceFactoryHolder.getFactory(); factoryHolder = new VizServiceFactoryHolder(); // Set the bot's timeout and playback rate SWTBotPreferences.TIMEOUT = 3000; SWTBotPreferences.PLAYBACK_DELAY = 250; // Set up the workspace IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); // The OS's file path separator String separator = System.getProperty("file.separator"); String projectName = "CSVVizService"; java.net.URI defaultProjectLocation = null; // Setup the project try { // Get the project handle IProject project = workspaceRoot.getProject(projectName); // If the project does not exist, create it if (!project.exists()) { // Set the location as // ${workspace_loc}/CAEBATModelTesterWorkspace defaultProjectLocation = (new File( System.getProperty("user.home") + separator + "ICETests" + separator + projectName)).toURI(); // Create the project description IProjectDescription desc = ResourcesPlugin.getWorkspace() .newProjectDescription(projectName); // Set the location of the project desc.setLocationURI(defaultProjectLocation); // Create the project project.create(desc, null); } // Open the project if it is not already open if (project.exists() && !project.isOpen()) { project.open(null); } // Refresh the workspace project.refreshLocal(IResource.DEPTH_INFINITE, null); } catch (CoreException e) { // Catch exception for creating the project e.printStackTrace(); fail(); } }
@BeforeClass public static void setupBot() { bot = new SWTWorkbenchBot(); SWTBotPreferences.KEYBOARD_LAYOUT = EN_US; closeWelcomeView(); }
@Before public void setUp() { // SWTBotPreferences.PLAYBACK_DELAY = 500; SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US"; bot = new HsSWTWorkbenchBot(); }
protected ESPrimaryVersionSpec updateToVersion() { SWTBotPreferences.PLAYBACK_DELAY = 100; didUpdate = false; final ESUpdateObserver updateObserver = createUpdateObserver(); ESWorkspaceProviderImpl.getInstance(); ESWorkspaceProviderImpl.getObserverBus().register(updateObserver); UIThreadRunnable.asyncExec(new VoidResult() { public void run() { final UIUpdateProjectToVersionController updateProjectController = new UIUpdateProjectToVersionController( bot.getDisplay().getActiveShell(), getCopy()); updateProjectController.execute(); } }); Matcher<Shell> matcher = withText("Select a Version to update to"); bot.waitUntil(waitForShell(matcher)); bot.button("OK").click(); matcher = withText("Update"); bot.waitUntil(waitForShell(matcher)); bot.button("OK").click(); bot.waitUntil(new DefaultCondition() { // BEGIN SUPRESS CATCH EXCEPTION public boolean test() throws Exception { return didUpdate; } // END SUPRESS CATCH EXCEPTION public String getFailureMessage() { return "Update to version did not succeed."; } }, 600000); ESWorkspaceProviderImpl.getInstance(); ESWorkspaceProviderImpl.getObserverBus().unregister(updateObserver); return getCopy().getBaseVersion(); }