Skip to content

Commit

Permalink
Rework and add test for checking of Test Runner plugin (#6401)
Browse files Browse the repository at this point in the history
* add new steps, locators and methods for the tests
  • Loading branch information
Maxim Musienko committed Sep 28, 2017
1 parent a8516c3 commit 393451f
Show file tree
Hide file tree
Showing 13 changed files with 477 additions and 67 deletions.
Expand Up @@ -101,15 +101,6 @@ interface Run {
String DEBUG_CONFIGURATION = "gwt-debug-topmenu/Run/Debug Configurations";
String END_DEBUG_SESSION = "gwt-debug-topmenu/Run/disconnectDebug";
String TEST = "gwt-debug-topmenu/Run/TestingMainGroup";

interface Test {
String TEST_NG_TEST = "topmenu/Run/Test/Run Test";
String TEST_NG_CLASS = "gwt-debug-topmenu/Run/Test/TestNGActionRunClass";
String TEST_NG_PROJECT = "gwt-debug-topmenu/Run/Test/TestNGActionRunAllContext";
String TEST_NG_XML_SUITE = "gwt-debug-topmenu/Run/Test/TestNGActionRunXMLContext";
String JUNIT_TEST = "gwt-debug-topmenu/Run/Test/RunTest";
String JUNIT_PROJECT = "gwt-debug-topmenu/Run/Test/TestJUnitActionRunAllContext";
}
}

interface Profile {
Expand Down Expand Up @@ -198,4 +189,10 @@ interface CommandList {
String ITEM_PREFFIX_ID = "gwt-debug-CommandsGroup/";
String COMMAND_LIST_XPATH = "//div[@id='gwt-debug-dropDownHeader'][2]";
}

public static final String TEST_NG_TEST_DROP_DAWN_ITEM = "topmenu/Run/Test/Run Test";
public static final String JUNIT_TEST_DROP_DAWN_ITEM =
"gwt-debug-topmenu/Run/Test/TestJUnitActionRun";

public static final String TEST_DROP_DAWN_ITEM = "gwt-debug-topmenu/Run/Test/RunTest";
}
Expand Up @@ -24,6 +24,7 @@
import org.eclipse.che.selenium.core.SeleniumWebDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.ExpectedConditions;
Expand Down Expand Up @@ -59,9 +60,9 @@ public class Consoles {
public static final String PREVIEW_URL = "//div[@active]//a[@href]";
public static final String COMMAND_CONSOLE_ID =
"//div[@active]//div[@id='gwt-debug-commandConsoleLines']";

protected final SeleniumWebDriver seleniumWebDriver;
private final Loader loader;
private static final String CONSOLE_PANEL_DRUGGER_CSS = "div.gwt-SplitLayoutPanel-VDragger";

@Inject
public Consoles(SeleniumWebDriver seleniumWebDriver, Loader loader) {
Expand All @@ -73,6 +74,9 @@ public Consoles(SeleniumWebDriver seleniumWebDriver, Loader loader) {
PageFactory.initElements(seleniumWebDriver, this);
}

@FindBy(css = CONSOLE_PANEL_DRUGGER_CSS)
WebElement consolesPanelDrag;

@FindBy(id = PROCESSES_TAB)
WebElement processesTab;

Expand Down Expand Up @@ -300,4 +304,11 @@ public boolean processesMainAreaIsOpen() {
public void clickOnMaximizePanelIcon() {
redrawDriverWait.until(elementToBeClickable(By.xpath(MAXIMIZE_PANEL_ICON))).click();
}

public void dragConsolesInDefinePosition(int verticalShiftInPixels) {
WebElement drag = redrawDriverWait.until(ExpectedConditions.visibilityOf(consolesPanelDrag));
new Actions(seleniumWebDriver)
.dragAndDropBy(drag, verticalShiftInPixels, verticalShiftInPixels)
.perform();
}
}
Expand Up @@ -16,6 +16,7 @@
import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import org.eclipse.che.selenium.core.SeleniumWebDriver;
import org.eclipse.che.selenium.pageobject.Consoles;
Expand Down Expand Up @@ -43,6 +44,8 @@ public class JavaTestRunnerPluginConsole extends Consoles {
private static final String METHODS_MARKED_AS_IGNORED =
"//div[contains(@id,'gwt-uid')]//div[@style='text-decoration: line-through; color: yellow;']";

private static final String TEST_RESULT_NAVIGATION_TREE = "gwt-debug-test-tree-navigation-panel";

@FindAll({@FindBy(xpath = TEST_OUTPUT_XPATH)})
private List<WebElement> testOutput;

Expand All @@ -64,6 +67,9 @@ public class JavaTestRunnerPluginConsole extends Consoles {
@FindAll({@FindBy(xpath = METHODS_MARKED_AS_IGNORED)})
private List<WebElement> ignoredMethods;

@FindBy(id = TEST_RESULT_NAVIGATION_TREE)
private WebElement resultTreeMainForm;

@Inject
public JavaTestRunnerPluginConsole(SeleniumWebDriver seleniumWebDriver, Loader loader) {
super(seleniumWebDriver, loader);
Expand All @@ -86,7 +92,7 @@ public String getTestErrorMessage() {
}

/**
* wait single method in the result tree marked as failed (red color)
* Wait single method in the result tree marked as failed (red color).
*
* @param nameOfFailedMethods name of that should fail
*/
Expand All @@ -96,7 +102,7 @@ public void waitMethodMarkedAsFailed(String nameOfFailedMethods) {
}

/**
* wait single method in the result tree marked as failed (red color)
* Wait single method in the result tree marked as failed (red color).
*
* @param nameOfFailedMethods name of that should fail
*/
Expand All @@ -106,7 +112,7 @@ public void waitMethodMarkedAsIgnored(String nameOfFailedMethods) {
}

/**
* wait single method in the result tree marked as passed (green color)
* Wait single method in the result tree marked as passed (green color).
*
* @param nameOfFailedMethods name of expected method
*/
Expand All @@ -116,25 +122,25 @@ public void waitMethodMarkedAsPassed(String nameOfFailedMethods) {
}

/**
* wait the FQN of the test class in result tree class that has been launched
* Wait the FQN of the test class in result tree class that has been launched.
*
* @param fqn
*/
public void waitFqnOfTesClassInResultTree(String fqn) {
new WebDriverWait(seleniumWebDriver, MINIMUM_SEC)
.until(
ExpectedConditions.visibilityOfAllElementsLocatedBy(
ExpectedConditions.visibilityOfElementLocated(
By.xpath(String.format(TEST_RESULT_TREE_XPATH_TEMPLATE, fqn))));
}

/**
* get all name of the test methods form the test result tree marked with defined status (may be
* passed, failed or ignored)
* Get all name of the test methods form the test result tree marked with defined status (may be
* passed, failed or ignored).
*
* @param methodState the enumeration with defined status
* @return the list with names of methods with defined status
*/
public List<String> getAllMethodsMarkedDefinedStatus(JunitMethodsState methodState) {
public List<String> getAllNamesOfMethodsMarkedDefinedStatus(JunitMethodsState methodState) {
List<String> definedMethods = null;
switch (methodState) {
case PASSED:
Expand All @@ -150,11 +156,73 @@ public List<String> getAllMethodsMarkedDefinedStatus(JunitMethodsState methodSta
return definedMethods;
}

/**
* Get all defined methods from result tree and return as list WebElements.
*
* @param methodState the enumeration with defined status
* @return List WebElements with defined status
*/
public List<WebElement> getAllMethodsMarkedDefinedStatus(JunitMethodsState methodState) {
List<WebElement> definedMethods = null;
switch (methodState) {
case PASSED:
definedMethods = passedMethods;
break;
case FAILED:
definedMethods = failedMethods;
break;
case IGNORED:
definedMethods = ignoredMethods;
break;
}
return definedMethods;
}

private List<String> getAllMetodsWithDefinedStatus(List<WebElement> definedMethod) {
return new WebDriverWait(seleniumWebDriver, MINIMUM_SEC)
.until(ExpectedConditions.visibilityOfAllElements(definedMethod))
.stream()
.map(WebElement::getText)
.collect(Collectors.toList());
}

/**
* Get text from the test result tree. Mote! This method represent only text from test result tree
* without styles and formatting
*
* @return text representation of results of the test result tree widget
*/
public String getTextFromResultTree() {
return new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC)
.until(ExpectedConditions.visibilityOf(resultTreeMainForm))
.getText();
}

/**
* Click on the item in the result tree. If will be some items with the same name - will select
* first.
*
* @param item name of the item (method or fqn of test class) in the test result tree
*/
public void selectItemInResultTree(String item) {
new WebDriverWait(seleniumWebDriver, MINIMUM_SEC)
.until(ExpectedConditions.visibilityOf(resultTreeMainForm))
.findElement(By.xpath(String.format("//div[text()='%s']", item)))
.click();
}

/**
* Click on faled, passed or ignored method on the result tree.
*
* @param nameOfMethod
* @param state
*/
public void selectMethodWithDefinedStatus(JunitMethodsState state, String nameOfMethod) {
getAllMethodsMarkedDefinedStatus(state)
.stream()
.filter(webElement -> Objects.equals(webElement.getText(), nameOfMethod))
.findFirst()
.get()
.click();
}
}
@@ -0,0 +1,131 @@
/*
* Copyright (c) 2012-2017 Red Hat, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.selenium.testrunner;

import static org.eclipse.che.selenium.pageobject.plugins.JavaTestRunnerPluginConsole.JunitMethodsState.FAILED;
import static org.testng.Assert.assertTrue;

import com.google.inject.Inject;
import java.nio.file.Paths;
import org.eclipse.che.api.workspace.server.DtoConverter;
import org.eclipse.che.selenium.core.client.TestCommandServiceClient;
import org.eclipse.che.selenium.core.client.TestProjectServiceClient;
import org.eclipse.che.selenium.core.constant.TestBuildConstants;
import org.eclipse.che.selenium.core.constant.TestMenuCommandsConstants;
import org.eclipse.che.selenium.core.project.ProjectTemplates;
import org.eclipse.che.selenium.core.workspace.TestWorkspace;
import org.eclipse.che.selenium.pageobject.CodenvyEditor;
import org.eclipse.che.selenium.pageobject.Consoles;
import org.eclipse.che.selenium.pageobject.Ide;
import org.eclipse.che.selenium.pageobject.Loader;
import org.eclipse.che.selenium.pageobject.Menu;
import org.eclipse.che.selenium.pageobject.NotificationsPopupPanel;
import org.eclipse.che.selenium.pageobject.ProjectExplorer;
import org.eclipse.che.selenium.pageobject.intelligent.CommandsPalette;
import org.eclipse.che.selenium.pageobject.plugins.JavaTestRunnerPluginConsole;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

/** @author Musienko Maxim */
public class JavaTestPluginJunit4CheckRunSuitesAndScopesTest {
private static final String JUNIT4_PROJECT = "junit4-tests-with-separeted-suites";

private static final String PATH_TO_JUNIT4_TEST_CLASSES =
JUNIT4_PROJECT + "/src/test/java/org/eclipse/che/tests/AppOneTest.java";

private static final int VALUE_OF_SHIFTING_CONSOLES_ALONG_X_AXIS = -100;

@Inject private JavaTestRunnerPluginConsole pluginConsole;
@Inject private ProjectExplorer projectExplorer;
@Inject private Loader loader;
@Inject private NotificationsPopupPanel notifications;
@Inject private Menu menu;

@Inject private TestWorkspace ws;

@Inject private Ide ide;
@Inject private Consoles consoles;
@Inject private CodenvyEditor editor;
@Inject private TestCommandServiceClient testCommandServiceClient;
@Inject private CommandsPalette commandsPalette;
@Inject private TestProjectServiceClient projectServiceClient;

@BeforeClass
public void prepareTestProject() throws Exception {
CompileCommand compileCommand = new CompileCommand();
testCommandServiceClient.createCommand(DtoConverter.asDto(compileCommand), ws.getId());
projectServiceClient.importProject(
ws.getId(),
Paths.get(
getClass()
.getResource("/projects/plugins/JavaTestRunnerPlugin/" + JUNIT4_PROJECT)
.toURI()),
JUNIT4_PROJECT,
ProjectTemplates.CONSOLE_JAVA_SIMPLE);
ide.open(ws);
loader.waitOnClosed();
projectExplorer.waitItem(JUNIT4_PROJECT);
runCompileCommandByPallete(compileCommand);
notifications.waitProgressPopupPanelClose();
consoles.dragConsolesInDefinePosition(VALUE_OF_SHIFTING_CONSOLES_ALONG_X_AXIS);
}

@Test
public void shouldExecuteJUnit4TestClassWithDifferentStatuses() throws InterruptedException {
// given
String expectedResultAfterFirstLaunch =
"Default Suite\n"
+ "org.eclipse.che.tests.AppOneTest\n"
+ "shouldBeIgnoredOfAppOne\n"
+ "shouldSuccessOfAppOne\n"
+ "shouldFailOfAppOne\n"
+ "org.eclipse.che.suite.Junit4TestSuite\n"
+ "org.eclipse.che.tests.AppAnotherTest\n"
+ "shouldFailOfAppAnother\n"
+ "shouldSuccessOfAppAnother\n"
+ "org.eclipse.che.tests.AppAnotherTest\n"
+ "shouldFailOfAppAnother\n"
+ "shouldSuccessOfAppAnother\n"
+ "org.eclipse.che.tests.AppAnotherTest\n"
+ "shouldFailOfAppAnother\n"
+ "shouldSuccessOfAppAnother";

String expectedExceptionForFailedTest =
"java.lang.AssertionError\n"
+ " at org.junit.Assert.fail(Assert.java:86)\n"
+ " at org.junit.Assert.assertTrue(Assert.java:41)";

projectExplorer.quickRevealToItemWithJavaScript(PATH_TO_JUNIT4_TEST_CLASSES);
projectExplorer.selectItem(JUNIT4_PROJECT);
// when
menu.runCommand(
TestMenuCommandsConstants.Run.RUN_MENU,
TestMenuCommandsConstants.Run.TEST,
TestMenuCommandsConstants.JUNIT_TEST_DROP_DAWN_ITEM);

// then
notifications.waitExpectedMessageOnProgressPanelAndClosed("Test runner executed successfully.");
pluginConsole.waitFqnOfTesClassInResultTree("org.eclipse.che.tests.AppAnotherTest");
assertTrue(pluginConsole.getTextFromResultTree().equals(expectedResultAfterFirstLaunch));
pluginConsole.waitFqnOfTesClassInResultTree("org.eclipse.che.tests.AppOneTest");
pluginConsole.waitMethodMarkedAsPassed("shouldSuccessOfAppOne");
pluginConsole.waitMethodMarkedAsFailed("shouldFailOfAppOne");
pluginConsole.waitMethodMarkedAsIgnored("shouldBeIgnoredOfAppOne");
pluginConsole.selectMethodWithDefinedStatus(FAILED, "shouldFailOfAppAnother");
assertTrue(pluginConsole.getTestErrorMessage().startsWith(expectedExceptionForFailedTest));
}

private void runCompileCommandByPallete(CompileCommand compileCommand) {
commandsPalette.openCommandPalette();
commandsPalette.startCommandByDoubleClick(compileCommand.getName());
consoles.waitExpectedTextIntoConsole(TestBuildConstants.BUILD_SUCCESS);
}
}

0 comments on commit 393451f

Please sign in to comment.