public SWTBotGefEditPart addForEach( SWTBotGefEditPart toPart, String name, String startExpression, String finalExpression) throws Exception { appendActivity(toPart, "ForEach", name); SWTBot propsBot = propsView.bot(); propsView.selectTab(2); SWTBotButton leftButton = propsBot.button(0); SWTBotButton rightButton = propsBot.button(1); leftButton.click(); rightButton.click(); propsBot.styledText(0).setText(startExpression); // Previous change must be saved otherwise we will see an ugly NPE. // This issue seems to be caused by SWTBot since the exception cannot // be seen by clicking the steps manually. save(); propsBot.styledText(1).setText(finalExpression); save(); // TODO: maybe delete the scope element SWTBotGefEditPart added = getEditPart(toPart, name); log.info("Added [part=" + added + ", name=" + name + "]"); return added; }
public SWTBotGefEditPart addPickOnMessage( SWTBotGefEditPart pickPart, String in, String[] operationInfo) { setFocus(pickPart); gEditor.clickContextMenu("Add OnMessage"); save(); // get the new ElseIfPart List<SWTBotGefEditPart> children = pickPart.children(); SWTBotGefEditPart onMessagePart = children.get(children.size() - 1); // test the part if (!(onMessagePart.part().getModel() instanceof OnMessage)) { onMessagePart = children.get(children.size() - 2); } setFocus(onMessagePart); propsView.selectTab(0); SWTBot propsBot = propsView.bot(); propsBot.tree().expandNode(operationInfo).select(); propsBot.text(2).setText(in); save(); log.info("Added [part=" + onMessagePart + ", name=Unnamed]"); return onMessagePart; }
public void appendActivity(SWTBotGefEditPart toPart, String activity, String name) { setFocus(toPart); gEditor.clickContextMenu("Add").clickContextMenu(activity); propsView.selectTab(0); SWTBot propsBot = propsView.bot(); propsBot.text(0).setText(name); }
@Test public void testChangeProperties() throws Exception { openDialog(); SWTBotCheckBox checkBox = mBot.checkBox("Route orders to server"); assertThat(checkBox.isChecked(), is(true)); checkBox.click(); mBot.button("Add New Property").click(); new NewPropertyInputDialogTestFixture("key", "value").inputData(); mBot.button("Add New Property").click(); new NewPropertyInputDialogTestFixture("key2", "value2").inputData(); mBot.button("OK").click(); Thread.sleep(WAIT_TIME); AbstractUIRunner.syncRun( new ThrowableRunnable() { @Override public void run() throws Throwable { assertDeployedStrategy( mStrategy, mEngine, StrategyState.STOPPED, "Strategy1", "Claz", "Lang", "c:\\path", false, ImmutableMap.of("key", "value", "key2", "value2")); } }); }
@Override public void confirmShellAddProjects(String projectName, TypeOfCreateProject usingWhichProject) throws RemoteException { SWTBot bot = new SWTBot(); bot.waitUntil( Conditions.shellIsActive(SHELL_ADD_PROJECTS), SarosSWTBotPreferences.SAROS_LONG_TIMEOUT); SWTBotShell shell = bot.shell(SHELL_ADD_PROJECTS); switch (usingWhichProject) { case NEW_PROJECT: shell.bot().radio(RADIO_CREATE_NEW_PROJECT).click(); break; case EXIST_PROJECT: shell.bot().radio(RADIO_USING_EXISTING_PROJECT).click(); shell.bot().textWithLabel("Project name", 1).setText(projectName); break; case EXIST_PROJECT_WITH_COPY: shell.bot().radio("Use existing project").click(); shell.bot().checkBox("Create copy for working distributed. New project name:").click(); break; } shell.bot().button(FINISH).click(); bot.waitUntil(Conditions.shellCloses(shell)); }
@Test public void testPropertiesContextMenu() throws Exception { openDialog(); // use index 1 since first tree is property page navigation tree SWTBotTree tree = mBot.tree(1); ContextMenuHelper.clickContextMenu(tree, "Add"); new NewPropertyInputDialogTestFixture("keyx", "valuex").inputData(); ContextMenuHelper.clickContextMenu(tree, "Add"); new NewPropertyInputDialogTestFixture("keyz", "valuez").inputData(); tree.getTreeItem("keyz").select(); ContextMenuHelper.clickContextMenu(tree, "Delete"); tree.unselect(); // delete should not show up when the selection is empty assertThat(SWTTestUtil.getMenuItems(tree).get("Delete"), nullValue()); mBot.button("OK").click(); Thread.sleep(WAIT_TIME); AbstractUIRunner.syncRun( new ThrowableRunnable() { @Override public void run() throws Throwable { assertDeployedStrategy( mStrategy, mEngine, StrategyState.STOPPED, "Strategy1", "Claz", "Lang", "c:\\path", true, ImmutableMap.of("keyx", "valuex")); } }); }
private void openDialog() throws Exception { AbstractUIRunner.syncRun( new ThrowableRunnable() { @Override public void run() throws Throwable { mStrategy = createDeployedStrategy("Strategy1"); mStrategy.setUrn(new ModuleURN("metc:strategy:system:Strategy1")); mStrategy.setClassName("Claz"); mStrategy.setLanguage("Lang"); mStrategy.setScriptPath("c:\\path"); mStrategy.setRouteOrdersToServer(true); mEngine = createEngine("Engine"); mEngine.setConnection(new MockUIConnection()); mEngine.getDeployedStrategies().add(mStrategy); mDialog = PropertyDialog.createDialogOn( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), StrategyEngineWorkbenchUI.DEPLOYED_STRATEGY_CONFIGURATION_PROPERTY_PAGE_ID, mStrategy); mDialog.setBlockOnOpen(false); mDialog.open(); } }); mBot.shell("Properties for Strategy1 on Engine"); SWTTestUtil.assertButtonDoesNotExist("Apply"); SWTTestUtil.assertButtonDoesNotExist("Restore Defaults"); SWTTestUtil.testReadOnlyText(mBot.textWithLabel("Instance Name:"), "Strategy1"); SWTTestUtil.testReadOnlyText(mBot.textWithLabel("Class:"), "Claz"); SWTTestUtil.testReadOnlyText(mBot.textWithLabel("Language:"), "Lang"); SWTTestUtil.testReadOnlyText(mBot.textWithLabel("Script:"), "c:\\path"); }
@Test public void testCancelChange() throws Exception { openDialog(); mBot.checkBox("Route orders to server").click(); mBot.button("Add New Property").click(); new NewPropertyInputDialogTestFixture("key2", "value2").inputData(); mBot.button("Cancel").click(); Thread.sleep(WAIT_TIME); AbstractUIRunner.syncRun( new ThrowableRunnable() { @Override public void run() throws Throwable { assertDeployedStrategy( mStrategy, mEngine, StrategyState.STOPPED, "Strategy1", "Claz", "Lang", "c:\\path", true, null); } }); }
@Test public void testInlineEditing() throws Exception { openDialog(); mBot.button("Add New Property").click(); new NewPropertyInputDialogTestFixture("key2", "value2").inputData(); // use index 1 since first tree is property page navigation tree CustomTree tree = new CustomTree(mBot.tree(1).widget); tree.click(0, 1); mBot.sleep(500); mBot.text("value2").setText("value3"); mBot.button("OK").click(); Thread.sleep(WAIT_TIME); AbstractUIRunner.syncRun( new ThrowableRunnable() { @Override public void run() throws Throwable { assertDeployedStrategy( mStrategy, mEngine, StrategyState.STOPPED, "Strategy1", "Claz", "Lang", "c:\\path", true, ImmutableMap.of("key2", "value3")); } }); }
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)); }
@Test public void shouldRefreshSyncResultAfterRepositoryChange() throws Exception { // given resetRepositoryToCreateInitialTag(); changeFilesInProject(); launchSynchronization(HEAD, HEAD, true); // preconditions - sync result should contain two uncommitted changes SWTBotTree syncViewTree = bot.viewByTitle("Synchronize").bot().tree(); SWTBotTreeItem[] syncItems = syncViewTree.getAllItems(); assertTrue(syncItems[0].getText().contains(PROJ1)); syncItems[0].expand(); syncItems[0].getItems()[0].expand(); assertEquals(2, syncItems[0].getItems()[0].getItems().length); // when commit(PROJ1); // then - synchronize view should be empty SWTBot viewBot = bot.viewByTitle("Synchronize").bot(); @SuppressWarnings("unchecked") Matcher matcher = allOf(widgetOfType(Label.class), withRegex("No changes in .*")); @SuppressWarnings("unchecked") SWTBotLabel l = new SWTBotLabel((Label) viewBot.widget(matcher)); assertNotNull(l); }
@Override public void confirmShellNewSharedFile(String decision) { SWTBot bot = new SWTBot(); SWTBotShell shell = bot.shell(SHELL_NEW_FILE_SHARED); shell.activate(); shell.bot().button(decision).click(); bot.waitUntil(Conditions.shellCloses(shell)); }
@Override public void confirmShellNeedBased(String decsision, boolean remember) throws RemoteException { SWTBot bot = new SWTBot(); SWTBotShell shell = bot.shell(SHELL_NEED_BASED_SYNC); shell.activate(); if (remember) shell.bot().checkBox("Remember my decision.").click(); shell.bot().button(decsision).click(); bot.waitUntil(Conditions.shellCloses(shell)); }
/** @param bot */ private void createJavaProject(SWTBot bot) throws Exception { bot.menu("File") .menu("New") .menu("Java Project") .click(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ bot.shell("New Java Project").activate(); // $NON-NLS-1$ bot.textWithLabel("Project name:").setText("MyProject"); // $NON-NLS-1$ //$NON-NLS-2$ bot.button("Finish").click(); // $NON-NLS-1$ }
@Test public void getsTextCellBasedOnRowNumberColumnText() throws Exception { bot.checkBox("Multiple Columns").select(); tree = bot.treeInGroup("Tree"); assertEquals("2556", tree.cell(1, "Size")); assertEquals("Node 2", tree.cell(1, "Name")); assertEquals("today", tree.cell(3, "Modified")); }
@Test public void getsColumnTextBasedOnRowColumnNumbers() throws Exception { bot.checkBox("Multiple Columns").select(); tree = bot.treeInGroup("Tree"); assertEquals("2556", tree.cell(1, 2)); assertEquals("Node 2", tree.cell(1, 0)); assertEquals("today", tree.cell(3, 3)); }
/** * Closes Subclipse Report Usage Window * * @param shell * @param report */ private static void closeSubclipseUsageWindow(SWTBotShell shell, boolean report) { SWTBot shellBot = shell.bot(); SWTBotCheckBox chbReportUsage = shellBot.checkBox(IDELabel.SubclipseUsageDialog.REPORT_USAGE_CHECK_BOX); if ((report && (!chbReportUsage.isChecked())) || ((!report) && chbReportUsage.isChecked())) { chbReportUsage.click(); } shellBot.button(IDELabel.Button.OK).click(); log.info("Sublcipse Report Usage window closed"); }
@Test public void setsMultipleSelection() throws Exception { bot.radio("SWT.MULTI").click(); tree = bot.treeInGroup("Tree"); tree.select(new String[] {"Node 2", "Node 4"}); assertEquals(2, tree.selectionCount()); TableCollection selection = tree.selection(); assertEquals("Node 2", selection.get(0, 0)); assertEquals("Node 4", selection.get(1, 0)); }
// DONE! public SWTBotGefEditPart addIf(SWTBotGefEditPart toPart, String name, String condition) { appendActivity(toPart, "If", name); SWTBot propsBot = propsView.bot(); propsView.selectTab(1); propsBot.button("Create a New Condition").click(); propsBot.styledText().setText(condition); save(); SWTBotGefEditPart added = getEditPart(toPart, name); log.info("Added [part=" + added + ", name=" + name + "]"); return added; }
// DONE ! public SWTBotGefEditPart addReceive( SWTBotGefEditPart toPart, String name, String var, String[] operationInfo) { appendActivity(toPart, "Receive", name); SWTBot propsBot = propsView.bot(); propsView.selectTab(1); propsBot.tree().expandNode(operationInfo).select(); propsBot.text(2).setText(var); save(); SWTBotGefEditPart added = getEditPart(toPart, name); // log.info("Added [part=" + added + ", name=" + name + "]"); return added; }
@Test public void clicksOnANode() throws Exception { bot.checkBox("Listen").select(); SWTBotTreeItem node = bot.tree().expandNode("Node 3").expandNode("Node 3.1"); bot.button("Clear").click(); node.click(); SWTBotText listener = bot.textInGroup("Listeners"); assertTextContains("MouseDown [3]: MouseEvent{Tree {}", listener); assertTextContains("Selection [13]: SelectionEvent{Tree {}", listener); assertTextContains("item=TreeItem {Node 3.1}", listener); assertTextContains("MouseUp [4]: MouseEvent{Tree {}", listener); }
@Test public void getsAllColumnHeadings() throws Exception { bot.checkBox("Multiple Columns").select(); tree = bot.treeInGroup("Tree"); ArrayList<String> arrayList = new ArrayList<String>(); arrayList.add("Name"); arrayList.add("Type"); arrayList.add("Size"); arrayList.add("Modified"); assertEquals(arrayList, tree.columns()); }
@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); }
@Test public void expandsNode() throws Exception { bot.checkBox("Multiple Columns").select(); bot.checkBox("Listen").select(); Widget notifications = bot.textInGroup("Listeners").widget; tree = bot.treeInGroup("Tree"); tree.expandNode("Node 2"); assertEquals(6, tree.visibleRowCount()); assertTextContains("Expand [17]: TreeEvent{Tree {} time=", notifications); assertTextContains( "data=null item=TreeItem {Node 2} detail=0 x=0 y=0 width=0 height=0 stateMask=0 text=null doit=true}", notifications); }
// TODO - return just the new <copy></copy> element public SWTBotGefEditPart copyVarToExpresion( SWTBotGefEditPart assignPart, String[] from, String exp) { setFocus(assignPart); propsView.selectTab(1); SWTBot propsBot = propsView.bot(); propsBot.button("New").click(); propsBot.comboBox(1).setSelection("Expression"); propsBot.tree().expandNode(from).select(); propsBot.styledText().setText(exp); save(); return assignPart; }
/** * Choose Server Popup Menu with specified label on Server with position specified by index * * @param bot * @param index * @param menuLabel * @param timeOut * @param uiTimeOut */ public static void chooseServerPopupMenu( SWTWorkbenchBot bot, int index, String menuLabel, long timeOut, long uiTimeOut) { SWTEclipseExt swtEclipseExt = new SWTEclipseExt(); SWTBot servers = swtEclipseExt.showView(ViewType.SERVERS); SWTBotTree serverTree = servers.tree(); ContextMenuHelper.prepareTreeItemForContextMenu(serverTree, index); SWTTestExt.util.waitForAll(uiTimeOut); SWTBotMenu menu = new SWTBotMenu(ContextMenuHelper.getContextMenu(serverTree, menuLabel, false)); SWTTestExt.util.waitForAll(uiTimeOut); menu.click(); SWTTestExt.util.waitForAll(timeOut); }
@Test public void getsSingleSelection() throws Exception { bot.checkBox("Multiple Columns").select(); tree = bot.treeInGroup("Tree"); tree.select(2); TableCollection selection = tree.selection(); assertEquals(1, selection.rowCount()); assertEquals(4, selection.columnCount()); assertEquals( new TableCollection() .add(new TableRow(new String[] {"Node 3", "images", "91571", "yesterday"})), selection); }
// DONE ! public SWTBotGefEditPart addInvoke( SWTBotGefEditPart toPart, String name, String in, String out, String[] operationInfo) { appendActivity(toPart, "Invoke", name); SWTBot propsBot = propsView.bot(); propsView.selectTab(1); propsBot.tree().expandNode(operationInfo).select(); propsBot.text(2).setText(in); propsBot.text(3).setText(out); // Save changes to update process model save(); SWTBotGefEditPart added = getEditPart(toPart, name); // log.info("Added [part=" + added + ", name=" + name + "]"); return added; }
@Test public void testDisabledForRunningStrategy() throws Exception { AbstractUIRunner.syncRun( new ThrowableRunnable() { @Override public void run() throws Throwable { mStrategy = createDeployedStrategy("Strategy1"); mStrategy.setClassName("Claz"); mStrategy.setLanguage("Lang"); mStrategy.setScriptPath("c:\\path"); mStrategy.setRouteOrdersToServer(true); mStrategy.setState(StrategyState.RUNNING); mEngine = createEngine("Engine"); mEngine.setConnection(new MockUIConnection()); mEngine.getDeployedStrategies().add(mStrategy); mDialog = PropertyDialog.createDialogOn( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), StrategyEngineWorkbenchUI.DEPLOYED_STRATEGY_CONFIGURATION_PROPERTY_PAGE_ID, mStrategy); mDialog.setBlockOnOpen(false); mDialog.open(); } }); mBot.shell("Properties for Strategy1 on Engine"); testDisabled(mBot.textWithLabel("Instance Name:"), "Strategy1"); testDisabled(mBot.textWithLabel("Class:"), "Claz"); testDisabled(mBot.textWithLabel("Language:"), "Lang"); testDisabled(mBot.textWithLabel("Script:"), "c:\\path"); assertThat(mBot.checkBox("Route orders to server").isEnabled(), is(false)); assertThat(mBot.checkBox("Route orders to server").isChecked(), is(true)); // use index 1 since first tree is property page navigation tree assertThat(mBot.tree(1).isEnabled(), is(false)); assertThat(mBot.button("Add New Property").isEnabled(), is(false)); }
@Override public void confirmShellLeavingClosingSession() throws RemoteException { SWTBot bot = new SWTBot(); SWTBotShell shell; if (!Views.getInstance().sarosView().isHost()) { shell = bot.shell(SHELL_CONFIRM_LEAVING_SESSION); } else { shell = bot.shell(SHELL_CONFIRM_CLOSING_SESSION); } shell.activate(); shell.bot().button(YES).click(); Views.getInstance().sarosView().waitUntilIsNotInSession(); }