List of usage examples for org.openqa.selenium.support.ui Wait until
<T> T until(Function<? super F, T> isTrue);
From source file:org.nuxeo.functionaltests.AbstractTest.java
License:Open Source License
/** * Fluent wait for text to be not present in the given element. * * @since 5.7.3//from w w w.j a v a 2s . com */ public static void waitForTextNotPresent(final WebElement element, final String text) { Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(LOAD_TIMEOUT_SECONDS, TimeUnit.SECONDS) .pollingEvery(POLLING_FREQUENCY_SECONDS, TimeUnit.SECONDS); wait.until((new Function<WebDriver, Boolean>() { public Boolean apply(WebDriver driver) { try { return !element.getText().contains(text); } catch (StaleElementReferenceException e) { return null; } } })); }
From source file:org.nuxeo.functionaltests.dam.FoldableBoxFragment.java
License:Open Source License
public WebElement waitUntilElementPresent(final By locator) { Wait<WebDriver> wait = new FluentWait<>(driver) .withTimeout(AbstractTest.LOAD_TIMEOUT_SECONDS, TimeUnit.SECONDS) .pollingEvery(AbstractTest.POLLING_FREQUENCY_SECONDS, TimeUnit.SECONDS) .ignoring(NoSuchElementException.class); return wait.until(new Function<WebDriver, WebElement>() { public WebElement apply(WebDriver driver) { return element.findElement(locator); }//from www . j a va2 s .co m }); }
From source file:org.nuxeo.functionaltests.forms.Select2WidgetElement.java
License:Open Source License
/** * Select a single value./* www . j a v a2 s .c om*/ * * @param value the value to be selected * * @since 5.7.3 */ public void selectValue(final String value) { WebElement select2Field = null; if (mutliple) { select2Field = element; } else { select2Field = element.findElement(By.xpath("a[contains(@class,'select2-choice select2-default')]")); } select2Field.click(); Wait<WebDriver> wait = new FluentWait<WebDriver>(driver) .withTimeout(SELECT2_LOADING_TIMEOUT, TimeUnit.SECONDS).pollingEvery(100, TimeUnit.MILLISECONDS) .ignoring(NoSuchElementException.class); WebElement suggestInput = null; if (mutliple) { suggestInput = driver.findElement(By.xpath("//ul/li[@class='select2-search-field']/input")); } else { suggestInput = driver.findElement(By.xpath(S2_SINGLE_INPUT_XPATH)); } char c; for (int i = 0; i < value.length(); i++) { c = value.charAt(i); suggestInput.sendKeys(c + ""); try { wait.until(mutliple ? s2MultipleWaitFunction : s2SingleWaitFunction); } catch (TimeoutException e) { if (i == (value.length() - 1)) { log.error("Suggestion definitly timed out with last letter : " + c + ". There is something wrong with select2"); throw e; } log.warn("Suggestion timed out with letter : " + c + ". Let's try with next letter."); } } WebElement suggestion = driver.findElement(By.xpath(S2_SUGGEST_RESULT_XPATH)); suggestion.click(); }
From source file:org.nuxeo.functionaltests.fragment.GadgetsContainerFragment.java
License:Open Source License
public WebElement waitForGadgetsLoad(final String mandatoryElements) { Wait<WebDriver> wait = new FluentWait<WebDriver>(driver) .withTimeout(AbstractTest.LOAD_TIMEOUT_SECONDS, TimeUnit.SECONDS).pollingEvery(5, TimeUnit.SECONDS) .ignoring(NoSuchElementException.class); return wait.until(new Function<WebDriver, WebElement>() { public WebElement apply(WebDriver driver) { WebElement container = getElement(); // iterate through all frames, and ensure opensocial ones are // loaded, and expect at least one opensocial frame boolean oneFound = false; List<WebElement> framesList = driver.findElements(By.xpath("//iframe")); if (framesList != null && !framesList.isEmpty()) { List<String> mandatory = Arrays.asList(mandatoryElements.split(",")); for (WebElement frame : framesList) { String frameName = frame.getAttribute("name"); if (frameName == null || !frameName.startsWith("open-social")) { continue; }// ww w.ja v a 2 s.c o m log.debug(String.format("Found one GWT gadget frame named '%s' ", frameName)); oneFound = true; boolean loaded = false; driver.switchTo().defaultContent(); driver.switchTo().frame(frame); for (String mand : mandatory) { try { driver.findElement(By.id(mand)); loaded = true; log.debug(String.format("Gadget frame '%s' mandatory element '%s' loaded", frameName, mand)); } catch (NoSuchElementException e) { loaded = false; log.debug(String.format( "Gadget frame '%s' not loaded yet, " + "mandatory element '%s' not found", frameName, mand)); break; } } if (!loaded) { log.debug(String.format("Gadget frame '%s' not loaded yet", frameName)); driver.switchTo().defaultContent(); return null; } log.debug(String.format("Gadget frame '%s' loaded", frameName)); driver.switchTo().defaultContent(); } } if (oneFound) { return container; } log.debug("No gadget frame loaded yet"); return null; } }); }
From source file:org.nuxeo.functionaltests.ITSafeEditTest.java
License:Open Source License
private void checkSafeEditRestoreProvided() { // We must find the status message asking if we want to restore // previous unchanged data, and make sure it is visible Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(5, TimeUnit.SECONDS) .pollingEvery(100, TimeUnit.MILLISECONDS).ignoring(NoSuchElementException.class); wait.until(ExpectedConditions.textToBePresentInElement(By.className("ambiance-title"), "A draft of this document has been saved")); }
From source file:org.nuxeo.functionaltests.ITSafeEditTest.java
License:Open Source License
private void waitForSavedNotification() { Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(5, TimeUnit.SECONDS) .pollingEvery(100, TimeUnit.MILLISECONDS).ignoring(NoSuchElementException.class); try {/*from w w w . j av a 2s. co m*/ wait.until(new Function<WebDriver, WebElement>() { public WebElement apply(WebDriver driver) { return driver .findElement(By.xpath("//div[contains(.,'" + DRAFT_SAVE_TEXT_NOTIFICATION + "')]")); } }); } catch (TimeoutException e) { log.warn("Could not see saved message, maybe I was too slow and it " + "has already disappeared. Let's see if I can restore."); } }
From source file:org.nuxeo.functionaltests.Locator.java
License:Apache License
/** * Finds the first {@link WebElement} using the given method, with a {@code findElementTimeout}, inside an optional * {@code parentElement}. Then waits until the element is enabled, with a {@code waitUntilEnabledTimeout}. * * @param parentElement the parent element (can be null) * @param by the locating mechanism/*from ww w .j a va 2 s .c om*/ * @param findElementTimeout the find element timeout in milliseconds * @param waitUntilEnabledTimeout the wait until enabled timeout in milliseconds * @return the first matching element on the current page, if found, with optional parent element * @throws NotFoundException if the element is not found or not enabled * @since 8.3 */ public static WebElement findElementAndWaitUntilEnabled(WebElement parentElement, final By by, final int findElementTimeout, final int waitUntilEnabledTimeout) throws NotFoundException { Wait<WebDriver> wait = getFluentWait(); Function<WebDriver, WebElement> function = new Function<WebDriver, WebElement>() { @Override public WebElement apply(WebDriver driver) { WebElement element = null; try { // Find the element. element = findElementWithTimeout(by, findElementTimeout, parentElement); // Try to wait until the element is enabled. waitUntilEnabled(element, waitUntilEnabledTimeout); } catch (StaleElementReferenceException sere) { AbstractTest.log.debug("StaleElementReferenceException: " + sere.getMessage()); return null; } return element; } }; return wait.until(function); }
From source file:org.nuxeo.functionaltests.Locator.java
License:Apache License
/** * Fluent wait for text to be not present in the given element. * * @since 5.7.3//from w w w . ja v a 2s .co m */ public static void waitForTextNotPresent(final WebElement element, final String text) { Wait<WebDriver> wait = getFluentWait(); wait.until((new Function<WebDriver, Boolean>() { @Override public Boolean apply(WebDriver driver) { try { return !element.getText().contains(text); } catch (StaleElementReferenceException e) { return null; } } })); }
From source file:org.nuxeo.functionaltests.Locator.java
License:Apache License
/** * Fluent wait for text to be present in the element retrieved with the given method. * * @since 5.7.3//from www . j ava2 s . c o m */ public static void waitForTextPresent(By locator, String text) { Wait<WebDriver> wait = getFluentWait(); wait.until(ExpectedConditions.textToBePresentInElementLocated(locator, text)); }
From source file:org.nuxeo.functionaltests.Locator.java
License:Apache License
/** * Fluent wait for text to be present in the given element. * * @since 5.7.3//from w w w .jav a 2s . c om */ public static void waitForTextPresent(final WebElement element, final String text) { Wait<WebDriver> wait = getFluentWait(); wait.until((new Function<WebDriver, Boolean>() { @Override public Boolean apply(WebDriver driver) { try { return element.getText().contains(text); } catch (StaleElementReferenceException e) { return null; } } })); }