Skip to content

Commit

Permalink
Fix selenium tests in editor package (#10471)
Browse files Browse the repository at this point in the history
Signed-off-by: Anatoliy Bazko <[email protected]>
  • Loading branch information
tolusha authored and tsmaeder committed Oct 12, 2018
1 parent d9b0ab4 commit 9756840
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ protected void registerAction(
keyBindingManager
.getGlobal()
.addKey(new KeyBuilder().shift().charCode(KeyCodeMap.F6).build(), "LS.rename");

DefaultActionGroup editorContextMenuGroup =
(DefaultActionGroup) actionManager.getAction("editorContextMenu");
editorContextMenuGroup.addSeparator();
editorContextMenuGroup.add(findDefinitionAction);
editorContextMenuGroup.add(refactoringGroup);
}

@Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ public enum ContextMenuLocator {
FORMAT(By.id("contextMenu/Format")),
QUICK_DOC(By.id("contextMenu/Quick Documentation")),
QUICK_FIX(By.id("contextMenu/Quick Fix")),
OPEN_DECLARATION(By.id("contextMenu/Open Declaration")),
FIND_DEFINITION(By.id("contextMenu/Find Definition")),
NAVIGATE_FILE_STRUCTURE(By.id("contextMenu/Navigate File Structure")),
FIND(By.id("contextMenu/Find")),
OPEN_ON_GITHUB(By.id("contextMenu/Open on GitHub")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

import static org.eclipse.che.selenium.pageobject.CodenvyEditor.ContextMenuLocator.CLOSE;
import static org.eclipse.che.selenium.pageobject.CodenvyEditor.ContextMenuLocator.FIND;
import static org.eclipse.che.selenium.pageobject.CodenvyEditor.ContextMenuLocator.FIND_DEFINITION;
import static org.eclipse.che.selenium.pageobject.CodenvyEditor.ContextMenuLocator.FORMAT;
import static org.eclipse.che.selenium.pageobject.CodenvyEditor.ContextMenuLocator.NAVIGATE_FILE_STRUCTURE;
import static org.eclipse.che.selenium.pageobject.CodenvyEditor.ContextMenuLocator.OPEN_DECLARATION;
import static org.eclipse.che.selenium.pageobject.CodenvyEditor.ContextMenuLocator.QUICK_DOC;
import static org.eclipse.che.selenium.pageobject.CodenvyEditor.ContextMenuLocator.QUICK_FIX;
import static org.eclipse.che.selenium.pageobject.CodenvyEditor.ContextMenuLocator.REDO;
Expand All @@ -25,14 +25,9 @@
import static org.eclipse.che.selenium.pageobject.CodenvyEditor.ContextMenuLocator.UNDO;
import static org.eclipse.che.selenium.pageobject.CodenvyEditor.MarkerLocator.ERROR;

import com.google.common.base.Joiner;
import com.google.inject.Inject;
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import java.util.Random;
import org.eclipse.che.commons.lang.NameGenerator;
import org.eclipse.che.selenium.core.client.TestProjectServiceClient;
import org.eclipse.che.selenium.core.project.ProjectTemplates;
Expand All @@ -56,20 +51,39 @@ public class ContextMenuEditorTest {

private static final String PROJECT_NAME =
NameGenerator.generate(ContextMenuEditorTest.class.getSimpleName(), 4);
private static final String PROJECT_NAME_2 = "2_ContextMenuEditor" + new Random().nextInt(999);
private static final String FORMATTED_TEXT =
"public class AppController implements Controller {\n"
"/*\n"
+ " * Copyright (c) 2012-2018 Red Hat, Inc.\n"
+ " * All rights reserved. This program and the accompanying materials\n"
+ " * are made available under the terms of the Eclipse Public License v1.0\n"
+ " * which accompanies this distribution, and is available at\n"
+ " * http://www.eclipse.org/legal/epl-v10.html\n"
+ " *\n"
+ " * Contributors:\n"
+ " * Red Hat, Inc. - initial API and implementation\n"
+ " */\n"
+ "package org.eclipse.qa.examples;\n"
+ "\n"
+ "import java.util.Random;\n"
+ "\n"
+ "import org.springframework.web.servlet.ModelAndView;\n"
+ "import org.springframework.web.servlet.mvc.Controller;\n"
+ "\n"
+ "import javax.servlet.http.HttpServletRequest;\n"
+ "import javax.servlet.http.HttpServletResponse;\n"
+ "\n"
+ "public class AppController implements Controller {\n"
+ " private static final String secretNum = Integer.toString(new Random().nextInt(10));\n"
+ "\n"
+ " @Override\n"
+ " public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {\n"
+ " String numGuessByUser = request.getParameter(\"numGuess\");\n"
+ " String result = \"\";\n"
+ "\n"
+ " \n"
+ " if (numGuessByUser != null && numGuessByUser.equals(secretNum)) {\n"
+ " result = \"Congrats! The number is \" + secretNum;\n"
+ " }\n"
+ "\n"
+ " } \n"
+ " \n"
+ " else if (numGuessByUser != null) {\n"
+ " result = \"Sorry, you failed. Try again later!\";\n"
+ " }\n"
Expand All @@ -84,14 +98,8 @@ public class ContextMenuEditorTest {

private static final String QUICK_DOC_TEXT =
"java.lang.Exception\n"
+ "\n"
+ "The class Exception and its subclasses are a form of Throwable that"
+ " indicates conditions that a reasonable application might want to catch.\n"
+ "The class Exception and any subclasses that are not also subclasses "
+ "of RuntimeException are checked exceptions. Checked exceptions need "
+ "to be declared in a method or constructor's throws clause if they can"
+ " be thrown by the execution of the method or constructor and propagate"
+ " outside the method or constructor boundary.\n"
+ "The class Exception and its subclasses are a form of Throwable that indicates conditions that a reasonable application might want to catch.\n"
+ "The class Exception and any subclasses that are not also subclasses of RuntimeException are checked exceptions. Checked exceptions need to be declared in a method or constructor's throws clause if they can be thrown by the execution of the method or constructor and propagate outside the method or constructor boundary.\n"
+ "Since:\n"
+ "JDK1.0\n"
+ "Author:\n"
Expand All @@ -101,8 +109,6 @@ public class ContextMenuEditorTest {
+ "@jls\n"
+ "11.2 Compile-Time Checking of Exceptions";

private String expectedTextBeforeDownloadSources = "";

@Inject private TestWorkspace workspace;
@Inject private Ide ide;
@Inject private ProjectExplorer projectExplorer;
Expand All @@ -122,16 +128,6 @@ public void prepare() throws Exception {
Paths.get(resource.toURI()),
PROJECT_NAME,
ProjectTemplates.MAVEN_SPRING);
testProjectServiceClient.importProject(
workspace.getId(),
Paths.get(resource.toURI()),
PROJECT_NAME_2,
ProjectTemplates.MAVEN_SPRING);

resource = ContextMenuEditorTest.class.getResource("expected-test-before-download-sources");
List<String> expectedText =
Files.readAllLines(Paths.get(resource.toURI()), Charset.forName("UTF-8"));
expectedTextBeforeDownloadSources = Joiner.on('\n').join(expectedText);

ide.open(workspace);
projectExplorer.waitProjectExplorer();
Expand Down Expand Up @@ -212,9 +208,9 @@ public void checkClose() {

@Test(priority = 3)
public void checkQuickDocumentation() {
projectExplorer.waitItem(PROJECT_NAME_2);
projectExplorer.waitItem(PROJECT_NAME);
projectExplorer.openItemByPath(
PROJECT_NAME_2 + "/src/main/java/org/eclipse/qa/examples/AppController.java");
PROJECT_NAME + "/src/main/java/org/eclipse/qa/examples/AppController.java");
editor.waitActive();
editor.goToCursorPositionVisible(26, 105);
loader.waitOnClosed();
Expand All @@ -229,9 +225,9 @@ public void checkQuickDocumentation() {

@Test(priority = 4)
public void checkQuickFix() {
projectExplorer.waitItem(PROJECT_NAME_2);
projectExplorer.waitItem(PROJECT_NAME);
projectExplorer.openItemByPath(
PROJECT_NAME_2 + "/src/main/java/org/eclipse/qa/examples/AppController.java");
PROJECT_NAME + "/src/main/java/org/eclipse/qa/examples/AppController.java");
editor.waitActive();
editor.setCursorToLine(29);
editor.typeTextIntoEditor("String s = 5;");
Expand All @@ -250,16 +246,15 @@ public void checkQuickFix() {

@Test(priority = 5)
public void checkOpenDeclaration() {
projectExplorer.waitItem(PROJECT_NAME_2);
projectExplorer.waitItem(PROJECT_NAME);
projectExplorer.openItemByPath(
PROJECT_NAME_2 + "/src/main/java/org/eclipse/qa/examples/AppController.java");
PROJECT_NAME + "/src/main/java/org/eclipse/qa/examples/AppController.java");
editor.goToCursorPositionVisible(26, 13);
editor.openContextMenuOnElementInEditor(" ModelAndView");
editor.clickOnItemInContextMenu(OPEN_DECLARATION);
editor.clickOnItemInContextMenu(FIND_DEFINITION);
editor.waitContextMenuIsNotPresent();
editor.waitTabIsPresent("ModelAndView");
editor.waitTextIntoEditor(expectedTextBeforeDownloadSources);
editor.closeFileByNameWithSaving("ModelAndView");
editor.waitTabIsPresent("ModelAndView.class");
editor.closeFileByNameWithSaving("ModelAndView.class");
}

@Test(priority = 6)
Expand Down Expand Up @@ -295,40 +290,40 @@ public void checkRefactoring() {

@Test(priority = 7)
public void checkNaviFileStructure() {
projectExplorer.waitItem(PROJECT_NAME_2);
projectExplorer.waitItem(PROJECT_NAME);
projectExplorer.openItemByPath(
PROJECT_NAME_2 + "/src/main/java/org/eclipse/qa/examples/AppController.java");
PROJECT_NAME + "/src/main/java/org/eclipse/qa/examples/AppController.java");
editor.openContextMenuInEditor();
editor.clickOnItemInContextMenu(NAVIGATE_FILE_STRUCTURE);
editor.waitContextMenuIsNotPresent();
fileStructure.waitFileStructureFormIsOpen("AppController");
loader.waitOnClosed();
fileStructure.waitExpectedTextInFileStructure(
"handleRequest(HttpServletRequest, HttpServletResponse) : ModelAndView");
"handleRequest(HttpServletRequest, HttpServletResponse):ModelAndView");
loader.waitOnClosed();
fileStructure.selectItemInFileStructure(
"handleRequest(HttpServletRequest, HttpServletResponse) : ModelAndView");
"handleRequest(HttpServletRequest, HttpServletResponse):ModelAndView");
fileStructure.selectItemInFileStructureByDoubleClick(
"handleRequest(HttpServletRequest, HttpServletResponse) : ModelAndView");
"handleRequest(HttpServletRequest, HttpServletResponse):ModelAndView");
fileStructure.waitFileStructureFormIsClosed();
editor.typeTextIntoEditor(Keys.ARROW_LEFT.toString());
editor.waitTextElementsActiveLine("handleRequest");
editor.waitSpecifiedValueForLineAndChar(26, 25);
editor.waitSpecifiedValueForLineAndChar(26, 24);
}

@Test(priority = 8)
public void checkFind() {
projectExplorer.waitItem(PROJECT_NAME_2);
projectExplorer.waitItem(PROJECT_NAME);
projectExplorer.openItemByPath(
PROJECT_NAME_2 + "/src/main/java/org/eclipse/qa/examples/AppController.java");
PROJECT_NAME + "/src/main/java/org/eclipse/qa/examples/AppController.java");
editor.openContextMenuInEditor();
editor.clickOnItemInContextMenu(FIND);
editor.waitContextMenuIsNotPresent();
findText.waitFindTextMainFormIsOpen();
findText.typeTextIntoFindField("class");
findText.waitTextIntoFindField("class");
loader.waitOnClosed();
findText.waitPathIntoRootField("/" + PROJECT_NAME_2 + "/src/main/java/org/eclipse/qa/examples");
findText.waitPathIntoRootField("/" + PROJECT_NAME + "/src/main/java/org/eclipse/qa/examples");
findText.clickOnSearchButtonMainForm();
findText.waitFindInfoPanelIsOpen();
findText.waitExpectedTextInFindInfoPanel("AppController.java");
Expand Down

0 comments on commit 9756840

Please sign in to comment.