Repository: geode Updated Branches: refs/heads/develop ef86239f8 -> df8730d9d
GEODE-2201 Make UITests a bit more resilient - Increase some timeouts - Avoid StaleElementReferenceExceptions by retrying the element retrieval. Project: http://git-wip-us.apache.org/repos/asf/geode/repo Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/d4276136 Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/d4276136 Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/d4276136 Branch: refs/heads/develop Commit: d4276136337d2c9bee7336bafa281f2301af2a40 Parents: 1d951e3 Author: Jens Deppe <jde...@pivotal.io> Authored: Thu Dec 8 20:56:44 2016 -0800 Committer: Jens Deppe <jde...@pivotal.io> Committed: Thu Dec 8 20:56:44 2016 -0800 ---------------------------------------------------------------------- .../tests/rules/ScreenshotOnFailureRule.java | 2 +- .../tools/pulse/tests/rules/WebDriverRule.java | 4 +- .../tools/pulse/tests/ui/PulseTestUtils.java | 54 +++++++++++--------- 3 files changed, 33 insertions(+), 27 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/geode/blob/d4276136/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/rules/ScreenshotOnFailureRule.java ---------------------------------------------------------------------- diff --git a/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/rules/ScreenshotOnFailureRule.java b/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/rules/ScreenshotOnFailureRule.java index 91465f0..3728015 100644 --- a/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/rules/ScreenshotOnFailureRule.java +++ b/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/rules/ScreenshotOnFailureRule.java @@ -47,7 +47,7 @@ public class ScreenshotOnFailureRule extends TestWatcher { try { File screenshot = new File("build/screenshots/" + screenshotName + ".png"); FileUtils.copyFile(tempFile, screenshot); - System.out.println("Screenshot saved to: " + screenshot.getCanonicalPath()); + System.err.println("Screenshot saved to: " + screenshot.getCanonicalPath()); } catch (IOException e) { throw new Error(e); } http://git-wip-us.apache.org/repos/asf/geode/blob/d4276136/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/rules/WebDriverRule.java ---------------------------------------------------------------------- diff --git a/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/rules/WebDriverRule.java b/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/rules/WebDriverRule.java index e273557..8a4e7f4 100644 --- a/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/rules/WebDriverRule.java +++ b/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/rules/WebDriverRule.java @@ -98,8 +98,8 @@ public class WebDriverRule extends ExternalResource { driver = new PhantomJSDriver(capabilities); driver.manage().window().maximize(); - driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); - driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS); + driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); + driver.manage().timeouts().pageLoadTimeout(300, TimeUnit.SECONDS); } public WebElement waitForElementById(final String id) { http://git-wip-us.apache.org/repos/asf/geode/blob/d4276136/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/ui/PulseTestUtils.java ---------------------------------------------------------------------- diff --git a/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/ui/PulseTestUtils.java b/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/ui/PulseTestUtils.java index c6ed3ff..076229e 100644 --- a/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/ui/PulseTestUtils.java +++ b/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/ui/PulseTestUtils.java @@ -25,7 +25,9 @@ import java.util.TreeMap; import java.util.function.Supplier; import org.openqa.selenium.By; +import org.openqa.selenium.StaleElementReferenceException; import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebDriverException; import org.openqa.selenium.WebElement; import org.openqa.selenium.interactions.Actions; import org.openqa.selenium.support.ui.ExpectedCondition; @@ -56,38 +58,42 @@ public final class PulseTestUtils { public static int maxWaitTime = 30; public static WebElement waitForElementWithId(String id) { + return waitForElement(By.id(id)); + } + + public static WebElement waitForElement(By by) { WebElement element = (new WebDriverWait(driverProvider.get(), maxWaitTime)) - .until(new ExpectedCondition<WebElement>() { - @Override - public WebElement apply(WebDriver d) { - return d.findElement(By.id(id)); - } - }); + .until((ExpectedCondition<WebElement>) d -> d.findElement(by)); assertNotNull(element); return element; } - - public static WebElement findElementUsingXpath(String xpath) { - return getDriver().findElement(By.xpath(xpath)); - } - public static void clickElementUsingId(String id) { - waitForElementWithId(id).click(); + WebDriverException lastException = null; + int attempts = 3; + while (attempts > 0) { + try { + waitForElementWithId(id).click(); + return; + } catch (StaleElementReferenceException sere) { + lastException = sere; + } + attempts++; + } + + throw lastException; } public static void clickElementUsingXpath(String xpath) { - findElementUsingXpath(xpath).click(); + findElementByXpath(xpath).click(); } - public static void sendKeysUsingId(String Id, String textToEnter) { waitForElementWithId(Id).sendKeys(textToEnter); } - public static WebElement findElementByXpath(String xpath) { - return getDriver().findElement(By.xpath(xpath)); + return waitForElement(By.xpath(xpath)); } public static String getTextUsingXpath(String xpath) { @@ -99,25 +105,25 @@ public final class PulseTestUtils { } public static String getPersistanceEnabled(Region r) { - String persitance = null; + String persistence = null; if (r.getPersistentEnabled()) { - persitance = "ON"; + persistence = "ON"; } else if (!r.getPersistentEnabled()) { - persitance = "OFF"; + persistence = "OFF"; } - return persitance; + return persistence; } public static String getPersistanceEnabled(String trueOrFalse) { - String persitance = null; + String persistence = null; if (trueOrFalse.contains("true")) { - persitance = "ON"; + persistence = "ON"; } else if (trueOrFalse.contains("false")) { - persitance = "OFF"; + persistence = "OFF"; } - return persitance; + return persistence; } public static void validateServerGroupGridData() {