Change steps in the test and rework depended Page Object for increasing stability tests (#6808) (#6826)

add steps and changes to Page Object for increasing stability tests
6.19.x
Maxim Musienko 2017-10-19 17:37:00 +03:00 committed by GitHub
parent 1373dda147
commit 9e8d987d7b
3 changed files with 83 additions and 66 deletions

View File

@ -10,7 +10,6 @@
*/
package org.eclipse.che.selenium.pageobject;
import static org.eclipse.che.selenium.core.constant.TestTimeoutsConstants.ELEMENT_TIMEOUT_SEC;
import static org.eclipse.che.selenium.core.constant.TestTimeoutsConstants.LOAD_PAGE_TIMEOUT_SEC;
import static org.eclipse.che.selenium.core.constant.TestTimeoutsConstants.MINIMUM_SEC;
import static org.eclipse.che.selenium.core.constant.TestTimeoutsConstants.REDRAW_UI_ELEMENTS_TIMEOUT_SEC;
@ -42,6 +41,7 @@ public class Menu {
private final SeleniumWebDriver seleniumWebDriver;
private final Loader loader;
private final ActionsFactory actionsFactory;
private WebDriverWait redrawMenuItemsWait;
@Inject
public Menu(SeleniumWebDriver seleniumWebDriver, Loader loader, ActionsFactory actionsFactory) {
@ -49,6 +49,7 @@ public class Menu {
this.loader = loader;
this.actionsFactory = actionsFactory;
PageFactory.initElements(seleniumWebDriver, this);
redrawMenuItemsWait = new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC);
}
private static String ENABLED_CSS_VALUE = "rgba(255, 255, 255, 1)";
@ -59,8 +60,7 @@ public class Menu {
* @param idCommand
*/
public void runCommand(String idCommand) {
new WebDriverWait(seleniumWebDriver, ELEMENT_TIMEOUT_SEC)
.until(ExpectedConditions.visibilityOfElementLocated(By.id(idCommand)));
redrawMenuItemsWait.until(ExpectedConditions.visibilityOfElementLocated(By.id(idCommand)));
clickOnCommand(idCommand);
loader.waitOnClosed();
}
@ -72,8 +72,7 @@ public class Menu {
* @param userDelay delay for waiting active state menu defined by user
*/
public void runCommand(String idCommand, int userDelay) {
new WebDriverWait(seleniumWebDriver, userDelay)
.until(ExpectedConditions.visibilityOfElementLocated(By.id(idCommand)));
redrawMenuItemsWait.until(ExpectedConditions.visibilityOfElementLocated(By.id(idCommand)));
clickOnCommand(idCommand);
loader.waitOnClosed();
}
@ -85,18 +84,18 @@ public class Menu {
* @param idCommandName
*/
public void runAndWaitCommand(final String idTopMenuCommand, final String idCommandName) {
(new WebDriverWait(seleniumWebDriver, LOAD_PAGE_TIMEOUT_SEC))
.until(
new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(WebDriver driver) {
driver.findElement(By.id(idTopMenuCommand)).click();
return driver.findElement(By.id(idCommandName)).isDisplayed();
}
});
redrawMenuItemsWait.until(
new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(WebDriver driver) {
driver.findElement(By.id(idTopMenuCommand)).click();
return driver.findElement(By.id(idCommandName)).isDisplayed();
}
});
seleniumWebDriver.findElement(By.id(idCommandName)).click();
(new WebDriverWait(seleniumWebDriver, LOAD_PAGE_TIMEOUT_SEC))
.until(ExpectedConditions.invisibilityOfElementLocated(By.id(idCommandName)));
redrawMenuItemsWait.until(
ExpectedConditions.invisibilityOfElementLocated(By.id(idCommandName)));
}
/**
@ -108,27 +107,29 @@ public class Menu {
public void runCommand(final String idTopMenuCommand, final String idCommandName) {
loader.waitOnClosed();
try {
new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC)
redrawMenuItemsWait
.until(ExpectedConditions.visibilityOfElementLocated(By.id(idTopMenuCommand)))
.click();
} catch (WebDriverException ex) {
LOG.error(ex.getLocalizedMessage(), ex);
WaitUtils.sleepQuietly(REDRAW_UI_ELEMENTS_TIMEOUT_SEC, TimeUnit.MILLISECONDS);
new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC)
redrawMenuItemsWait
.until(ExpectedConditions.visibilityOfElementLocated(By.id(idTopMenuCommand)))
.click();
}
try {
new WebDriverWait(seleniumWebDriver, ELEMENT_TIMEOUT_SEC)
redrawMenuItemsWait
.until(ExpectedConditions.visibilityOfElementLocated(By.id(idCommandName)))
.click();
} catch (TimeoutException e) {
seleniumWebDriver.findElement(By.id(idTopMenuCommand)).click();
new WebDriverWait(seleniumWebDriver, MINIMUM_SEC)
redrawMenuItemsWait
.until(ExpectedConditions.visibilityOfElementLocated(By.id(idCommandName)))
.click();
}
redrawMenuItemsWait.until(
ExpectedConditions.invisibilityOfElementLocated(By.id(idCommandName)));
}
/**
@ -142,29 +143,30 @@ public class Menu {
loader.waitOnClosed();
clickOnCommand(idTopMenuCommand);
try {
new WebDriverWait(seleniumWebDriver, ELEMENT_TIMEOUT_SEC)
.until(ExpectedConditions.visibilityOfElementLocated(By.id(idCommandName)));
redrawMenuItemsWait.until(
ExpectedConditions.visibilityOfElementLocated(By.id(idCommandName)));
} catch (TimeoutException e) {
LOG.error(e.getLocalizedMessage(), e);
clickOnCommand(idTopMenuCommand);
}
new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC)
.until(ExpectedConditions.elementToBeClickable(By.id(idCommandName)));
redrawMenuItemsWait.until(ExpectedConditions.elementToBeClickable(By.id(idCommandName)));
actionsFactory
.createAction(seleniumWebDriver)
.moveToElement(seleniumWebDriver.findElement(By.id(idCommandName)))
.perform();
//if element If the element is not drawn in time, in the catch block call submenu again
try {
new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC)
.until(ExpectedConditions.visibilityOfElementLocated(By.id(idSubCommandName)));
redrawMenuItemsWait.until(
ExpectedConditions.visibilityOfElementLocated(By.id(idSubCommandName)));
} catch (TimeoutException e) {
WaitUtils.sleepQuietly(1);
seleniumWebDriver.findElement(By.id(idCommandName)).click();
new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC)
.until(ExpectedConditions.visibilityOfElementLocated(By.id(idSubCommandName)));
redrawMenuItemsWait.until(
ExpectedConditions.visibilityOfElementLocated(By.id(idSubCommandName)));
}
seleniumWebDriver.findElement(By.id(idSubCommandName)).click();
redrawMenuItemsWait.until(
ExpectedConditions.invisibilityOfElementLocated(By.id(idCommandName)));
}
/**
@ -176,33 +178,35 @@ public class Menu {
*/
public void runCommandByXpath(
String idTopMenuCommand, String idCommandName, String xpathSubCommandName) {
loader.waitOnClosed();
clickOnCommand(idTopMenuCommand);
try {
new WebDriverWait(seleniumWebDriver, ELEMENT_TIMEOUT_SEC)
.until(ExpectedConditions.visibilityOfElementLocated(By.id(idCommandName)));
redrawMenuItemsWait.until(
ExpectedConditions.visibilityOfElementLocated(By.id(idCommandName)));
} catch (TimeoutException e) {
LOG.error(e.getLocalizedMessage(), e);
clickOnCommand(idTopMenuCommand);
}
new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC)
.until(ExpectedConditions.elementToBeClickable(By.id(idCommandName)));
redrawMenuItemsWait.until(ExpectedConditions.elementToBeClickable(By.id(idCommandName)));
actionsFactory
.createAction(seleniumWebDriver)
.moveToElement(seleniumWebDriver.findElement(By.id(idCommandName)))
.perform();
//if element If the element is not drawn in time, in the catch block call submenu again
try {
new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC)
.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xpathSubCommandName)));
redrawMenuItemsWait.until(
ExpectedConditions.visibilityOfElementLocated(By.xpath(xpathSubCommandName)));
} catch (TimeoutException e) {
LOG.error(e.getLocalizedMessage(), e);
WaitUtils.sleepQuietly(MINIMUM_SEC);
seleniumWebDriver.findElement(By.id(idCommandName)).click();
new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC)
.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xpathSubCommandName)));
redrawMenuItemsWait.until(
ExpectedConditions.visibilityOfElementLocated(By.xpath(xpathSubCommandName)));
}
seleniumWebDriver.findElement(By.xpath(xpathSubCommandName)).click();
redrawMenuItemsWait.until(
ExpectedConditions.invisibilityOfElementLocated(By.id(idCommandName)));
}
/**
@ -212,18 +216,17 @@ public class Menu {
*/
public void clickOnCommand(final String idTopMenuCommand) {
//TODO Use attributes enabled/disabled instead of css values
new WebDriverWait(seleniumWebDriver, LOAD_PAGE_TIMEOUT_SEC)
.until(
new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(WebDriver driver) {
WebElement element = driver.findElement(By.id(idTopMenuCommand));
boolean isTrue = element.getCssValue("color").equals(ENABLED_CSS_VALUE);
Actions actions = actionsFactory.createAction(seleniumWebDriver);
actions.moveToElement(element).click().perform();
return isTrue;
}
});
redrawMenuItemsWait.until(
new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(WebDriver driver) {
WebElement element = driver.findElement(By.id(idTopMenuCommand));
boolean isTrue = element.getCssValue("color").equals(ENABLED_CSS_VALUE);
Actions actions = actionsFactory.createAction(seleniumWebDriver);
actions.moveToElement(element).click().perform();
return isTrue;
}
});
}
/**

View File

@ -10,6 +10,7 @@
*/
package org.eclipse.che.selenium.pageobject.intelligent;
import static java.lang.String.format;
import static org.eclipse.che.selenium.core.constant.TestTimeoutsConstants.REDRAW_UI_ELEMENTS_TIMEOUT_SEC;
import com.google.inject.Inject;
@ -143,13 +144,13 @@ public class CommandsPalette {
public void commandIsExists(String commandName) {
redrawUiElementTimeout.until(
ExpectedConditions.visibilityOfElementLocated(
By.xpath(String.format(Locators.COMMANDS, commandName))));
By.xpath(format(Locators.COMMANDS, commandName))));
}
public void commandIsNotExists(String commandName) {
redrawUiElementTimeout.until(
ExpectedConditions.invisibilityOfElementLocated(
By.xpath(String.format(Locators.COMMANDS, commandName))));
By.xpath(format(Locators.COMMANDS, commandName))));
}
/**
@ -158,11 +159,13 @@ public class CommandsPalette {
* @param commandName name of the command
*/
public void startCommandByDoubleClick(String commandName) {
actions
.doubleClick(
seleniumWebDriver.findElement(By.xpath(String.format(Locators.COMMANDS, commandName))))
.build()
.perform();
String locatorToCurrentCommand = format(Locators.COMMANDS, commandName);
WebElement currentCommand =
redrawUiElementTimeout.until(
ExpectedConditions.visibilityOfElementLocated(By.xpath(locatorToCurrentCommand)));
actions.doubleClick(currentCommand).perform();
redrawUiElementTimeout.until(
ExpectedConditions.invisibilityOfElementLocated(By.xpath(locatorToCurrentCommand)));
}
/**
@ -171,8 +174,17 @@ public class CommandsPalette {
* @param commandName name of the command
*/
public void startCommandByEnterKey(String commandName) {
seleniumWebDriver.findElement(By.xpath(String.format(Locators.COMMANDS, commandName))).click();
actionsFactory.createAction(seleniumWebDriver).sendKeys(Keys.ENTER.toString()).perform();
String locatorToCurrentCommand = format(Locators.COMMANDS, commandName);
WebElement currentCommand =
redrawUiElementTimeout.until(
ExpectedConditions.visibilityOfElementLocated(By.xpath(locatorToCurrentCommand)));
seleniumWebDriver.findElement(By.xpath(locatorToCurrentCommand)).click();
actionsFactory
.createAction(seleniumWebDriver)
.sendKeys(currentCommand, Keys.ENTER.toString())
.perform();
redrawUiElementTimeout.until(
ExpectedConditions.invisibilityOfElementLocated(By.xpath(locatorToCurrentCommand)));
}
/**

View File

@ -10,6 +10,9 @@
*/
package org.eclipse.che.selenium.debugger;
import static org.eclipse.che.selenium.pageobject.debug.DebugPanel.DebuggerButtonsPanel.BTN_DISCONNECT;
import static org.eclipse.che.selenium.pageobject.debug.DebugPanel.DebuggerButtonsPanel.RESUME_BTN_ID;
import com.google.inject.Inject;
import java.nio.file.Paths;
import org.eclipse.che.selenium.core.client.TestCommandServiceClient;
@ -113,8 +116,7 @@ public class InnerClassAndLambdaDebuggingTest {
@AfterMethod
public void stopDebug() {
debugPanel.removeAllBreakpoints();
menu.runCommand(
TestMenuCommandsConstants.Run.RUN_MENU, TestMenuCommandsConstants.Run.END_DEBUG_SESSION);
debugPanel.clickOnButton(BTN_DISCONNECT);
}
@Test
@ -122,7 +124,7 @@ public class InnerClassAndLambdaDebuggingTest {
// when
editor.setCursorToLine(37);
editor.setBreakpoint(37);
debugPanel.clickOnButton(DebugPanel.DebuggerButtonsPanel.RESUME_BTN_ID);
debugPanel.clickOnButton(RESUME_BTN_ID);
// then
editor.waitActiveBreakpoint(37);
@ -134,7 +136,7 @@ public class InnerClassAndLambdaDebuggingTest {
// when
editor.setCursorToLine(53);
editor.setBreakpoint(53);
debugPanel.clickOnButton(DebugPanel.DebuggerButtonsPanel.RESUME_BTN_ID);
debugPanel.clickOnButton(RESUME_BTN_ID);
// then
editor.waitActiveBreakpoint(53);
@ -146,7 +148,7 @@ public class InnerClassAndLambdaDebuggingTest {
// when
editor.setCursorToLine(64);
editor.setBreakpoint(64);
debugPanel.clickOnButton(DebugPanel.DebuggerButtonsPanel.RESUME_BTN_ID);
debugPanel.clickOnButton(RESUME_BTN_ID);
// then
editor.waitActiveBreakpoint(64);
@ -158,7 +160,7 @@ public class InnerClassAndLambdaDebuggingTest {
// when
editor.setCursorToLine(72);
editor.setBreakpoint(72);
debugPanel.clickOnButton(DebugPanel.DebuggerButtonsPanel.RESUME_BTN_ID);
debugPanel.clickOnButton(RESUME_BTN_ID);
// then
editor.waitActiveBreakpoint(72);
@ -171,21 +173,21 @@ public class InnerClassAndLambdaDebuggingTest {
editor.setCursorToLine(79);
editor.setBreakPointAndWaitActiveState(79);
editor.setBreakPointAndWaitActiveState(87);
debugPanel.clickOnButton(DebugPanel.DebuggerButtonsPanel.RESUME_BTN_ID);
debugPanel.clickOnButton(RESUME_BTN_ID);
// then
editor.waitActiveBreakpoint(79);
debugPanel.waitTextInVariablesPanel("j=1");
// when
debugPanel.clickOnButton(DebugPanel.DebuggerButtonsPanel.RESUME_BTN_ID);
debugPanel.clickOnButton(RESUME_BTN_ID);
// then
editor.waitActiveBreakpoint(79);
debugPanel.waitTextInVariablesPanel("j=2");
// when
debugPanel.clickOnButton(DebugPanel.DebuggerButtonsPanel.RESUME_BTN_ID);
debugPanel.clickOnButton(RESUME_BTN_ID);
// then
editor.waitActiveBreakpoint(87);