-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rework and add test for checking of Test Runner plugin #6401
Changes from 7 commits
ab18801
7151deb
5e7c227
d3c23df
cb85518
acb14d0
27e9b0d
775e9a2
c88a850
439001d
41f149b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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; | ||
|
||
|
@@ -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); | ||
|
@@ -123,7 +129,7 @@ public void waitMethodMarkedAsPassed(String nameOfFailedMethods) { | |
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)))); | ||
} | ||
|
||
|
@@ -134,7 +140,7 @@ public void waitFqnOfTesClassInResultTree(String fqn) { | |
* @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: | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Uppercase? |
||
* 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(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
/* | ||
* 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; | ||
|
||
public class JavaTestPluginJuinit4CheckRunSuitesAndScopesTest { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo in the name of the class |
||
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 String PATH_TO_JUNIT4_TEST_SUITE = | ||
JUNIT4_PROJECT + "/src/tests/java/org/examples/suite/Junit4TestSuite.java"; | ||
|
||
@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(-100); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
@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); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the name of the method is self descriptive I don't want to see any java doc.
Review all javadocs you have added in this PR. https://dev.liferay.com/participate/javadoc-guidelines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name of the variables
xoffset
seems weird.