public void testBlockComment() throws Throwable { // Test open page openPage(); setEditor(bot.editorByTitle(TEST_PAGE).toTextEditor()); setEditorText(getEditor().getText()); // Test add block comment from Source menu SWTBotExt botExt = new SWTBotExt(); final String commentValue = "<h:commandButton action=\"hello\" value=\"Say Hello!\" />"; SWTJBTExt.selectTextInSourcePane(botExt, TEST_PAGE, commentValue, 0, commentValue.length(), 0); bot.sleep(Timing.time2S()); bot.menu("Source").menu("Add Block Comment").click(); // $NON-NLS-1$//$NON-NLS-2$ getEditor().save(); waitForBlockingJobsAcomplished(VISUAL_UPDATE); SWTBotWebBrowser webBrowser = new SWTBotWebBrowser(TEST_PAGE, new SWTBotExt()); assertVisualEditorContainsManyComments(webBrowser, 1, TEST_PAGE); assertTrue( "Visual Representation of page doesn't contain comment with value " + commentValue, webBrowser.containsCommentWithValue(commentValue)); // Test remove block comment from Source menu SWTJBTExt.selectTextInSourcePane(botExt, TEST_PAGE, commentValue, 0, commentValue.length(), 0); getEditor().selectCurrentLine(); bot.sleep(Timing.time2S()); bot.menu("Source").menu("Remove Block Comment").click(); // $NON-NLS-1$//$NON-NLS-2$ getEditor().save(); waitForBlockingJobsAcomplished(VISUAL_UPDATE); assertVisualEditorContainsManyComments(webBrowser, 0, TEST_PAGE); // Test add block comment with CTRL+SHIFT+/ hot keys SWTJBTExt.selectTextInSourcePane(botExt, TEST_PAGE, commentValue, 0, commentValue.length(), 0); pressBlockCommentHotKeys(); getEditor().save(); waitForBlockingJobsAcomplished(VISUAL_UPDATE); assertVisualEditorContainsManyComments(webBrowser, 1, TEST_PAGE); assertTrue( "Visual Representation of page doesn't contain comment with value " + commentValue, webBrowser.containsCommentWithValue(commentValue)); // Test remove block comment with CTRL+SHIFT+\ hot keys SWTJBTExt.selectTextInSourcePane(botExt, TEST_PAGE, commentValue, 0, commentValue.length(), 0); bot.sleep(Timing.time2S()); getEditor().selectCurrentLine(); pressUnBlockCommentHotKeys(); getEditor().save(); waitForBlockingJobsAcomplished(VISUAL_UPDATE); assertVisualEditorContainsManyComments(webBrowser, 0, TEST_PAGE); }
/** * Checks Content Assist content on specified position within editor with editorTitle and checks * if expectedProposalList is equal to current Proposal List * * @param editorTitle * @param textToSelect * @param selectionOffset * @param selectionLength * @param textToSelectIndex * @param expectedProposalList * @param mustEquals */ public static SWTBotEditor checkContentAssistContent( SWTBotExt bot, String editorTitle, String textToSelect, int selectionOffset, int selectionLength, int textToSelectIndex, List<String> expectedProposalList, boolean mustEquals) { SWTJBTExt.selectTextInSourcePane( bot, editorTitle, textToSelect, selectionOffset, selectionLength, textToSelectIndex); bot.sleep(Timing.time1S()); SWTBotEditorExt editor = SWTTestExt.bot.swtBotEditorExtByTitle(editorTitle); ContentAssistBot contentAssist = editor.contentAssist(); List<String> currentProposalList = contentAssist.getProposalList(); assertTrue( "Code Assist menu has incorrect menu items.\n" + "Expected Proposal Menu Labels vs. Current Proposal Menu Labels :\n" + FormatUtils.getListsDiffFormatted(expectedProposalList, currentProposalList), mustEquals ? expectedProposalList.equals(currentProposalList) : currentProposalList.containsAll(expectedProposalList)); return editor; }
/** * Checks Content Assist auto proposal. It's case when there is only one content assist item and * that item is automatically inserted into editor and checks if expectedProposalList is equal to * current Proposal List * * @param editorTitle * @param textToSelect * @param selectionOffset * @param selectionLength * @param textToSelectIndex * @param expectedInsertedText */ public static SWTBotEditor checkContentAssistAutoProposal( SWTBotExt bot, String editorTitle, String textToSelect, int selectionOffset, int selectionLength, int textToSelectIndex, String expectedInsertedText) { SWTJBTExt.selectTextInSourcePane( bot, editorTitle, textToSelect, selectionOffset, selectionLength, textToSelectIndex); bot.sleep(Timing.time1S()); SWTBotEditorExt editor = SWTTestExt.bot.swtBotEditorExtByTitle(editorTitle); String editorLineBeforeInsert = editor.getTextOnCurrentLine(); int xPos = editor.cursorPosition().column; String expectedEditorLineAfterInsert = editorLineBeforeInsert.substring(0, xPos) + expectedInsertedText + editorLineBeforeInsert.substring(xPos); ContentAssistBot contentAssist = editor.contentAssist(); contentAssist.invokeContentAssist(); String editorLineAfterInsert = editor.getTextOnCurrentLine(); assertTrue( "Text on current line should be:\n" + expectedEditorLineAfterInsert + "\nbut is:\n" + editorLineAfterInsert, editorLineAfterInsert.equals(expectedEditorLineAfterInsert)); return editor; }
/** * Applies Open On (F3) on textToSelect within editor with editorTitle and checks if * expectedOpenedFileName was opened * * @param editorTitle * @param textToSelect * @param selectionOffset * @param selectionLength * @param textToSelectIndex * @param expectedOpenedFileName */ public static SWTBotEditor checkOpenOnFileIsOpened( SWTBotExt bot, String editorTitle, String textToSelect, int selectionOffset, int selectionLength, int textToSelectIndex, String expectedOpenedFileName) { SWTBotEclipseEditor sourceEditor = SWTJBTExt.selectTextInSourcePane( bot, editorTitle, textToSelect, selectionOffset, selectionLength, textToSelectIndex); bot.sleep(Timing.time3S()); sourceEditor.setFocus(); // process UI Events UIThreadRunnable.syncExec( new VoidResult() { @Override public void run() {} }); bot.sleep(Timing.time3S()); new SWTUtilExt(bot).waitForNonIgnoredJobs(); KeyboardHelper.typeKeyCodeUsingAWT(KeyEvent.VK_F3); // process UI Events UIThreadRunnable.syncExec( new VoidResult() { @Override public void run() {} }); bot.sleep(Timing.time3S()); new SWTUtilExt(bot).waitForNonIgnoredJobs(); return checkActiveEditorTitle(bot, expectedOpenedFileName); }
private static SWTBotEditor checkActiveEditorTitle(SWTBotExt bot, String expectedOpenedFileName) { SWTBotEditor activeEditor = null; try { bot.waitUntil( new ActiveEditorHasTitleCondition(bot, expectedOpenedFileName), Timing.time10S()); activeEditor = bot.activeEditor(); } catch (TimeoutException toe) { activeEditor = bot.activeEditor(); fail( "Opened file has to have title " + expectedOpenedFileName + " but has " + activeEditor.getTitle()); } return activeEditor; }
/** * Applies Content Assist auto proposal. It's case when there is only one content assist item and * that item is automatically inserted into editor * * @param editorTitle * @param textToSelect * @param selectionOffset * @param selectionLength * @param textToSelectIndex */ public static SWTBotEditor applyContentAssistAutoProposal( SWTBotExt bot, String editorTitle, String textToSelect, int selectionOffset, int selectionLength, int textToSelectIndex) { SWTJBTExt.selectTextInSourcePane( bot, editorTitle, textToSelect, selectionOffset, selectionLength, textToSelectIndex); bot.sleep(Timing.time1S()); SWTBotEditorExt editor = SWTTestExt.bot.swtBotEditorExtByTitle(editorTitle); ContentAssistBot contentAssist = editor.contentAssist(); contentAssist.invokeContentAssist(); return editor; }
/** * Creates Drools Rule and checks result * * @param droolsRuletName */ private void createDroolsRule(String droolsRuleName) { packageExplorer.show(); SWTBotTreeItem tiDroolsRules = packageExplorer.selectTreeItem( DroolsAllBotTests.SRC_MAIN_RULES_TREE_NODE, new String[] {DroolsAllBotTests.DROOLS_PROJECT_NAME}); tiDroolsRules.select(); eclipse.createNew(EntityType.DROOLS_RULE); bot.textWithLabel(IDELabel.NewDroolsRuleDialog.FILE_NAME).setText(droolsRuleName); bot.textWithLabel(IDELabel.NewDroolsRuleDialog.RULE_PACKAGE_NAME) .setText(DroolsAllBotTests.COM_SAMPLE_TREE_NODE); bot.button(IDELabel.Button.FINISH).click(); bot.sleep(Timing.time1S()); tiDroolsRules.expand(); // Test if new Drools Rule is within package tree view boolean isRuleCreated = true; try { tiDroolsRules.getNode(droolsRuleName); } catch (WidgetNotFoundException wnfe) { isRuleCreated = false; } assertTrue( "New Drools Rule was not created properly. It's not present within Package Explorer", isRuleCreated); // Test if new Drools Rule is opened in editor isRuleCreated = true; try { bot.editorByTitle(droolsRuleName); } catch (WidgetNotFoundException wnfe) { isRuleCreated = false; } assertTrue( "New Drools Rule was not created properly. File " + droolsRuleName + " is not opened in editor", isRuleCreated); }
/** Test manage Drools Rules */ @Test public void testManageDroolsRules() { createDroolsRule(DroolsAllBotTests.TEST_DROOLS_RULE_NAME); bot.sleep(Timing.time3S()); debugDroolsRule(DroolsAllBotTests.SAMPLE_DROOLS_RULE_NAME); }
/** * Adds External Jar File to Project Build Path. If External Jar File already exists and * 'overwriteIfExists' parameter is set to true, it is overwritten * * @param externalJarLocation * @param projectName * @return */ public static String addExternalJar( final String externalJarLocation, final String projectName, boolean overwriteIfExists) { assertTrue( "External Jar Location cannot be empty but is " + externalJarLocation, externalJarLocation != null && externalJarLocation.length() > 0); SWTBotExt bot = new SWTEclipseExt().openPropertiesOfProject(projectName); bot.shell(IDELabel.Shell.PROPERTIES_FOR + " " + projectName).activate().bot(); bot.tree() .expandNode(IDELabel.JavaBuildPathPropertiesEditor.JAVA_BUILD_PATH_TREE_ITEM_LABEL) .select(); bot.sleep(Timing.time3S()); bot.tabItem(IDELabel.JavaBuildPathPropertiesEditor.LIBRARIES_TAB_LABEL).activate(); final SWTBotButton btn = bot.button(IDELabel.Button.ADD_VARIABLE); btn.click(); bot.sleep(Timing.time2S()); // workaround because first click is not working when test is run via maven try { bot.shell(IDELabel.Shell.NEW_VARIABLE_CLASS_PATH_ENTRY).activate(); } catch (WidgetNotFoundException wnfe) { btn.click(); bot.sleep(Timing.time2S()); bot.shell(IDELabel.Shell.NEW_VARIABLE_CLASS_PATH_ENTRY).activate(); } String jarFileName = new File(externalJarLocation).getName(); String variableEntryName = jarFileName.toUpperCase() + "_LOCATION"; boolean externalJarExists = false; for (int i = 0; i < bot.table().rowCount(); i++) { if (bot.table().getTableItem(i).getText().split(" - ")[0].equals(variableEntryName)) { bot.table().getTableItem(i).select(); externalJarExists = true; break; } } bot.button(IDELabel.Button.CONFIGURE_VARIABLES).click(); bot.shell(IDELabel.Shell.PREFERENCES_FILTERED).activate(); if (externalJarExists && overwriteIfExists) { bot.button(IDELabel.Button.EDIT).click(); bot.shell(IDELabel.Shell.EDIT_VARIABLE_ENTRY).activate(); bot.textWithLabel(IDELabel.NewVariableEntryDialog.PATH_TEXT_LABEL) .setText(externalJarLocation); } else { bot.button(IDELabel.Button.NEW).click(); bot.shell(IDELabel.Shell.NEW_VARIABLE_ENTRY).activate(); bot.textWithLabel(IDELabel.NewVariableEntryDialog.NAME_TEXT_LABEL).setText(variableEntryName); bot.textWithLabel(IDELabel.NewVariableEntryDialog.PATH_TEXT_LABEL) .setText(externalJarLocation); } bot.clickButton(IDELabel.Button.OK).click(); String result = TableHelper.getSelectionText(bot.table()); bot.waitUntil(new ActiveShellTitleMatches(bot, "Preferences \\(Filtered\\)"), Timing.time3S()); bot.clickButton(IDELabel.Button.OK).click(); bot.waitUntil( new ActiveShellTitleMatches(bot, IDELabel.Shell.NEW_VARIABLE_CLASS_PATH_ENTRY), Timing.time3S()); bot.clickButton(IDELabel.Button.OK).click(); bot.waitUntil( new ActiveShellTitleMatches(bot, IDELabel.Shell.PROPERTIES_FOR + " " + projectName), Timing.time3S()); bot.clickButton(IDELabel.Button.OK).click(); new SWTUtilExt(bot).waitForNonIgnoredJobs(); return result; }