]> source.dussan.org Git - archiva.git/commitdiff
Fixing another timing issue with JS tests
authorMartin Stockhammer <martin_s@apache.org>
Tue, 13 Jun 2017 14:39:33 +0000 (16:39 +0200)
committerMartin Stockhammer <martin_s@apache.org>
Tue, 13 Jun 2017 14:39:33 +0000 (16:39 +0200)
archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/ArchivaAdminTest.java
archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/parent/AbstractArchivaTest.java
archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/parent/AbstractSeleniumTest.java

index 37805588a369726d4641682e8707562584925dfe..5e7cb0f4da2a77f4bc7bc772bd2f9f8dba7f32a2 100644 (file)
@@ -22,10 +22,15 @@ package org.apache.archiva.web.test;
 import org.apache.archiva.web.test.parent.AbstractArchivaTest;
 import org.junit.Test;
 import org.openqa.selenium.By;
+import org.openqa.selenium.JavascriptExecutor;
+import org.openqa.selenium.WebDriver;
 import org.openqa.selenium.WebElement;
 import org.openqa.selenium.support.ui.ExpectedConditions;
 import org.openqa.selenium.support.ui.WebDriverWait;
 
+import java.util.function.Function;
+import java.util.function.Predicate;
+
 public class ArchivaAdminTest
     extends AbstractArchivaTest
 {
@@ -33,23 +38,23 @@ public class ArchivaAdminTest
     @Test
     public void testHome()
     {
-        getWebDriver().get( baseUrl );
-        WebDriverWait wait = new WebDriverWait(getWebDriver(), 30);
-        wait.until(ExpectedConditions.titleContains("Apache Archiva"));
+        loadPage( baseUrl, 30 );
+        WebDriverWait wait = new WebDriverWait( getWebDriver(), 30 );
+        wait.until( ExpectedConditions.titleContains( "Apache Archiva" ) );
     }
 
     @Test
     public void testInitialRepositories()
     {
-        WebDriverWait wait = new WebDriverWait(getWebDriver(), 20);
+        WebDriverWait wait = new WebDriverWait( getWebDriver(), 20 );
         WebElement el;
-        el = wait.until(ExpectedConditions.elementToBeClickable( By.id("menu-repositories-list-a")));
-        tryClick( el,  ExpectedConditions.presenceOfElementLocated( By.xpath("//table[@id='managed-repositories-table']//td[contains(text(),'internal')]") ),
-            "Managed Repositories not activated");
-        wait.until(ExpectedConditions.visibilityOfElementLocated( By.xpath("//table[@id='managed-repositories-table']//td[contains(text(),'snapshots')]") ));
-        el = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@href='#remote-repositories-content']")));
-        tryClick(el,ExpectedConditions.visibilityOfElementLocated(By.xpath("//table[@id='remote-repositories-table']//td[contains(text(),'central')]")),
-            "Remote Repositories View not available");
+        el = wait.until( ExpectedConditions.elementToBeClickable( By.id( "menu-repositories-list-a" ) ) );
+        tryClick( el, ExpectedConditions.presenceOfElementLocated( By.xpath( "//table[@id='managed-repositories-table']//td[contains(text(),'internal')]" ) ),
+            "Managed Repositories not activated" );
+        wait.until( ExpectedConditions.visibilityOfElementLocated( By.xpath( "//table[@id='managed-repositories-table']//td[contains(text(),'snapshots')]" ) ) );
+        el = wait.until( ExpectedConditions.elementToBeClickable( By.xpath( "//a[@href='#remote-repositories-content']" ) ) );
+        tryClick( el, ExpectedConditions.visibilityOfElementLocated( By.xpath( "//table[@id='remote-repositories-table']//td[contains(text(),'central')]" ) ),
+            "Remote Repositories View not available" );
 
     }
 }
\ No newline at end of file
index 66696bc2ecdc0c0f54b8b643ba458da9b303f260..c2731fc9fbe4a3df6283ce684fd31f5828517ced 100644 (file)
@@ -180,7 +180,7 @@ public abstract class AbstractArchivaTest
 
     public void goToHomePage()
     {
-        getWebDriver().get( baseUrl );
+        loadPage( baseUrl, 30 );
     }
 
     protected void logout()
index 4d51fa270c9d44cff5a31f0bbe0d3c1c46591579..7ee5a6aedf03fbdbf9216df12fb3e312a883ddcc 100644 (file)
@@ -129,6 +129,19 @@ public abstract class AbstractSeleniumTest
         initializeArchiva( baseUrl, browser, maxWaitTimeInMs, seleniumHost, seleniumPort, remoteSelenium );
     }
 
+    public void loadPage(String url, int timeout) {
+        getWebDriver().get( url );
+        WebDriverWait wait = new WebDriverWait( getWebDriver(), timeout );
+        wait.until( new Function<WebDriver, Boolean>()
+                    {
+                        public Boolean apply( WebDriver driver )
+                        {
+                            return ( (JavascriptExecutor) driver ).executeScript( "return document.readyState" ).equals( "complete" );
+                        }
+                    }
+        );
+    }
+
     public void initializeArchiva( String baseUrl, String browser, int maxWaitTimeInMs, String seleniumHost,
                                    int seleniumPort, boolean remoteSelenium)
         throws Exception
@@ -136,7 +149,7 @@ public abstract class AbstractSeleniumTest
 
         open( baseUrl, browser, seleniumHost, seleniumPort, maxWaitTimeInMs, remoteSelenium);
 
-        getWebDriver().get(baseUrl);
+        loadPage(baseUrl, 30);
         WebDriverWait wait = new WebDriverWait(getWebDriver(),30);
         wait.until(ExpectedConditions.presenceOfElementLocated(By.id("topbar-menu")));
 
@@ -232,7 +245,7 @@ public abstract class AbstractSeleniumTest
     public void goToLoginPage()
     {
         logger.info("Goto login page");
-        getWebDriver().get( baseUrl );
+        loadPage(baseUrl, 30);
         WebDriverWait wait = new WebDriverWait(getWebDriver(),30);
         wait.until(ExpectedConditions.presenceOfElementLocated(By.id("topbar-menu")));
         wait.until(ExpectedConditions.or(ExpectedConditions.visibilityOfElementLocated(By.id("logout-link")),