]> source.dussan.org Git - archiva.git/commitdiff
Adding fixes for chrome WebDriver
authorMartin Stockhammer <martin_s@apache.org>
Fri, 9 Jun 2017 21:19:58 +0000 (23:19 +0200)
committerMartin Stockhammer <martin_s@apache.org>
Fri, 9 Jun 2017 21:19:58 +0000 (23:19 +0200)
archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/RepositoryAdminTest.java
archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/parent/AbstractSeleniumTest.java
archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/tools/WebdriverUtility.java

index d9d0da10b7f0448fae72bf4afd94eb8d7bad5ba3..6dbf5ebc6d7b0b7ffc29d0d3b89af0bb63c4b03c 100644 (file)
@@ -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" ));
index 2cfe0705cd74156439934d79cc2f933b2176a867..7922997e58a1c197cd095b91be39d036b5d5aa16 100644 (file)
@@ -620,6 +620,32 @@ public abstract class AbstractSeleniumTest
         }
     }
 
+    public <V> V tryClick(By clickableLocator, Function<? super WebDriver, V> 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 <code>el</code> and waits for the conditions.
      * If the condition is not fulfilled in <code>maxWaitTimeInS</code>, the click is executed again
index 12546c340e6d1621d75aaa7bf3f4424d30999681..a1fbca3bf0114d8abca3c3ab37c1c33224a8c800 100644 (file)
@@ -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 );
                 }
             }