/** Ensures that ExternalJavaActionCalls with unchecked precondition are not displayed. */ public void testPopupMenuWithExternalJavaActionCallAndFalsePrecondition() { // When getting the contextual menu of // "Employee" Class -- "wage" attribute // The precondition value is false and the Java Action Call action // should // not be displayed boolean foundContextMenu = true; final SWTBotTreeItem node = editor .bot() .tree() .getTreeItem(TREE_ITEM_WITH_JAVA_ACTION_CONTAINER_NAME) .expand() .getNode(TREE_ITEM_WITH_JAVA_ACTION_NAME) .select(); // The test must be passed in the exception, so we deactivated the catch // of // "error log" view setErrorCatchActive(false); try { node.contextMenu(JAVA_ACTION_CALL_NAME); } catch (TimeoutException e) { foundContextMenu = false; } assertFalse( "Java Action Call " + JAVA_ACTION_CALL_NAME + " should not be displayed on TreeITem " + TREE_ITEM_WITH_JAVA_ACTION_NAME, foundContextMenu); setErrorCatchActive(true); }
@Test @Ignore // workspace model dosn't show non-workspace files ... yet ;) public void shouldShowCompareEditorForNonWorkspaceFileFromSynchronization() throws Exception { // given String content = "file content"; String name = "non-workspace.txt"; File root = new File(getTestDirectory(), REPO1); File nonWorkspace = new File(root, name); BufferedWriter writer = new BufferedWriter(new FileWriter(nonWorkspace)); writer.append(content); writer.close(); // when launchSynchronization(INITIAL_TAG, HEAD, true); // then SWTBotTree syncViewTree = bot.viewByTitle("Synchronize").bot().tree(); SWTBotTreeItem workingTree = syncViewTree.expandNode(PROJ1); assertEquals(1, syncViewTree.getAllItems().length); workingTree.expand().getNode(name).doubleClick(); SWTBotEditor editor = bot.editorByTitle(name); editor.setFocus(); // the WidgetNotFoundException will be thrown when widget with given content cannot be not found SWTBotStyledText left = editor.bot().styledText(content); SWTBotStyledText right = editor.bot().styledText(""); // to be complete sure assert that both sides are not the same assertNotSame(left, right); }
@Test public void translationEditorFilterControls() throws Exception { SWTBotCheckBox emptyChkBox = editor.bot().checkBox(EMPTY_TRANSLATIONS); assertTrue("Filter empty translations is default checked", emptyChkBox.isChecked()); SWTBotCheckBox depPrjTrans = editor.bot().checkBox(DEPPROJ_TRANSLATIONS); assertTrue("Filter dependent project translations is default checked", depPrjTrans.isChecked()); }
/** @throws Exception */ private void checkTab(String tabName) throws Exception { SWTBotCTabItem tabItem = editor.bot().cTabItem(tabName); tabItem.setFocus(); SWTBotTable table = editor.bot().table(); SWTBotTableColumn tCol = table.header("Translation of"); tCol.setFocus(); tCol = table.header("Kind"); tCol.setFocus(); SWTBotButton bttn = editor.bot().button("Edit Source Model"); assertFalse(bttn.isEnabled()); }
/** Ensures that PopupMenu is not created if its precondition is not checked. */ public void testPopupMenuWithFalsePrecondition() { // When getting the contextual menu of // "NamedEntity" Class -- "wrongFeature" attribute // The precondition value is false and the Pop-up Menu should // not be displayed boolean foundContextMenu = true; SWTBotTreeItem unaplicableNode = editor .bot() .tree() .getTreeItem(TREE_ITEM_WITH_UNAPLICABLE_POPUP_CONTAINER_NAME) .expand() .getNode(TREE_ITEM_WITH_UNAPLICABLE_POPUP_NAME); try { unaplicableNode.contextMenu(POP_UP_MENU_NAME); } catch (TimeoutException e) { foundContextMenu = false; } assertFalse( "Pop-up Menu " + POP_UP_MENU_NAME + " should not be displayed on TreeITem " + TREE_ITEM_WITH_UNAPLICABLE_POPUP_NAME, foundContextMenu); }
@Test public void shouldExchangeCompareEditorSidesBetweenIncomingAndOutgoingChanges() throws Exception { // given resetRepositoryToCreateInitialTag(); makeChangesAndCommit(PROJ1); // compare HEAD against tag launchSynchronization(HEAD, INITIAL_TAG, false); SWTBotEditor compEditor = getCompareEditorForFileInWorspaceModel(FILE1); SWTBot outgoingCompare = compEditor.bot(); // save left value from compare editor String outgoingLeft = outgoingCompare.styledText(0).getText(); // save right value from compare editor String outgoingRight = outgoingCompare.styledText(1).getText(); compEditor.close(); // when // compare tag against HEAD launchSynchronization(INITIAL_TAG, HEAD, false); // then SWTBot incomingComp = getCompareEditorForFileInWorspaceModel(FILE1).bot(); String incomingLeft = incomingComp.styledText(0).getText(); String incomingRight = incomingComp.styledText(1).getText(); // right side from compare editor should be equal with left assertThat(outgoingLeft, equalTo(incomingRight)); // left side from compare editor should be equal with right assertThat(outgoingRight, equalTo(incomingLeft)); }
/** Test show type action on VSM and hide type action. */ public void testShowHideTypeAction() { SWTBotView projectExplorer = bot.viewByTitle("Model Explorer"); projectExplorer.setFocus(); projectExplorer.bot().tree().expandNode(getProjectName()).expandNode(VSM_FILE).doubleClick(); SWTBotEditor activeEditor = bot.activeEditor(); activeEditor.setFocus(); String nodeLabel = "platform:/resource/" + getProjectName() + "/" + VSM_FILE; SWTBotMenu contextualMenu = activeEditor .bot() .tree() .expandNode(nodeLabel) .expandNode(GROUP) .expandNode(VIEWPOINT_NAME) .expandNode(REPRESENTATION_NAME) .contextMenu(SHOW_TYPE); contextualMenu.click(); contextualMenu = activeEditor .bot() .tree() .expandNode(nodeLabel) .expandNode(TYPED_GROUP) .expandNode(TYPED_VIEWPOINT_NAME) .expandNode(TYPED_REPRESENTATION_NAME) .contextMenu(HIDE_TYPE); contextualMenu.click(); contextualMenu = activeEditor .bot() .tree() .expandNode(nodeLabel) .expandNode(GROUP) .expandNode(VIEWPOINT_NAME) .expandNode(REPRESENTATION_NAME) .contextMenu(SHOW_TYPE); }
/** * Select the given element in the given editor. * * @param editor the editor where the bot must process * @param element the element to select * @return the selected node */ public SWTBotTreeItem selectNode(SWTBotEditor editor, EObject element) { assertNotNull("The model has not been initialized.", testModelResource); final List<Object> expansionPath = EEFModelHelper.getExpansionPath(element); final Iterator<Object> iterator = expansionPath.iterator(); Object next = null; SWTBotTreeItem node2 = editor.bot().tree().getTreeItem(testModelResource.getURI().toString()); while (iterator.hasNext()) { sleep(1000); node2.expand(); next = iterator.next(); node2 = selectSubNode(node2, next); } return node2; }
/** * Save all editors * * @param bot */ public static void save(final SWTBotEditor editor) { editor .bot() .waitUntil( new DefaultCondition() { @Override public boolean test() throws Exception { return editor.isDirty(); } @Override public String getFailureMessage() { return "Editor never dirty"; } }, 10000, 1000); editor.save(); editor .bot() .waitUntil( new DefaultCondition() { @Override public boolean test() throws Exception { return !editor.isDirty(); } @Override public String getFailureMessage() { return "Editor still dirty"; } }, 10000, 1000); }
@Test public void stashAndApplyChanges() throws Exception { String originalContent = getTestFileContent(); String modifiedContent = "changes to stash"; touch(modifiedContent); assertEquals(modifiedContent, getTestFileContent()); ContextMenuHelper.clickContextMenu( selectProject(), "Team", STASHES, UIText.StashesMenu_StashChangesActionText); SWTBotShell createDialog = bot.shell(UIText.StashCreateCommand_titleEnterCommitMessage); SWTBotText enterMessageText = createDialog.bot().text(0); String stashMessage = "stash message"; enterMessageText.setText(stashMessage); createDialog.bot().button(IDialogConstants.OK_LABEL).click(); assertEquals(originalContent, getTestFileContent()); ContextMenuHelper.clickContextMenu( selectProject(), "Team", STASHES, MessageFormat.format(UIText.StashesMenu_StashItemText, Integer.valueOf(0), stashMessage)); SWTBotEditor stashEditor = bot.activeEditor(); // Check if text with message is there stashEditor.bot().styledText(stashMessage); stashEditor .bot() .toolbarButtonWithTooltip(util.getPluginLocalizedValue("StashApplyCommand.label")) .click(); assertEquals(modifiedContent, getTestFileContent()); }
/** * @param path * @param modelName * @return the root of the new resource */ private EObject getRoot(String path, String modelName) { final URI fileURI = URI.createPlatformResourceURI(path + "/" + modelName, true); Resource resource = editingDomain.getResourceSet().getResource(fileURI, true); setTestModelResource(resource); final SWTBotTreeItem modelTreeItem = editor.bot().tree().getTreeItem(testModelResource.getURI().toString()); resource = (Resource) syncExec( new Result<Object>() { public Object run() { return modelTreeItem.widget.getData(); } }); setTestModelResource(resource); assertFalse("The model is empty.", resource.getContents().isEmpty()); return resource.getContents().get(0); }
private static void goToTableEnd() { SWTBotEditor eventsEditor = SWTBotUtils.activeEventsEditor(fBot); eventsEditor.setFocus(); eventsEditor.bot().table().pressShortcut(Keystrokes.END); }
/** * Gets the editor tree. * * @param bot the bot * @return the editor tree * @throws Exception the exception */ public static SWTBotTree getEditorTree(final SWTWorkbenchBot bot, String title) throws Exception { SWTBotEditor editor = bot.editorByTitle(title); SWTBotTree tree = editor.bot().tree(); return tree; }