From: Martin Stockhammer Date: Fri, 9 Jun 2017 21:19:58 +0000 (+0200) Subject: Adding fixes for chrome WebDriver X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2513029e2e6c3333073c265fa496bc50fb2e405d;p=archiva.git Adding fixes for chrome WebDriver --- diff --git a/archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/RepositoryAdminTest.java b/archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/RepositoryAdminTest.java index d9d0da10b..6dbf5ebc6 100644 --- a/archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/RepositoryAdminTest.java +++ b/archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/RepositoryAdminTest.java @@ -66,9 +66,11 @@ public class RepositoryAdminTest el.click(); wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("remote-repositories-view-a"))); - el = wait.until(ExpectedConditions.elementToBeClickable( By.id("menu-proxy-connectors-list-a") )); - el.click(); - wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("proxy-connectors-view-tabs-a-network-proxies-grid"))); + tryClick(By.id("menu-proxy-connectors-list-a"), + ExpectedConditions.visibilityOfElementLocated(By.id("proxy-connectors-view-tabs-a-network-proxies-grid")), + "Network proxies not available", + 3,10 + ); wait.until(ExpectedConditions.textToBePresentInElementLocated(By.id("main-content"), "Proxy Connectors")); // proxy connect wait.until(ExpectedConditions.textToBePresentInElementLocated(By.id("proxy-connectors-view"), "central" )); diff --git a/archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/parent/AbstractSeleniumTest.java b/archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/parent/AbstractSeleniumTest.java index 2cfe0705c..7922997e5 100644 --- a/archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/parent/AbstractSeleniumTest.java +++ b/archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/parent/AbstractSeleniumTest.java @@ -620,6 +620,32 @@ public abstract class AbstractSeleniumTest } } + public V tryClick(By clickableLocator, Function conditions, String message, int attempts, int maxWaitTimeInS) { + + int count = attempts; + WebDriverWait wait = new WebDriverWait( getWebDriver(), maxWaitTimeInS ); + V result = null; + Exception ex = null; + while(count>0) + { + try + { + WebElement el = wait.until(ExpectedConditions.elementToBeClickable( clickableLocator )); + el.click(); + result = wait.until( conditions ); + count=0; + ex = null; + } catch (Exception e) { + ex = e; + count--; + } + } + if (ex!=null) { + Assert.fail( message); + } + return result; + } + /** * Executes click() on the WebElement el and waits for the conditions. * If the condition is not fulfilled in maxWaitTimeInS, the click is executed again diff --git a/archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/tools/WebdriverUtility.java b/archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/tools/WebdriverUtility.java index 12546c340..a1fbca3bf 100644 --- a/archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/tools/WebdriverUtility.java +++ b/archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/tools/WebdriverUtility.java @@ -23,6 +23,7 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; import org.openqa.selenium.*; import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.htmlunit.HtmlUnitDriver; import org.openqa.selenium.ie.InternetExplorerDriver; @@ -69,13 +70,17 @@ public class WebdriverUtility try { if ( StringUtils.contains(seleniumBrowser, "chrome")) { + ChromeOptions options = new ChromeOptions(); + options.addArguments("start-maximized"); if (seleniumRemote) { + DesiredCapabilities capabilities = DesiredCapabilities.chrome(); + capabilities.setCapability( ChromeOptions.CAPABILITY, options ); return new RemoteWebDriver( new URL( "http://" + seleniumHost + ":" + seleniumPort + "/wd/hub" ), - DesiredCapabilities.chrome() + capabilities ); } else { - return new ChromeDriver( ); + return new ChromeDriver( options ); } }