List of usage examples for org.openqa.selenium.support.ui FluentWait until
@Override public <V> V until(Function<? super T, V> isTrue)
From source file:com.ionidea.RegressionNGA.Tests.pages.WidgetWorksOfArtPage.java
/** * /* ww w. ja v a 2 s .co m*/ * @param list the list of check-boxes * @return */ public boolean verifyAllCheckBoxesAreUnselected(List<WebElement> list, FluentWait wait) { int index2 = 0; //verify all elements from the list while (index2 < list.size()) { wait.until(ExpectedConditions.elementToBeClickable(list.get(index2))); Assert.assertFalse(list.get(index2).isSelected()); System.out.println("The element is not selected" + list.get(index2)); index2++; } return true; }
From source file:com.ionidea.RegressionNGA.Tests.pages.WidgetWorksOfArtPage.java
/** * /* w ww .j a v a 2s.c o m*/ * @param listToClick - list of WebElements * @return boolean */ public boolean clickAllElements(List<WebElement> listToClick, FluentWait wait) { int index1 = 0; //verify all elements from the list while (index1 < listToClick.size()) { wait.until(ExpectedConditions.elementToBeClickable(listToClick.get(index1))); listToClick.get(index1).click(); index1++; } System.out.println("All elements are selected"); return true; }
From source file:com.ionidea.RegressionNGA.Tests.pages.WidgetWorksOfArtPage.java
/** * // w w w. j av a2 s. c om * @param page - the page * @param list - the list of elements to count across all pages * @return - number of Works of Art * @throws InterruptedException */ public int addToListallWorkObjects(WidgetWorksOfArtPage page, List<WebElement> list, Integer pageNumber, FluentWait wait) throws InterruptedException { int number; // the list will contain elemtns from all pages List<WebElement> entireList = new ArrayList<WebElement>(); entireList.addAll(list); //open all pages one by one and add work objects to the entire list int currentPage = 1; while (currentPage < pageNumber) { Thread.sleep(2000); page.pageButtonNext.get(0).click(); wait.until(ExpectedConditions.visibilityOfAllElements(list)); entireList.addAll(page.artistNameLabels); System.out.println("the entire number is:" + entireList.size()); currentPage++; } System.out.println("The full number of works of art is: 50!"); //get the number of the ojects number = entireList.size(); return number; }
From source file:com.mengge.pagefactory.AppiumElementLocator.java
License:Apache License
private List<WebElement> waitFor() { // When we use complex By strategies (like ChainedBy or ByAll) // there are some problems (StaleElementReferenceException, implicitly // wait time out // for each chain By section, etc) try {//from w ww. j av a 2 s. c o m changeImplicitlyWaitTimeOut(0, TimeUnit.SECONDS); FluentWait<By> wait = new FluentWait<>(by); wait.withTimeout(timeOutDuration.getTime(), timeOutDuration.getTimeUnit()); return wait.until(waitingFunction); } catch (TimeoutException e) { return new ArrayList<>(); } finally { changeImplicitlyWaitTimeOut(timeOutDuration.getTime(), timeOutDuration.getTimeUnit()); } }
From source file:com.robin.utilities.Utilities.java
License:Open Source License
/** * A utility that waits for a gmail mailbox to receive a new message with * according to a given SearchTerm. Only "Not seen" messages are searched, * and all match is set as SEEN, but just the first occurrence of the * matching message is returned./* ww w . j av a2 s .c om*/ * @param username the mailbox owner's user name (no @gmail.com required). * @param pass the user password protecting this mailbox * @param st the SearchTerm built to filter messages * @param timeoutMessage the message to show when no such mail found within * timeout * @param timeout The maximum amount of time to wait in milliseconds. * @return a last from the new messages thats match the st conditions */ public EMail waitForMailWithSearchTerm(final String username, final String pass, final SearchTerm st, final String timeoutMessage, final long timeout) { String host = "imap.gmail.com"; final long retryTime = 1000; Properties props = System.getProperties(); props.setProperty("mail.store.protocol", "imaps"); props.put("mail.imaps.ssl.trust", "*"); EMail email = null; Session session = Session.getDefaultInstance(props, null); try { Store store = session.getStore("imaps"); store.connect(host, username, pass); Folder inbox = store.getFolder("Inbox"); inbox.open(Folder.READ_WRITE); FluentWait<Folder> waitForMail = new FluentWait<Folder>(inbox) .withTimeout(timeout, TimeUnit.MILLISECONDS).pollingEvery(retryTime, TimeUnit.MILLISECONDS) .withMessage(timeoutMessage); email = waitForMail.until(new Function<Folder, EMail>() { @Override public EMail apply(final Folder inbox) { EMail email = null; FlagTerm ft = new FlagTerm(new Flags(Flags.Flag.SEEN), false); SearchTerm sst = new AndTerm(ft, st); try { inbox.getMessageCount(); Message[] messages = inbox.search(sst); for (Message message : messages) { message.setFlag(Flag.SEEN, true); } if (messages.length > 0) { return new EMail(messages[0]); } } catch (MessagingException e) { Assert.fail(e.getMessage()); } return email; } }); inbox.close(false); store.close(); } catch (MessagingException e) { Assert.fail(e.getMessage()); } return email; }
From source file:com.synapticpath.naica.selenium.SeleniumUtils.java
License:Open Source License
/** * Call this method to find a WebElement. Several parameters are supported. * //from w w w. java 2s.co m * @param elementSelector * Will be used as primary criteria to find an element. * @param visible * When not null, will be evaluated for visibility on page. That is, the desired element must * also be visible when true, or invisible when false. * @param withText * if specified, the element.getText must match also. * @param timeout * positive number of seconds to wait * @return the {@link WebElement} when found, null if not found in timeout reached first. */ public static WebElement findElementWithTimeout(final SeleniumSelector elementSelector, final Boolean visible, final String withText, int timeout) { final WebDriver driver = SeleniumTestContext.getInstance().getDriver(); FluentWait<WebDriver> wait = new FluentWait<WebDriver>(driver) .withTimeout(timeout > -1 ? timeout : MAX_WAIT, TimeUnit.SECONDS) .pollingEvery(POLL_INTERVAL_MILLIS, TimeUnit.MILLISECONDS).ignoring(NoSuchElementException.class) .ignoring(TimeoutException.class); try { return wait.until((WebDriver d) -> { WebElement e = d.findElement(elementSelector.toBySelector()); if (e != null && (withText == null || e.getText().contains(withText)) && (visible == null || visible && e.isDisplayed() || !visible && !e.isDisplayed())) { return e; } return null; }); } catch (TimeoutException te) { logger.severe(format("Element selected by %s, visible:%s, withText:%s was not found in time.", elementSelector, visible, withText)); } return null; }
From source file:com.synapticpath.naica.selenium.SeleniumUtils.java
License:Open Source License
/** * Polls through Selenium driver until an element matched by given {@link SeleniumSelector} can no longer be found. * //from w w w . j a va2s .c o m * @param elementSelector * @param timeout * number of seconds to wait if positive number, otherwise * default will be applied. * @return true when element disappears, false otherwise */ public static boolean waitUntilElementGoneWithTimeout(final SeleniumSelector elementSelector, final int timeout) { final WebDriver driver = SeleniumTestContext.getInstance().getDriver(); FluentWait<WebDriver> wait = new FluentWait<WebDriver>(driver) .withTimeout(timeout > -1 ? timeout : MAX_WAIT, TimeUnit.SECONDS) .pollingEvery(POLL_INTERVAL_MILLIS, TimeUnit.MILLISECONDS).ignoring(NoSuchElementException.class); try { return wait.until((WebDriver d) -> d.findElements(elementSelector.toBySelector()).size() == 0); } catch (TimeoutException te) { logger.severe( format("Element selected by %s did not go away in time.", elementSelector.toBySelector())); } return false; }
From source file:com.synapticpath.naica.selenium.SeleniumUtils.java
License:Open Source License
/** * Polls through Selenium driver until://from ww w . j av a 2 s . co m * a) browser URL contains desired String * b) timeout is reached * * @param text * @param timeout * @return true when url contains the text, false if timeout reached. */ public static boolean waitUntilUrlContains(final String text, int timeout) { final WebDriver driver = SeleniumTestContext.getInstance().getDriver(); FluentWait<WebDriver> wait = new FluentWait<WebDriver>(driver) .withTimeout(timeout > -1 ? timeout : MAX_WAIT, TimeUnit.SECONDS) .pollingEvery(POLL_INTERVAL_MILLIS, TimeUnit.MILLISECONDS).ignoring(NoSuchElementException.class); try { return wait.until(ExpectedConditions.urlContains(text)); } catch (TimeoutException te) { logger.severe(format("Url did not contain text %s in time.", text)); } return false; }
From source file:com.worldline.easycukes.selenium.utils.SeleniumHelper.java
License:Open Source License
/** * @param driver//from w w w. ja v a 2 s.c o m * @param by * @return */ public static WebElement waitForElementToBePresent(@NonNull final WebDriver driver, @NonNull final By by) { final FluentWait<WebDriver> wait = new FluentWait<>(driver) .withTimeout(WAITING_TIME_OUT_IN_SECONDS, TimeUnit.SECONDS) .pollingEvery(POLLING_INTERVAL_IN_MILLIS, TimeUnit.MILLISECONDS) .ignoring(NoSuchElementException.class); return wait.until(new ExpectedCondition<WebElement>() { @Override public WebElement apply(WebDriver webDriver) { try { if (webDriver.findElement(by).isDisplayed()) return webDriver.findElement(by); return null; } catch (final ElementNotVisibleException e) { return null; } } }); }
From source file:com.worldline.easycukes.selenium.utils.SeleniumHelper.java
License:Open Source License
/** * @return/*from w w w . j a v a 2 s.co m*/ */ public static void waitUntilElementIsHidden(@NonNull final WebDriver driver, @NonNull final By by) { // Waiting for an element to be present on the page, checking for its // presence once every second. final FluentWait<WebDriver> wait = new FluentWait<>(driver) .withTimeout(WAITING_TIME_OUT_IN_SECONDS, TimeUnit.SECONDS) .pollingEvery(POLLING_INTERVAL_IN_MILLIS, TimeUnit.MILLISECONDS).ignoring(TimeoutException.class); wait.until(new ExpectedCondition<Boolean>() { @Override public Boolean apply(WebDriver webDriver) { try { log.debug("waiting for hidden " + by); final List<WebElement> list = webDriver.findElements(by); for (final WebElement webElement : list) if (webElement.isDisplayed()) { log.debug("Still displayed !");// TODO return false; } return true; } catch (final StaleElementReferenceException e) { return true; } catch (final NoSuchElementException e) { return true; } } }); }