List of usage examples for org.openqa.selenium.support.ui FluentWait FluentWait
public FluentWait(T input)
From source file:org.nuxeo.functionaltests.pages.tabs.RelationTabSubPage.java
License:Open Source License
public RelationTabSubPage setRelationWithDocument(String documentName, String predicateUri) { org.junit.Assert.assertFalse(isObjectDocumentChecked()); Select predicateSelect = new Select(predicate); predicateSelect.selectByValue(predicateUri); Select2WidgetElement documentSuggestionWidget = new Select2WidgetElement(driver, By.xpath("//*[@id='s2id_createForm:nxw_singleDocumentSuggestion_select2']")); documentSuggestionWidget.selectValue(documentName); Function<WebDriver, Boolean> isDocumentSelected = new Function<WebDriver, Boolean>() { public Boolean apply(WebDriver driver) { String value = selectedDocument.getAttribute("value"); boolean result = StringUtils.isNotBlank(value); if (!result) { log.debug("Waiting for select2 ajaxReRender"); }/*from www .j a v a 2 s .c o m*/ return result; } }; org.junit.Assert.assertTrue(isObjectDocumentChecked()); Wait<WebDriver> wait = new FluentWait<WebDriver>(driver) .withTimeout(SELECT2_CHANGE_TIMEOUT, TimeUnit.SECONDS).pollingEvery(100, TimeUnit.MILLISECONDS); wait.until(isDocumentSelected); log.debug("Submitting relation on document: " + selectedDocument.getAttribute("value")); addButton.click(); return asPage(RelationTabSubPage.class); }
From source file:org.objectfabric.Selenium.java
License:Apache License
private Wait<WebDriver> getWait() { return new FluentWait<WebDriver>(_driver) // .withTimeout(5, TimeUnit.SECONDS) // .pollingEvery(1, TimeUnit.SECONDS) // .ignoring(NoSuchElementException.class); }
From source file:org.objectfabric.Selenium.java
License:Apache License
private WebElement fluentWait(final By locator) { Wait<WebDriver> wait = new FluentWait<WebDriver>(_driver) // .withTimeout(5, TimeUnit.SECONDS) // .pollingEvery(100, TimeUnit.MILLISECONDS) // .ignoring(NoSuchElementException.class); WebElement foo = wait.until(new Function<WebDriver, WebElement>() { public WebElement apply(WebDriver driver) { return driver.findElement(locator); }//from ww w. ja v a2s .c o m }); return foo; }
From source file:org.owasp.webgoat.plugins.TestUtils.java
License:Open Source License
public static FluentWait createDefaultWait(WebDriver webDriver) { return new FluentWait(webDriver).withTimeout(10, SECONDS).pollingEvery(2, SECONDS) .ignoring(NoSuchElementException.class).ignoring(StaleElementReferenceException.class); }
From source file:org.pentaho.ctools.suite.CToolsTestSuite.java
License:Open Source License
@BeforeClass public static void setUpClass() throws IOException { System.out.println("Master setup"); //System.setProperty("webdriver.log.file", "/dev/stdout"); //System.setProperty("webdriver.firefox.logfile", "/dev/stdout"); //Setting log preferences LoggingPreferences logs = new LoggingPreferences(); logs.enable(LogType.BROWSER, Level.ALL); logs.enable(LogType.SERVER, Level.ALL); logs.enable(LogType.DRIVER, Level.ALL); logs.enable(LogType.PROFILER, Level.ALL); logs.enable(LogType.CLIENT, Level.ALL); logs.enable(LogType.PERFORMANCE, Level.ALL); DesiredCapabilities capabilities = DesiredCapabilities.firefox(); capabilities.setCapability(CapabilityType.LOGGING_PREFS, logs); //Inicialize DRIVER FirefoxProfile ffProfile = new FirefoxProfile(); ffProfile.setPreference("intl.accept_languages", "en-us"); capabilities.setCapability(FirefoxDriver.PROFILE, ffProfile); JavaScriptError.addExtension(ffProfile); driver = new FirefoxDriver(capabilities); driver.manage().window().maximize(); driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS); driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); //Inicialize WAIT wait = new FluentWait<WebDriver>(driver).withTimeout(30, TimeUnit.SECONDS).pollingEvery(1, TimeUnit.SECONDS) .ignoring(org.openqa.selenium.NoSuchElementException.class); //Inicialize BASEURL baseUrl = "http://localhost:8080/pentaho/"; }
From source file:org.senchalabs.gwt.gwtdriver.gxt.models.ComboBox.java
License:Apache License
public ListView waitForDropDown(long duration, TimeUnit unit) { return new FluentWait<WebDriver>(getDriver()).withTimeout(duration, unit).ignoring(NotFoundException.class) .until(new Function<WebDriver, ListView>() { @Override// w w w. j a v a 2 s . c om public ListView apply(WebDriver webDriver) { return getDropDown(); } }); }
From source file:org.senchalabs.gwt.gwtdriver.models.GwtWidgetFinder.java
License:Apache License
public W waitFor(long duration, TimeUnit unit) { return new FluentWait<WebDriver>(driver).withTimeout(duration, unit).ignoring(NotFoundException.class) .until(new Function<WebDriver, W>() { @Nullable/*from w w w .ja v a2 s. c o m*/ @Override public W apply(@Nullable WebDriver webDriver) { return done(); } }); }
From source file:org.testeditor.fixture.web.AbstractWebFixture.java
License:Open Source License
/** * Searches for a given text on the page. * //from www.j a v a 2 s.com * @param text * to be searched for * @return {@code true} if the {@code text} is present on the page, * {@code false} otherwise */ public boolean checkTextIsPresentOnPage(final String text) { waitForPage(); try { int interval = (int) Math.floor(Math.sqrt(timeout)); logger.info("Got interval: " + interval); Wait<WebDriver> wait = new FluentWait<WebDriver>(webDriver).withTimeout(timeout, TimeUnit.SECONDS) .pollingEvery(interval, TimeUnit.SECONDS) .ignoring(NoSuchElementException.class, StaleElementReferenceException.class); return wait.until(new ExpectedCondition<Boolean>() { @Override public Boolean apply(WebDriver driver) { String source = webDriver.getPageSource(); logger.info("Got source: " + "\"" + source + "\""); logger.info("text to be checked: " + "\"" + text + "\""); source = source.replaceFirst("(?i:<HEAD[^>]*>[\\s\\S]*</HEAD>)", ""); return source.contains(text.trim()); } }); } catch (Exception e) { return false; } }
From source file:org.testeditor.fixture.web.AbstractWebFixture.java
License:Open Source License
/** * Waits for page is complete loaded. Therefore the "document.readyState" is * checked./* w w w .ja v a 2 s .c o m*/ * * @return {@code true} if complete loaded during the timeout, {@code false} * otherwise */ public boolean waitForPage() { int interval = (int) Math.floor(Math.sqrt(timeout)); Wait<WebDriver> wait = new FluentWait<WebDriver>(webDriver).withTimeout(timeout, TimeUnit.SECONDS) .pollingEvery(interval, TimeUnit.SECONDS) .ignoring(NoSuchElementException.class, StaleElementReferenceException.class); try { return wait.until(new ExpectedCondition<Boolean>() { @Override public Boolean apply(WebDriver arg) { return ((JavascriptExecutor) webDriver).executeScript("return document.readyState") .equals("complete"); } }); } catch (TimeoutException e) { throw new ContinueTestException("Page could not be loaded within the timeout."); } catch (Exception e) { logger.error(e.getMessage()); } return true; }
From source file:org.testeditor.fixture.web.AbstractWebFixture.java
License:Open Source License
/** * Finds and returns all web element in the DOM matching the technical * locator. This does not necessarily mean that the elements are visible. * The configured {@code timeout} is used to specify the time to wait for * the element./* w w w . j av a2 s . c o m*/ * * @param elementListKey * key in the element list to find the technical locator * @param replaceArgs * values to replace the place holders in the element list entry * @return the web elements or {@code null} if no matching element is * present in the DOM * @throws StopTestException * if a timeout occurred while finding the web elements */ protected List<WebElement> findWebElements(String elementListKey, String... replaceArgs) throws StopTestException { int interval = (int) Math.floor(Math.sqrt(timeout)); Wait<WebDriver> wait = new FluentWait<WebDriver>(webDriver).withTimeout(timeout, TimeUnit.SECONDS) .pollingEvery(interval, TimeUnit.SECONDS) .ignoring(NoSuchElementException.class, StaleElementReferenceException.class); try { return wait.until( ExpectedConditions.presenceOfAllElementsLocatedBy(createBy(elementListKey, replaceArgs))); } catch (TimeoutException e) { throw new StopTestException("There was a timeout while finding the element '" + createBy(elementListKey, replaceArgs) + "'!"); } }