use of org.openqa.selenium.support.ui.ExpectedCondition in project scout.rt by eclipse.
the class SeleniumExpectedConditions method tableToHaveNumberOfRows.
/**
* @param parentElement
* if not null, findElement below the given parent, if null, findElements in document
* @param numRows
* @return The table-rows found by the expected condition
*/
public static ExpectedCondition<List<WebElement>> tableToHaveNumberOfRows(final WebElement parentElement, final int numRows) {
return new ExpectedCondition<List<WebElement>>() {
@Override
public List<WebElement> apply(WebDriver driver) {
try {
By by = By.className("table-row");
List<WebElement> tableRows = parentElement != null ? parentElement.findElements(by) : driver.findElements(by);
if (numRows == tableRows.size()) {
return tableRows;
}
} catch (StaleElementReferenceException e) {
// NOSONAR
// NOP
}
return null;
}
@Override
public String toString() {
return String.format("table should have %d rows", numRows);
}
};
}
use of org.openqa.selenium.support.ui.ExpectedCondition in project selenium-tests by Wikia.
the class CommonExpectedConditions method elementInViewPort.
public static ExpectedCondition<Boolean> elementInViewPort(final WebElement element) {
return new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(WebDriver driver) {
Dimension size = element.getSize();
Point location = element.getLocation();
if (((size.height + location.y) > -1) && (size.width + location.x > -1)) {
return true;
}
return false;
}
@Override
public String toString() {
return String.format("Element ('%s') not in viewport!", element.getTagName());
}
};
}
use of org.openqa.selenium.support.ui.ExpectedCondition in project selenium-tests by Wikia.
the class CommonExpectedConditions method elementToHaveColor.
/**
* @param accuracy in percentage between 0 and 100.
*/
public static ExpectedCondition<Boolean> elementToHaveColor(final WebElement element, final Color color, final int accuracy) {
final Shooter shooter = new Shooter();
final ImageComparison imageComparison = new ImageComparison();
return new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(WebDriver driver) {
BufferedImage image = shooter.takeScreenshot(element, driver);
return imageComparison.isColorImage(image, color, accuracy);
}
@Override
public String toString() {
return String.format("At least %s percents of element does not have %s color", (100 - accuracy), color.toString());
}
};
}
use of org.openqa.selenium.support.ui.ExpectedCondition in project selenium-tests by Wikia.
the class IntraWikiSearchPageObject method verifyNamespace.
public void verifyNamespace(String namespace) {
driver.manage().timeouts().implicitlyWait(250, TimeUnit.MILLISECONDS);
try {
new WebDriverWait(driver, 30).until((ExpectedCondition<Boolean>) webDriver -> !titles.isEmpty());
} finally {
restoreDefaultImplicitWait();
}
Assertion.assertTrue(titles.get(0).getText().startsWith(namespace));
}
use of org.openqa.selenium.support.ui.ExpectedCondition in project keycloak by keycloak.
the class WaitUtils method waitForPageToLoad.
/**
* Waits for page to finish any pending redirects, REST API requests etc.
* Because Keycloak's Admin Console is a single-page application, we need to
* take extra steps to ensure the page is fully loaded
*/
public static void waitForPageToLoad() {
WebDriver driver = getCurrentDriver();
if (driver instanceof HtmlUnitDriver) {
// not needed
return;
}
String currentUrl = null;
// Ensure the URL is "stable", i.e. is not changing anymore; if it'd changing, some redirects are probably still in progress
for (int maxRedirects = 4; maxRedirects > 0; maxRedirects--) {
currentUrl = driver.getCurrentUrl();
FluentWait<WebDriver> wait = new FluentWait<>(driver).withTimeout(Duration.ofMillis(250));
try {
wait.until(not(urlToBe(currentUrl)));
} catch (TimeoutException e) {
// URL has not changed recently - ok, the URL is stable and page is current
break;
}
if (maxRedirects == 1) {
log.warn("URL seems unstable! (Some redirect are probably still in progress)");
}
}
WebDriverWait wait = new WebDriverWait(getCurrentDriver(), PAGELOAD_TIMEOUT_MILLIS / 1000);
ExpectedCondition waitCondition = null;
// Different wait strategies for Admin and Account Consoles
if (currentUrl.matches("^[^\\/]+:\\/\\/[^\\/]+\\/auth\\/admin\\/.*$")) {
// Admin Console
// Checks if the document is ready and asks AngularJS, if present, whether there are any REST API requests in progress
waitCondition = javaScriptThrowsNoExceptions("if (document.readyState !== 'complete' " + "|| (typeof angular !== 'undefined' && angular.element(document.body).injector().get('$http').pendingRequests.length !== 0)) {" + "throw \"Not ready\";" + "}");
} else if (// check for new Account Console URL
currentUrl.matches("^[^\\/]+:\\/\\/[^\\/]+\\/auth\\/realms\\/[^\\/]+\\/account\\/.*#/.+$")) {
// TODO rework this temporary workaround once KEYCLOAK-11201 and/or KEYCLOAK-8181 are fixed
pause(2000);
}
if (waitCondition != null) {
try {
wait.until(waitCondition);
} catch (TimeoutException e) {
log.warn("waitForPageToLoad time exceeded!");
}
}
}
Aggregations