From 8183ff19eb4b02350c452c2c8f9b6518d7c1aae9 Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Fri, 9 Jun 2017 16:46:52 +0200 Subject: [PATCH] Finish migrating tests to Webdriver --- .../archiva/web/test/ArchivaAdminTest.java | 5 +++- .../archiva/web/test/RepositoryAdminTest.java | 20 +++++++++++----- .../archiva/web/test/RolesManagementTest.java | 12 +++++++--- .../web/test/parent/AbstractArchivaTest.java | 23 ++++++++++++++----- .../web/test/parent/AbstractSeleniumTest.java | 2 +- 5 files changed, 45 insertions(+), 17 deletions(-) diff --git a/archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/ArchivaAdminTest.java b/archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/ArchivaAdminTest.java index 5a9d15607..3e177b2aa 100644 --- a/archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/ArchivaAdminTest.java +++ b/archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/ArchivaAdminTest.java @@ -21,6 +21,8 @@ package org.apache.archiva.web.test; import org.apache.archiva.web.test.parent.AbstractArchivaTest; import org.junit.Test; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; public class ArchivaAdminTest extends AbstractArchivaTest @@ -30,6 +32,7 @@ public class ArchivaAdminTest public void testHome() { getWebDriver().get( baseUrl ); - assertPage( "Apache Archiva" ); + WebDriverWait wait = new WebDriverWait(getWebDriver(), 30); + wait.until(ExpectedConditions.titleContains("Apache Archiva")); } } \ No newline at end of file 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 4728e4099..0ea8580ea 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 @@ -24,11 +24,14 @@ import org.junit.Assert; import org.junit.Test; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.WebElement; import org.openqa.selenium.htmlunit.HtmlUnitDriver; import org.openqa.selenium.support.ui.ExpectedCondition; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; +import java.util.List; + /** * Based on LoginTest of Emmanuel Venisse test. * @@ -45,8 +48,9 @@ public class RepositoryAdminTest public void testManagedRepository() { login( getAdminUsername(), getAdminPassword() ); - clickLinkWithLocator( "menu-repositories-list-a"); WebDriverWait wait = new WebDriverWait(getWebDriver(), 10); + wait.until(ExpectedConditions.elementToBeClickable(By.id("menu-repositories-list-a"))); + clickLinkWithLocator( "menu-repositories-list-a"); wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("managed-repositories-view-a"))); clickLinkWithXPath( "//a[@href='#remote-repositories-content']"); wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("remote-repositories-view-a"))); @@ -80,12 +84,16 @@ public class RepositoryAdminTest wait.until(ExpectedConditions.textToBePresentInElementLocated(By.id("user-messages"),"ProxyConnector added")); wait.until(ExpectedConditions.textToBePresentInElementLocated(By.id("proxy-connectors-view"), "central" )); wait.until(ExpectedConditions.textToBePresentInElementLocated(By.id("proxy-connectors-view"), "myrepoid" )); - clickLinkWithXPath( "//i[contains(concat(' ',normalize-space(@class),' '),' icon-resize-vertical ')]/../..", true ); + clickLinkWithXPath( "//i[contains(@class,'icon-resize-vertical')]//ancestor::a"); + // This is needed here for HTMLUnit Tests. Currently do not know why, wait is not working for the + // list entries down + waitPage(); + WebElement el = wait.until(ExpectedConditions.presenceOfElementLocated(By.id("proxy-connector-edit-order-div"))); assertTextPresent( "internal" ); - // order test - Assert.assertTrue( "First repo is myrepo",findElement("//div[@id='proxy-connector-edit-order-div']/div[1]").getText().contains("myrepoid")); - Assert.assertTrue( "Second repo is central",findElement("//div[@id='proxy-connector-edit-order-div']/div[2]" ).getText().contains( "central" )); - + List repos = el.findElements(By.xpath("./div")); + Assert.assertTrue("First repo is myrepo", repos.get(0).getText().contains("myrepoid")); + Assert.assertTrue("Second repo is central", repos.get(1).getText().contains("central")); + // works until this point /*getSelenium().mouseDown( "xpath=//div[@id='proxy-connector-edit-order-div']/div[1]" ); getSelenium().mouseMove( "xpath=//div[@id='proxy-connector-edit-order-div']/div[2]" ); diff --git a/archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/RolesManagementTest.java b/archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/RolesManagementTest.java index 1a13488a0..b31ab23f9 100644 --- a/archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/RolesManagementTest.java +++ b/archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/RolesManagementTest.java @@ -22,6 +22,9 @@ import org.apache.archiva.web.test.parent.AbstractArchivaTest; import org.apache.commons.lang.StringUtils; import org.junit.Assert; import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; /** @@ -36,14 +39,17 @@ public class RolesManagementTest throws Exception { login( getAdminUsername(), getAdminPassword() ); - clickLinkWithLocator( "menu-roles-list-a", true ); - assertTextPresent( "Archiva System Administrator " ); + clickLinkWithLocator( "menu-roles-list-a"); + WebDriverWait wait = new WebDriverWait(getWebDriver(), 10); + wait.until(ExpectedConditions.textToBePresentInElementLocated(By.id("roles-view"),"Archiva System Administrator")); Assert.assertTrue( StringUtils.isEmpty( getText( "role-description-Guest" ) ) ); clickLinkWithLocator( "edit-role-Guest" ); + wait.until(ExpectedConditions.elementToBeClickable(By.id("role-edit-description-save"))); String desc = "The guest description"; setFieldValue( "role-edit-description", desc ); clickButtonWithLocator( "role-edit-description-save" ); + wait.until(ExpectedConditions.textToBePresentInElementLocated(By.id("user-messages"), "Role Guest updated.")); clickLinkWithLocator( "roles-view-tabs-a-roles-grid" ); - Assert.assertTrue( StringUtils.equals( desc, getText( "role-description-Guest" ) ) ); + wait.until(ExpectedConditions.textToBePresentInElementLocated(By.id("role-description-Guest"), desc)); } } diff --git a/archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/parent/AbstractArchivaTest.java b/archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/parent/AbstractArchivaTest.java index 54a20d5d3..4409ae3ca 100644 --- a/archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/parent/AbstractArchivaTest.java +++ b/archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/parent/AbstractArchivaTest.java @@ -2,6 +2,9 @@ package org.apache.archiva.web.test.parent; import org.junit.runner.RunWith; import org.junit.runners.BlockJUnit4ClassRunner; +import org.openqa.selenium.By; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; import java.io.File; import java.io.IOException; @@ -97,9 +100,11 @@ public abstract class AbstractArchivaTest boolean valid ) { login( getAdminUsername(), getAdminPassword() ); - clickLinkWithLocator( "menu-users-list-a", true ); - clickLinkWithLocator( "users-view-tabs-li-user-edit-a", true ); - + WebDriverWait wait = new WebDriverWait(getWebDriver(), 10); + clickLinkWithLocator( "menu-users-list-a"); + wait.until(ExpectedConditions.elementToBeClickable(By.id("users-view-tabs-li-user-edit-a"))); + clickLinkWithLocator( "users-view-tabs-li-user-edit-a"); + wait.until(ExpectedConditions.elementToBeClickable(By.id("user-create-form-register-button"))); assertCreateUserPage(); setFieldValue( "username", userName ); setFieldValue( "fullname", fullName ); @@ -107,8 +112,9 @@ public abstract class AbstractArchivaTest setFieldValue( "password", password ); setFieldValue( "confirmPassword", confirmPassword ); - clickLinkWithLocator( "user-create-form-register-button", true ); + clickLinkWithLocator( "user-create-form-register-button"); + wait.until(ExpectedConditions.presenceOfElementLocated(By.id("users-grid-user-id-" + userName))); assertTextPresent( "User " + userName + " created." ); assertElementPresent( "users-grid-user-id-" + userName ); @@ -131,13 +137,17 @@ public abstract class AbstractArchivaTest public void deleteUser( String userName, String fullName, String emailAd, boolean validated, boolean locked ) { - clickLinkWithLocator( "menu-users-list-a", true ); + clickLinkWithLocator( "menu-users-list-a"); + WebDriverWait wait = new WebDriverWait(getWebDriver(),10); + wait.until(ExpectedConditions.elementToBeClickable(By.id("users-grid-delete-" + userName))); assertTextPresent( userName ); assertTextPresent( fullName ); clickLinkWithLocator( "users-grid-delete-" + userName ); + wait.until(ExpectedConditions.elementToBeClickable(By.id("dialog-confirm-modal-ok"))); clickLinkWithLocator( "dialog-confirm-modal-ok" ); + wait.until(ExpectedConditions.elementToBeClickable(By.id("alert-message-success-close-a" ))); assertTextPresent( "User " + userName + " deleted." ); clickLinkWithLocator( "alert-message-success-close-a" ); @@ -175,7 +185,8 @@ public abstract class AbstractArchivaTest protected void logout() { clickLinkWithLocator( "logout-link-a" ); - waitPage(); + WebDriverWait wait = new WebDriverWait(getWebDriver(), 10); + wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[text()='Login']//ancestor::a"))); assertTextNotPresent( "Current User:" ); assertLinkNotVisible( "Edit Details" ); assertLinkNotVisible( "Logout" ); 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 2245910be..d6d4a1f82 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 @@ -355,7 +355,7 @@ public abstract class AbstractSeleniumTest public void assertPage( String title ) { - Assert.assertEquals( getTitle(), title ); + Assert.assertEquals( title, getTitle()); } public String getTitle() -- 2.39.5