From 8b3de94f7738c897acdc7d18bed1f0fa9bd90c0f Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Thu, 2 Nov 2017 21:53:11 +0100 Subject: [PATCH] Adding another hack for selenium tests --- .../archiva/web/test/RepositoryAdminTest.java | 19 ++++++++++--- .../web/test/parent/AbstractSeleniumTest.java | 27 +++++++++++++++++-- 2 files changed, 41 insertions(+), 5 deletions(-) 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 e8240f5c6..6daad8a42 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 @@ -25,7 +25,9 @@ import org.junit.Test; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.Select; import org.openqa.selenium.support.ui.WebDriverWait; import java.util.List; @@ -61,9 +63,15 @@ public class RepositoryAdminTest setFieldValue( "id", "myrepoid" ); setFieldValue( "name", "My repo name" ); setFieldValue( "url", "http://www.repo.org" ); - + + el = wait.until( ExpectedConditions.elementToBeClickable(By.id("remote-repository-save-button") )); + Actions actions = new Actions(getWebDriver()); + actions.moveToElement(el); + actions.perform(); + ((JavascriptExecutor)getWebDriver()).executeScript("arguments[0].scrollIntoView();", el); el.click(); - wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("remote-repositories-view-a"))); + el = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("remote-repositories-view-a"))); + ((JavascriptExecutor)getWebDriver()).executeScript("arguments[0].scrollIntoView();", el); tryClick(By.id("menu-proxy-connectors-list-a"), ExpectedConditions.visibilityOfElementLocated(By.id("proxy-connectors-view-tabs-a-network-proxies-grid")), "Network proxies not available", @@ -76,7 +84,12 @@ public class RepositoryAdminTest el = wait.until(ExpectedConditions.elementToBeClickable( By.id("proxy-connectors-view-tabs-a-edit") )); el.click(); el = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("proxy-connector-btn-save"))); - selectValue( "sourceRepoId", "internal" ); + wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("remote-repository-edit-fieldset"))); + // Another hack, don't know why the normal selectValue() does not work here + ((JavascriptExecutor)getWebDriver()).executeScript("jQuery('#sourceRepoId').css('display','block')"); + Select select = new Select(getWebDriver().findElement(By.xpath(".//select[@id='sourceRepoId']"))); + select.selectByVisibleText("internal"); + // selectValue( "sourceRepoId", "internal", true ); // Workaround // TODO: Check after upgrade of htmlunit, bootstrap or jquery // TODO: Check whats wrong here 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 96d6cf897..f7d979973 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 @@ -37,8 +37,10 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Date; import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Properties; @@ -503,11 +505,32 @@ public abstract class AbstractSeleniumTest } - public void selectValue( String locator, String value ) + public WebElement selectValue( String locator, String value) { + return this.selectValue( locator, value, false ); + } + + public WebElement selectValue( String locator, String value, boolean scrollToView ) { - WebElement element = findElement(locator ); + int count = 5; + boolean check = true; + WebDriverWait wait = new WebDriverWait( getWebDriver( ), 10 ); + WebElement element = null; + while(check && count-->0) + { + try + { + element = findElement( locator ); + List elementList = new ArrayList<>( ); + elementList.add( element ); + wait.until( ExpectedConditions.visibilityOfAllElements( elementList ) ); + check=false; + } catch (Throwable e) { + logger.info("Waiting for select element {} to be visible", locator); + } + } Select select = new Select(element); select.selectByValue( value ); + return element; } public WebElement findElement(String locator) { -- 2.39.5