Adding another hack for selenium tests

This commit is contained in:
Martin Stockhammer 2017-11-02 21:53:11 +01:00
parent 8070af6128
commit 8b3de94f77
2 changed files with 41 additions and 5 deletions

View File

@ -25,7 +25,9 @@
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 void testManagedRepository()
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 void testManagedRepository()
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

View File

@ -37,8 +37,10 @@
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 String getFieldValue( String fieldName )
}
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<WebElement> 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) {