use of org.openqa.selenium.support.ui.WebDriverWait in project archiva by apache.
the class AbstractSeleniumTest method tryClick.
/**
* 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
* and waits again for the condition.
* After the number of attempts as given by the parameter an assertion error will be thrown, with
* the given <code>message</code>.
*
* If the click was successful the element is returned that was created by the condition.
*
* @param el The element where the click is executed
* @param conditions The conditions to wait for after the click
* @param message The assertion messages
* @param attempts Maximum number of click attempts
* @param maxWaitTimeInS The time in seconds to wait that the condition is fulfilled.
* @param <V> The return type
* @return
*/
public <V> V tryClick(WebElement el, 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) {
if (count < attempts) {
try {
result = conditions.apply(getWebDriver());
return result;
} catch (Exception e) {
// Ignore
}
}
el.click();
try {
result = wait.until(conditions);
return result;
} catch (Exception e) {
logger.info("Error: {}, {}", count, e.getMessage());
ex = e;
count--;
}
try {
Thread.currentThread().sleep(500);
} catch (InterruptedException e) {
// Ignore
}
}
if (ex != null) {
Assert.fail(message);
}
return result;
}
use of org.openqa.selenium.support.ui.WebDriverWait in project archiva by apache.
the class AbstractSeleniumTest method initializeArchiva.
public void initializeArchiva(String baseUrl, String browser, int maxWaitTimeInMs, String seleniumHost, int seleniumPort, boolean remoteSelenium) throws Exception {
open(baseUrl, browser, seleniumHost, seleniumPort, maxWaitTimeInMs, remoteSelenium);
loadPage(baseUrl, 30);
WebDriverWait wait = new WebDriverWait(getWebDriver(), 30);
wait.until(ExpectedConditions.presenceOfElementLocated(By.id("topbar-menu")));
wait = new WebDriverWait(getWebDriver(), 20);
Boolean found = wait.until(ExpectedConditions.or(ExpectedConditions.visibilityOfElementLocated(By.id("create-admin-link-a")), ExpectedConditions.visibilityOfElementLocated(By.id("login-link-a"))));
if (found) {
WebElement adminLink = getWebDriver().findElement(By.id("create-admin-link-a"));
WebElement loginLink = getWebDriver().findElement(By.id("login-link-a"));
// if not admin user created create one
if (adminLink != null && adminLink.isDisplayed()) {
Assert.assertFalse(isElementVisible("login-link-a"));
Assert.assertFalse(isElementVisible("register-link-a"));
// skygo need to set to true for passing is that work as expected ?
adminLink.click();
wait = new WebDriverWait(getWebDriver(), 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("user-create")));
assertCreateAdmin();
String fullname = getProperty("ADMIN_FULLNAME");
String username = getAdminUsername();
String mail = getProperty("ADMIN_EMAIL");
String password = getProperty("ADMIN_PASSWORD");
submitAdminData(fullname, mail, password);
assertUserLoggedIn(username);
clickLinkWithLocator("logout-link-a", false);
} else if (loginLink != null && loginLink.isDisplayed()) {
Assert.assertTrue(isElementVisible("login-link-a"));
Assert.assertTrue(isElementVisible("register-link-a"));
login(getAdminUsername(), getAdminPassword());
}
}
}
use of org.openqa.selenium.support.ui.WebDriverWait in project archiva by apache.
the class AbstractSeleniumTest method tryClick.
public <V> V tryClick(By clickableLocator, Function<? super WebDriver, V> conditions, String message, int attempts, int maxWaitTimeInS) {
getWebDriver().manage().window().maximize();
int count = attempts;
WebDriverWait wait = new WebDriverWait(getWebDriver(), maxWaitTimeInS);
V result = null;
Exception ex = null;
WebElement el = null;
while (count > 0) {
try {
el = wait.until(ExpectedConditions.elementToBeClickable(clickableLocator));
Actions actions = new Actions(getWebDriver());
actions.moveToElement(el).click().perform();
result = wait.until(conditions);
return result;
} catch (Exception e) {
logger.info("Error: {}, {}, {}", count, e.getClass().getName(), e.getMessage());
if (el != null) {
// Elements may be stale and throw an exception, if the location is requested
try {
Point elLoc = el.getLocation();
logger.info("Location: x={} y={}", elLoc.getX(), elLoc.getY());
} catch (Throwable e2) {
logger.info("Could not determine location");
}
}
ex = e;
count--;
}
try {
Thread.currentThread().sleep(500);
} catch (InterruptedException e) {
// Ignore
}
}
if (ex != null) {
Assert.fail(message);
}
return result;
}
use of org.openqa.selenium.support.ui.WebDriverWait in project archiva by apache.
the class AbstractSeleniumTest method submitLoginPage.
public void submitLoginPage(String username, String password, boolean rememberMe, boolean validUsernamePassword, String assertReturnPage) {
logger.info("Activating login form");
// clickLinkWithLocator( "login-link-a", false);
WebDriverWait wait = new WebDriverWait(getWebDriver(), 5);
WebElement usernameField = wait.until(ExpectedConditions.visibilityOf(getWebDriver().findElement(By.id("user-login-form-username"))));
wait = new WebDriverWait(getWebDriver(), 5);
WebElement passwordField = wait.until(ExpectedConditions.visibilityOf(getWebDriver().findElement(By.id("user-login-form-password"))));
wait = new WebDriverWait(getWebDriver(), 5);
WebElement button = wait.until(ExpectedConditions.elementToBeClickable(By.id("modal-login-ok")));
usernameField.sendKeys(username);
passwordField.sendKeys(password);
/*
if ( rememberMe )
{
checkField( "rememberMe" );
}*/
button.click();
if (validUsernamePassword) {
assertUserLoggedIn(username);
}
/*
else
{
if ( "Login Page".equals( assertReturnPage ) )
{
assertLoginPage();
}
else
{
assertPage( assertReturnPage );
}
}*/
}
use of org.openqa.selenium.support.ui.WebDriverWait in project archiva by apache.
the class ArchivaAdminTest method testHome.
@Test
public void testHome() {
loadPage(baseUrl, 30);
WebDriverWait wait = new WebDriverWait(getWebDriver(), 30);
wait.until(ExpectedConditions.titleContains("Apache Archiva"));
}
Aggregations