List of usage examples for org.openqa.selenium.support.ui FluentWait FluentWait
public FluentWait(T input)
From source file:org.testeditor.fixture.web.AbstractWebFixture.java
License:Open Source License
/** * Finds and returns a list of web element displayed on the page. If non * matching element, an empty list is returned. * /* w ww. java 2 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 a list of available (present and not hidden) web elements * @throws StopTestException * if a timeout occurred */ protected List<WebElement> findAllAvailableWebElements(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.visibilityOfAllElementsLocatedBy(createBy(elementListKey, replaceArgs))); } catch (TimeoutException e) { throw new StopTestException("There was a timeout while finding the element '" + createBy(elementListKey, replaceArgs) + "'!"); } }
From source file:org.venkatesh.selenium.wait.ManagedFluentWaitTest.java
License:Apache License
@Before public void setUp() { control = EasyMock.createControl();/*from ww w. j av a2 s.co m*/ mockedDriver = control.createMock(WebDriver.class); provider = control.createMock(ManagedFluentWait.FluentWaitProvider.class); fluentWait = new FluentWait<WebDriver>(mockedDriver); expect(provider.get()).andReturn(fluentWait); expect(provider.getDriver()).andReturn(mockedDriver).anyTimes(); }
From source file:org.xmlium.test.web.commons.xml.XMLTestConfig.java
License:LGPL
protected void loadConfig() throws Exception { try {// w w w . j av a 2s .com String driverClass = config.getDriverClass(); if (driverClass.contains("SelendroidDriver")) { if (selendroidServer != null) { Method m = selendroidServer.getClass().getDeclaredMethod("stopSelendroid"); m.invoke(selendroidServer, null); } Object sdConfig = Class.forName("io.selendroid.standalone.SelendroidConfiguration").newInstance(); // Add the selendroid-test-app to the standalone server Method m = sdConfig.getClass().getDeclaredMethod("addSupportedApp", String.class); m.invoke(sdConfig, config.getAppApk()); //config.addSupportedApp("src/main/resources/selendroid-test-app-0.17.0.apk"); selendroidServer = Class.forName("io.selendroid.standalone.SelendroidLauncher") .getConstructor(sdConfig.getClass()).newInstance(sdConfig); Method m2 = selendroidServer.getClass().getDeclaredMethod("launchSelendroid"); m2.invoke(selendroidServer, null); String capabilitiesClass = "io.selendroid.common.SelendroidCapabilities"; Class capabilitiesClz = Class.forName(capabilitiesClass); Object caps = capabilitiesClz.getConstructor(String.class).newInstance(config.getAppId()); Class driverClz = Class.forName(config.getDriverClass()); getSuite().setDriver((WebDriver) driverClz.getConstructor(org.openqa.selenium.Capabilities.class) .newInstance(caps)); // if (selendroidServer != null) { // selendroidServer.stopSelendroid(); // } // SelendroidConfiguration configDroid = new SelendroidConfiguration(); // configDroid.addSupportedApp(config.getAppApk()); //// configDroid.addSupportedApp("src/main/resources/selendroid-test-app-0.17.0.apk"); // selendroidServer = new SelendroidLauncher(configDroid); // selendroidServer.launchSelendroid(); // //// SelendroidCapabilities caps = //// new SelendroidCapabilities("io.selendroid.testapp:0.17.0"); // SelendroidCapabilities caps = // new SelendroidCapabilities(config.getAppId()); // getSuite().setDriver(new SelendroidDriver(caps)); } else { getSuite().setDriver((WebDriver) Class.forName(config.getDriverClass()).newInstance()); } getSuite().setTimeout(config.getTimeout()); getSuite().setUrl(config.getUrl()); if (config.getLocale() != null && !config.getLocale().isEmpty()) { getSuite().setLocale(new Locale(config.getLocale().substring(0, config.getLocale().indexOf('_')), config.getLocale().substring(config.getLocale().indexOf('_') + 1))); getSuite().setCurrencyFormat(NumberFormat.getInstance(getSuite().getLocale())); ((DecimalFormat) getSuite().getCurrencyFormat()).setParseBigDecimal(true); } if (config.getDelay() != null) { getSuite().setDelay(config.getDelay().longValue()); } System.out.println("URL: " + getSuite().getUrl()); getSuite().setTimeoutUnits(TimeUnit.valueOf(config.getTimeUnit())); getSuite().setPathPatternString(config.getPathString()); getSuite().setFluentWait(new FluentWait<WebDriver>(getSuite().getDriver()) .withTimeout(getSuite().getTimeout(), getSuite().getTimeoutUnits()) .pollingEvery(200, TimeUnit.MILLISECONDS)); Iterator<String> iterClassNames = config.getFluentWaitIgnore().getExceptionClassNames().iterator(); while (iterClassNames.hasNext()) { String className = iterClassNames.next(); Class<? extends Throwable> c = (Class<? extends Throwable>) Class.forName(className); getSuite().getFluentWait().ignoring(c); } } catch (InstantiationException e) { logger.debug(e.getMessage(), e); throw e; } catch (IllegalAccessException e) { logger.debug(e.getMessage(), e); throw e; } catch (ClassNotFoundException e) { logger.debug(e.getMessage(), e); throw e; } catch (Exception e) { logger.debug(e.getMessage(), e); throw e; } }
From source file:Pages.ATT_HomePage.java
License:Open Source License
/** * check whether is at current page - fluent wait check *//*from w w w . j a va2 s.com*/ public Boolean isCurrentPage(int wait_timeout) { //fluent wait method - more flexible, user can pass in wait_timeout to specify how long to wait for certain web element to appear // new UiObject().waitUntilGone FluentWait<WebDriver> pwait = new FluentWait<WebDriver>(driver).withTimeout(wait_timeout, TimeUnit.SECONDS) .pollingEvery(5, TimeUnit.SECONDS).ignoring(NoSuchElementException.class); try { Object interval = pwait.until(new Function<WebDriver, WebElement>() { public WebElement apply(WebDriver d) { WebElement rateButton_obj = d.findElement(By.id("android:id/home")); System.out.println("home icon found"); return rateButton_obj; } }); return true; } catch (TimeoutException t) { System.out.println("Did not find the home icon within fluent wait time"); return false; } }
From source file:Pages.ATT_LikeDislikePage.java
License:Open Source License
public Boolean isCurrentPage(int wait_timeout) { //fluent wait method - more flexible, user can pass in wait_timeout to specify how long to wait for certain web element to appear FluentWait<WebDriver> pwait = new FluentWait<WebDriver>(driver).withTimeout(wait_timeout, TimeUnit.SECONDS) .pollingEvery(5, TimeUnit.SECONDS).ignoring(NoSuchElementException.class); try {//from ww w .j a v a 2 s. c om Object interval = pwait.until(new Function<WebDriver, WebElement>() { public WebElement apply(WebDriver d) { WebElement likeButton_obj = d.findElement(By.name("Like")); System.out.println("likeButton found"); return likeButton_obj; } }); return true; } catch (TimeoutException t) { System.out.println("Did not find the Like Button within fluent wait time"); return false; } }
From source file:Pages.ATT_LikeDislikePage_likesubpage.java
License:Open Source License
/** * check whether is at current page// ww w .jav a 2s.c o m */ public Boolean isCurrentPage(int wait_timeout) { //fluent wait method - more flexible, user can pass in wait_timeout to specify how long to wait for certain web element to appear FluentWait<WebDriver> pwait = new FluentWait<WebDriver>(driver).withTimeout(wait_timeout, TimeUnit.SECONDS) .pollingEvery(5, TimeUnit.SECONDS).ignoring(NoSuchElementException.class); try { Object interval = pwait.until(new Function<WebDriver, WebElement>() { public WebElement apply(WebDriver d) { WebElement rateButton_obj = d.findElement(By.name("Rate")); System.out.println("rateButton found"); return rateButton_obj; } }); return true; } catch (TimeoutException t) { System.out.println("Did not find the rateButton within fluent wait time"); return false; } }
From source file:Pages.ATT_LikeDislikePage_subpages.ATT_dislikesubpage.java
License:Open Source License
/** * check whether is at current page/*from w w w . j ava 2s . c o m*/ */ public Boolean isCurrentPage(int wait_timeout) { //fluent wait method - more flexible, user can pass in wait_timeout to specify how long to wait for certain web element to appear FluentWait<WebDriver> pwait = new FluentWait<WebDriver>(driver).withTimeout(wait_timeout, TimeUnit.SECONDS) .pollingEvery(5, TimeUnit.SECONDS).ignoring(NoSuchElementException.class); try { Object interval = pwait.until(new Function<WebDriver, WebElement>() { public WebElement apply(WebDriver d) { WebElement rateButton_obj = d.findElement(By.name("No, thanks")); System.out.println("nothanksButton found"); return rateButton_obj; } }); return true; } catch (TimeoutException t) { System.out.println("Did not find the nothanksButton within fluent wait time"); return false; } }
From source file:pawl.jbehave.step.MailSteps.java
License:Apache License
/** * Wait until received message with parameters. * * @param recipient of email/*from w w w .j a va 2 s. c o m*/ * @param subject of email */ private void waitUntilReceivedMessageWithParameters(final String recipient, final String subject) { final FluentWait<String> wait = new FluentWait<>(recipient) .withTimeout(Resources.base().explicitWait(), TimeUnit.SECONDS) .pollingEvery(Resources.base().pollingInterval(), TimeUnit.MILLISECONDS); try { wait.until(new Predicate<String>() { @Override public boolean apply(final String recipient) { try { openInboxAs(recipient); } catch (AuthenticationFailedException e) { return false; } return findMessageWithParams(recipient, subject) != null; } }); } catch (TimeoutException e) { throw new AssertionError("Could not find message with parameters: " + "recipient - " + recipient + ", subject - " + subject + "\nin mailbox with : " + recipientsAndSubjects.toString()); } }
From source file:ru.tanyasun.delightex.ft.CreateChatTest.java
License:Open Source License
@Test public void testCreateChat() { String userName = TestUtils.makeUserName(); TestUtils.verifyLoginBox(browser);/*from w w w. j a va2 s . c o m*/ TestUtils.doLogin(browser, userName); WebElement chatNameEdit = browser.findElement(By.xpath("//input[@type='text']")); String newChatName = TestUtils.makeChatName(); chatNameEdit.sendKeys(newChatName); WebElement createButton = browser.findElement(By.xpath("//button[@type='button']")); createButton.click(); browser.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); //By chatNameCondition = By.xpath("//a[contains(text(), '"+newChatName+"')]"); //WebElement chatLink = browser.findElement(chatNameCondition); //chatLink.click(); WebElement captionDiv = browser.findElement(By.xpath(TestUtils.CAPTION_DIV_PATH)); String captionText = captionDiv.getText(); assertTrue(captionText.contains(userName)); assertTrue(captionText.contains("you are in")); assertTrue(captionText.contains(newChatName)); assertTrue(captionText.contains("chat room")); WebElement chatTable = browser.findElement(By.xpath(TestUtils.CHAT_TABLE_XPATH)); By greetingCondition = By.xpath("//div[contains(text(), 'Hello! You are in a chat!')]"); FluentWait<By> messageWait = new FluentWait<By>(greetingCondition); messageWait.pollingEvery(100, TimeUnit.MILLISECONDS); messageWait.withTimeout(1000, TimeUnit.MILLISECONDS); messageWait.until(new Predicate<By>() { public boolean apply(By by) { try { return browser.findElement(by).isDisplayed(); } catch (NoSuchElementException ex) { return false; } } }); WebElement adminGreeting = browser.findElement(greetingCondition); String greetingText = adminGreeting.getText(); assertEquals("Hello! You are in a chat!", greetingText); }
From source file:selenium_tumblr_test.BasePage.java
License:Open Source License
public void clickThenWaitForElementToDisappear(By elementBy, int seconds) { try {//from w ww. j av a 2s. com // find element & click it WebElement element = driver.findElement(elementBy); element.click(); // now wait until element is no longer present or timeout try { (new FluentWait(driver)).withTimeout(seconds, TimeUnit.SECONDS) .pollingEvery(pollInterval, TimeUnit.SECONDS) .until(ExpectedConditions.not(ExpectedConditions.presenceOfElementLocated(elementBy))); } catch (NoSuchElementException noSuchElementException) { } catch (TimeoutException timeoutException) { } // handle any alerts if they pop up } catch (org.openqa.selenium.UnhandledAlertException unhandledAlertException) { try { // try to switch to the alert dialog and accept it Alert alert = driver.switchTo().alert(); alert.accept(); } catch (org.openqa.selenium.NoAlertPresentException noAlertPresentException) { // alert may have gone away. if so, then ignore } } }