From 7fdb0d105a3874f5bd839640dd6ae2b69f328321 Mon Sep 17 00:00:00 2001 From: Ihor Okhrimenko Date: Thu, 26 Jul 2018 17:42:45 +0300 Subject: [PATCH] Rework methods logic --- .../webdriver/SeleniumWebDriverHelper.java | 86 +++++++++++++++---- 1 file changed, 70 insertions(+), 16 deletions(-) diff --git a/selenium/che-selenium-core/src/main/java/org/eclipse/che/selenium/core/webdriver/SeleniumWebDriverHelper.java b/selenium/che-selenium-core/src/main/java/org/eclipse/che/selenium/core/webdriver/SeleniumWebDriverHelper.java index 2b8b6094568..13887e8cca0 100644 --- a/selenium/che-selenium-core/src/main/java/org/eclipse/che/selenium/core/webdriver/SeleniumWebDriverHelper.java +++ b/selenium/che-selenium-core/src/main/java/org/eclipse/che/selenium/core/webdriver/SeleniumWebDriverHelper.java @@ -32,7 +32,6 @@ import java.io.IOException; import java.nio.file.Path; import java.util.List; -import java.util.Set; import org.eclipse.che.selenium.core.SeleniumWebDriver; import org.eclipse.che.selenium.core.action.ActionsFactory; import org.eclipse.che.selenium.core.utils.WaitUtils; @@ -394,7 +393,7 @@ public List waitPresenceOfAllElements(By elementsLocator, int timeou * @param text text for sending */ public void waitAndSendKeysTo(By elementLocator, String text) { - waitVisibility(elementLocator).sendKeys(text); + waitAndSendKeysTo(elementLocator, text, DEFAULT_TIMEOUT); } /** @@ -435,7 +434,19 @@ public void sendKeys(String text) { * @return text which extracted from element by {@link WebElement#getAttribute(String)} */ public String waitVisibilityAndGetValue(By elementLocator) { - return waitVisibility(elementLocator).getAttribute("value"); + return waitVisibilityAndGetValue(elementLocator, DEFAULT_TIMEOUT); + } + + /** + * Waits during {@code timeout} visibility of {@link WebElement} with specified {@code + * elementLocator} and gets text. + * + * @param elementLocator locator of element from which text should be got + * @param timeout waiting time in seconds + * @return text which extracted from element by {@link WebElement#getAttribute(String)} + */ + public String waitVisibilityAndGetValue(By elementLocator, int timeout) { + return waitVisibilityAndGetAttribute(elementLocator, "value", timeout); } /** @@ -445,7 +456,18 @@ public String waitVisibilityAndGetValue(By elementLocator) { * @return text which extracted from element by {@link WebElement#getAttribute(String)} */ public String waitVisibilityAndGetValue(WebElement webElement) { - return waitVisibility(webElement).getAttribute("value"); + return waitVisibilityAndGetValue(webElement, DEFAULT_TIMEOUT); + } + + /** + * Waits during {@code timeout} visibility of provided {@code webElement} and gets text. + * + * @param webElement element, text from which should be got + * @param timeout waiting time in seconds + * @return text which extracted from element by {@link WebElement#getAttribute(String)} + */ + public String waitVisibilityAndGetValue(WebElement webElement, int timeout) { + return waitVisibilityAndGetAttribute(webElement, "value", timeout); } /** @@ -502,7 +524,7 @@ public String waitVisibilityAndGetAttribute(WebElement element, String attribute * @return element text by {@link WebElement#getText()} */ public String waitVisibilityAndGetText(By elementLocator) { - return waitVisibility(elementLocator).getText(); + return waitVisibilityAndGetText(elementLocator, DEFAULT_TIMEOUT); } /** @@ -524,7 +546,18 @@ public String waitVisibilityAndGetText(By elementLocator, int timeout) { * @return element text by {@link WebElement#getText()} */ public String waitVisibilityAndGetText(WebElement webElement) { - return waitVisibility(webElement).getText(); + return waitVisibilityAndGetText(webElement, DEFAULT_TIMEOUT); + } + + /** + * Waits during {@code timeout} visibility of provided {@code webElement} and gets text. + * + * @param webElement element from which text should be got + * @param timeout waiting time in seconds + * @return element text by {@link WebElement#getText()} + */ + public String waitVisibilityAndGetText(WebElement webElement, int timeout) { + return waitVisibility(webElement, timeout).getText(); } /** @@ -541,7 +574,7 @@ public void waitValueEqualsTo(By elementLocator, String expectedValue, int timeo .get(timeout) .until( (ExpectedCondition) - driver -> waitVisibilityAndGetValue(elementLocator).equals(expectedValue)); + driver -> waitVisibilityAndGetValue(elementLocator, timeout).equals(expectedValue)); } /** @@ -568,7 +601,7 @@ public void waitValueEqualsTo(WebElement webElement, String expectedValue, int t .get(timeout) .until( (ExpectedCondition) - driver -> waitVisibilityAndGetValue(webElement).equals(expectedValue)); + driver -> waitVisibilityAndGetValue(webElement, timeout).equals(expectedValue)); } /** @@ -597,7 +630,8 @@ public void waitValueContains(WebElement element, String expectedText, int timeo .get(timeout) .until( (ExpectedCondition) - driver -> waitVisibility(element).getAttribute("value").contains(expectedText)); + driver -> + waitVisibility(element, timeout).getAttribute("value").contains(expectedText)); } /** @@ -652,7 +686,7 @@ public void waitTextEqualsTo(By elementLocator, String expectedText, int timeout .get(timeout) .until( (ExpectedCondition) - driver -> waitVisibilityAndGetText(elementLocator).equals(expectedText)); + driver -> waitVisibilityAndGetText(elementLocator, timeout).equals(expectedText)); } /** @@ -679,7 +713,7 @@ public void waitTextEqualsTo(WebElement webElement, String expectedText, int tim .get(timeout) .until( (ExpectedCondition) - driver -> waitVisibilityAndGetText(webElement).equals(expectedText)); + driver -> waitVisibilityAndGetText(webElement, timeout).equals(expectedText)); } /** @@ -765,7 +799,7 @@ public void waitTextIsNotPresented(WebElement element, String expectedText, int .get(timeout) .until( (ExpectedCondition) - driver -> !(waitVisibilityAndGetText(element).contains(expectedText))); + driver -> !(waitVisibilityAndGetText(element, timeout).contains(expectedText))); } /** @@ -1081,12 +1115,32 @@ public String switchToIdeFrameAndWaitAvailability(int timeout) { public void waitOpenedSomeWin() { webDriverWaitFactory .get(WIDGET_TIMEOUT_SEC) + .until( + (ExpectedCondition) driver -> seleniumWebDriver.getWindowHandles().size() > 1); + } + + /** + * Waits during {@code timeout} until count of opened browser tabs are equals to {@code + * expectedCount}. + * + * @param expectedCount count of the opened browsers tabs + * @param timeout waiting time in seconds + */ + public void waitWindowsCount(int expectedCount, int timeout) { + webDriverWaitFactory + .get(timeout) .until( (ExpectedCondition) - input -> { - Set driverWindows = seleniumWebDriver.getWindowHandles(); - return (driverWindows.size() > 1); - }); + driver -> seleniumWebDriver.getWindowHandles().size() == expectedCount); + } + + /** + * Waits until count of opened browser tabs are equals to {@code expectedCount}. + * + * @param expectedCount count of the opened browsers tabs + */ + public void waitWindowsCount(int expectedCount) { + waitWindowsCount(expectedCount, WIDGET_TIMEOUT_SEC); } /**