Java 类org.openqa.selenium.support.ui.Wait 实例源码

项目:marathonv5    文件:JProgressBarTest.java   
public void progress() throws Throwable {
    driver = new JavaDriver();
    final WebElement progressbar = driver.findElement(By.cssSelector("progress-bar"));
    AssertJUnit.assertNotNull("could not find progress-bar", progressbar);
    AssertJUnit.assertEquals("0", progressbar.getAttribute("value"));
    driver.findElement(By.cssSelector("button")).click();

    Wait<WebDriver> wait = new WebDriverWait(driver, 30);
    // Wait for a process to complete
    wait.until(new ExpectedCondition<Boolean>() {
        @Override public Boolean apply(WebDriver webDriver) {
            return progressbar.getAttribute("value").equals("100");
        }
    });

    AssertJUnit.assertEquals("100", progressbar.getAttribute("value"));
    AssertJUnit.assertTrue(driver.findElement(By.cssSelector("text-area")).getText().contains("Done!"));
}
项目:ats-framework    文件:AbstractHtmlEngine.java   
private void switchToWindowByTitle(
                                    final String windowTitle,
                                    long timeoutInSeconds ) {

    ExpectedCondition<Boolean> expectation = new ExpectedCondition<Boolean>() {
        public Boolean apply(
                              WebDriver driver ) {

            return switchToWindowByTitle(windowTitle);
        }
    };
    Wait<WebDriver> wait = new WebDriverWait(webDriver, timeoutInSeconds);
    try {
        wait.until(expectation);
    } catch (Exception e) {
        throw new SeleniumOperationException("Timeout waiting for Window with title '" + windowTitle
                                             + "' to appear.", e);
    }
}
项目:willtest    文件:TimeoutsConfigurationParticipant.java   
/**
 * If there is an implicit wait set, then you might need to wait for a shorter period. This
 * method makes it possible with setting the implicit wait temporarily to 0.
 *
 * @param webDriver webdriver to be used
 * @param seconds timeout in seconds
 * @return a {@link Wait} instance, which set the implicit wait temporarily to 0.
 */
public Wait<WebDriver> waitOverridingImplicitWait(WebDriver webDriver, int seconds) {
    //API comes from selenium -> cannot migrate guava to java 8
    //noinspection Guava
    return new Wait<WebDriver>() {
        @Override
        public <T> T until(Function<? super WebDriver, T> function) {
            Timeouts timeouts = webDriver.manage().timeouts();
            try {
                timeouts.implicitlyWait(0, TimeUnit.SECONDS);
                return new WebDriverWait(webDriver, seconds, CONDITION_POLL_INTERVAL).until(function);
            } finally {
                timeouts.implicitlyWait(implicitWait.getNano(), TimeUnit.NANOSECONDS);
            }
        }
    };
}
项目:POM_HYBRID_FRAMEOWRK    文件:WebUtilities.java   
/**
 * Wait for element to appear.
 *
 * @param driver the driver
 * @param element the element
 * @param logger the logger
 */
public static boolean waitForElementToAppear(WebDriver driver, WebElement element, ExtentTest logger) {
    boolean webElementPresence = false;
    try {
        Wait<WebDriver> fluentWait = new FluentWait<WebDriver>(driver).pollingEvery(2, TimeUnit.SECONDS)
                .withTimeout(60, TimeUnit.SECONDS).ignoring(NoSuchElementException.class);
        fluentWait.until(ExpectedConditions.visibilityOf(element));
        if (element.isDisplayed()) {
            webElementPresence= true;
        }
    } catch (TimeoutException toe) {
        logger.log(LogStatus.ERROR, "Timeout waiting for webelement to be present<br></br>" + toe.getStackTrace());
    } catch (Exception e) {
        logger.log(LogStatus.ERROR, "Exception occured<br></br>" + e.getStackTrace());
    }
    return webElementPresence;
}
项目:POM_HYBRID_FRAMEOWRK    文件:WebPage.java   
public static void waitForPageLoad(WebDriver driver) {

        Wait<WebDriver> wait = new WebDriverWait(driver, 30);
        wait.until(new Function<WebDriver, Boolean>() {

            /* (non-Javadoc)
             * @see java.util.function.Function#apply(java.lang.Object)
             */
            public Boolean apply(WebDriver driver_) {
                System.out.println("Current Window State       : "
                        + String.valueOf(((JavascriptExecutor) driver).executeScript("return document.readyState")));
                return String.valueOf(((JavascriptExecutor) driver).executeScript("return document.readyState"))
                        .equals("complete");
            }
        });
    }
项目:helium    文件:ConfiguracioFestius.java   
private void marcarDiaCalendari(String idElem, boolean festiu) {

    String xPathFinal = "";
    if (festiu) {
        xPathFinal = "//*[@id='"+idElem+"'][contains(@class, 'festiu')]";
    }else{
        xPathFinal = "//*[@id='"+idElem+"'][not[contains(@class, 'festiu')]]";
    }

    //Clicam l´element y esperam un max de 10s si la pagina es recarrega amb l´element indicat marcat com a festiu o no (segons el booleà passat)
    driver.findElement(By.id(idElem)).click();

//Esperam fins a trobar la cel.la corresponent a dia 1 de gener de l´any escollit (maxim 10s.)
Wait<WebDriver> wait = new WebDriverWait(driver, 10);
      try {
        wait.until(visibilityOfElementLocated(By.xpath(xPathFinal)));
      }catch (Exception ex) {}
  }
项目:frameworkium-core    文件:HeaderComponent.java   
private void showHeaderMenuIfCollapsed() {
    Wait<WebDriver> wait = BaseUITest.newDefaultWait();

    // If browser is opened with width of 960 pixels or less
    // then the Header Menu is not displayed and a 'Hamburger' button is displayed instead. 
    // This button needs to be clicked to display the Header Menu.
    if (!headerMenu.isDisplayed()) {
        if (!hamburgerButton.isDisplayed()) {
            // Sometimes the Hamburger button is not initially displayed
            // so click the Header element to display the button 
            this.click();
        }
        hamburgerButton.click();

        // Ensure the Header Menu is displayed before attempting to click a link
        wait.until(ExpectedConditions.visibilityOf(headerMenu));
    }
}
项目:WebAuto    文件:Browser.java   
/**
 * Wait For the Page to Load in the Browser
 * 
 * @param driver
 */
public synchronized void waitForPageLoaded() {
    ExpectedCondition<Boolean> expectation = new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver driver) {
            return ((JavascriptExecutor) DriverManager.getDriver()).executeScript(
                    "return document.readyState").equals("complete");
        }
    };

    Wait<WebDriver> wait = new WebDriverWait(DriverManager.getDriver(), 30);
    try {
        wait.until(expectation);
    } catch (Throwable error) {
        new SelTestException(
                "Timeout waiting for Page Load Request to complete.");
    }
}
项目:Testy    文件:WebLocatorDriverExecutor.java   
private WebElement doWaitElement(final WebLocator el, final long millis) {
    Wait<WebDriver> wait = new FluentWait<>(driver)
            .withTimeout(millis, TimeUnit.MILLISECONDS)
            .pollingEvery(1, TimeUnit.MILLISECONDS)
            .ignoring(NoSuchElementException.class)
            .ignoring(ElementNotVisibleException.class)
            .ignoring(WebDriverException.class);

    try {
        if (el.getPathBuilder().isVisibility()) {
            el.currentElement = wait.until(ExpectedConditions.visibilityOfElementLocated(el.getSelector()));
        } else {
            el.currentElement = wait.until(d -> d.findElement(el.getSelector()));
        }
    } catch (TimeoutException e) {
        el.currentElement = null;
    }
    return el.currentElement;
}
项目:carina    文件:ExtendedWebElement.java   
/**
 * is Element Not Present After Wait
 *
 * @param timeout in seconds
 * @return boolean - false if element still present after wait - otherwise true if it disappear
 */
public boolean isElementNotPresentAfterWait(final long timeout) {
    final ExtendedWebElement element = this;

    LOGGER.info(String.format("Check element %s not presence after wait.", element.getName()));

    Wait<WebDriver> wait =
            new FluentWait<WebDriver>(getDriver()).withTimeout(timeout, TimeUnit.SECONDS).pollingEvery(1,
                    TimeUnit.SECONDS).ignoring(NoSuchElementException.class);
    try {
        return wait.until(driver -> {
            boolean result = driver.findElements(element.getBy()).isEmpty();
            if (!result) {
                LOGGER.info(String.format("Element '%s' is still present. Wait until it disappear.", element
                        .getNameWithLocator()));
            }
            return result;
        });
    } catch (Exception e) {
        LOGGER.error("Error happened: " + e.getMessage(), e.getCause());
        LOGGER.warn("Return standard element not presence method");
        return !element.isElementPresent();
    }
}
项目:POM_HYBRID_FRAMEOWRK    文件:WebUtilities.java   
/**
 * Wait for element to disappear.
 *
 * @param driver the driver
 * @param element the element
 * @param logger the logger
 * @return true, if successful
 */
public static boolean waitForElementToDisappear(WebDriver driver, WebElement element, ExtentTest logger) {
    try {
        Wait<WebDriver> fluentWait = new FluentWait<WebDriver>(driver).withTimeout(60, TimeUnit.SECONDS)
                .pollingEvery(2, TimeUnit.SECONDS).ignoring(NoSuchElementException.class);

        fluentWait.until(ExpectedConditions.invisibilityOf(element));
        return true;
    } catch (Exception e) {
        logger.log(LogStatus.ERROR,
                "Error occured while waiting for element to disappear</br>" + e.getStackTrace());
        return false;
    }
}
项目:helium    文件:ConfiguracioFestius.java   
@Test
public void b1_canviar_any() {

    carregarUrlConfiguracio();
    accedirConfiguracioFestius();

    screenshotHelper.saveScreenshot("configuracio/festius/b1_1_llista_festius_any_actual.png");

    //Seleccionar any anterior
    String anyAnterior = Integer.toString(dataAvull.get(Calendar.YEAR)-1);
    for (WebElement option : driver.findElement(By.xpath("//*[@id='content']/h3/form/select")).findElements(By.tagName("option"))) {
        if (anyAnterior.equals(option.getAttribute("value"))) {
            option.click();
            break;
        }
    }

    //Funcio que marca un dia del calendari (donada la id) y espera un maxim de 7s fins que es carregui el nou calendari via ajax.
    //Esperam fins a trobar la cel.la corresponent a dia 1 de gener de l´any escollit (maxim 10s.)
    Wait<WebDriver> wait = new WebDriverWait(driver, 10);
       WebElement element = wait.until(visibilityOfElementLocated(By.id("dia_01/01/"+anyAnterior)));

       if (element==null) {
        fail("La pagina del calendari corresponent a l'id dia_01/01/"+anyAnterior+" ha tardat massa a carregar.");
       }else{
        screenshotHelper.saveScreenshot("configuracio/festius/b1_2_llista_festius_any_anterior.png");
       }
}
项目:qa-automation    文件:WebDriverUtils.java   
public static void waitForElementPresent(WebDriver driver, WebElement element){
    Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
            .withTimeout(60, SECONDS)
            .pollingEvery(5, SECONDS)
            .ignoring(NoSuchElementException.class);
    wait.until(ExpectedConditions.visibilityOf(element));
}
项目:che    文件:PullRequestPanel.java   
public void openPullRequestOnGitHub() {
  Wait<WebDriver> wait =
      new FluentWait(seleniumWebDriver)
          .withTimeout(ATTACHING_ELEM_TO_DOM_SEC, SECONDS)
          .pollingEvery(500, MILLISECONDS)
          .ignoring(WebDriverException.class);
  wait.until(visibilityOfElementLocated(By.xpath(PullRequestLocators.OPEN_GITHUB_BTN))).click();
}
项目:che    文件:Consoles.java   
public void openServersTabFromContextMenu(String machineName) {
  Wait<WebDriver> wait =
      new FluentWait<WebDriver>(seleniumWebDriver)
          .withTimeout(ELEMENT_TIMEOUT_SEC, SECONDS)
          .pollingEvery(500, MILLISECONDS)
          .ignoring(WebDriverException.class);

  WebElement machine =
      wait.until(visibilityOfElementLocated(By.xpath(format(MACHINE_NAME, machineName))));
  wait.until(visibilityOf(machine)).click();

  actionsFactory.createAction(seleniumWebDriver).moveToElement(machine).contextClick().perform();
  redrawDriverWait.until(visibilityOf(serversMenuItem)).click();
}
项目:che    文件:CommandsToolbar.java   
/** wait appearance of process timer on commands toolbar and try to get value of the timer */
public String getTimerValue() {
  Wait<WebDriver> wait =
      new FluentWait<WebDriver>(seleniumWebDriver)
          .withTimeout(REDRAW_UI_ELEMENTS_TIMEOUT_SEC, TimeUnit.SECONDS)
          .pollingEvery(200, TimeUnit.MILLISECONDS)
          .ignoring(StaleElementReferenceException.class);

  return wait.until(driver -> driver.findElement(By.id(Locators.TIMER_LOCATOR)).getText());
}
项目:che    文件:Swagger.java   
/** expand 'workspace' item */
private void expandWorkSpaceItem() {
  Wait fluentWait =
      new FluentWait(seleniumWebDriver)
          .withTimeout(LOAD_PAGE_TIMEOUT_SEC, SECONDS)
          .pollingEvery(MINIMUM_SEC, SECONDS)
          .ignoring(StaleElementReferenceException.class, NoSuchElementException.class);
  fluentWait.until((ExpectedCondition<Boolean>) input -> workSpaceLink.isEnabled());
  workSpaceLink.click();
}
项目:web-test-framework    文件:PageWaits.java   
/**
 *
 * @return
 */
public T loaded() {
  page.getDriver().logStep("WAIT FOR PAGE TO LOAD: \"" + page.getUrl() + "\"");
  Wait<WebDriver> wait = new WebDriverWait(page.getDriver(), maxWaitForPageLoadSeconds);
  wait.until(new ExpectedCondition<Boolean>() {

    @Override
    public Boolean apply(WebDriver driver) {
      return page.isLoaded();
    }

  });
  return page;
}
项目:web-test-framework    文件:PageWaits.java   
/**
 *
 * @return
 */
public T correctPage() {
  page.getDriver().logStep("WAIT FOR CORRECT PAGE : \"" + page.getUrl() + "\"");

  Wait<WebDriver> wait = new WebDriverWait(page.getDriver(), maxWaitForUrlSeconds);
  wait.until(new ExpectedCondition<Boolean>() {

    @Override
    public Boolean apply(WebDriver f) {
      return page.isCorrectPage();
    }

  });
  return page;
}
项目:web-test-framework    文件:PageWaits.java   
/**
 *
 * @return
 */
public T jQueryToExist() {
  page.getDriver().logStep("WAIT FOR JQUERY TO EXIST : \"" + page.getUrl() + "\"");
  Wait<WebDriver> wait = new WebDriverWait(page.getDriver(), maxJQueryWaitSeconds);
  wait.until(ExpectedConditionsAdditional.jQueryExists());
  return page;
}
项目:web-test-framework    文件:PageWaits.java   
/**
 *
 * @return
 */
public T jQueryNotActive() {
  page.getDriver().logStep("WAIT FOR JQUERY NOT ACTIVE : \"" + page.getUrl() + "\"");
  Wait<WebDriver> wait = new WebDriverWait(page.getDriver(), maxJQueryWaitSeconds);
  wait.until(ExpectedConditionsAdditional.jQueryNotActive());
  return page;
}
项目:web-test-framework    文件:PageWaits.java   
/**
 *
 * @return
 */
public T jQueryToExistAndNotActive() {
  page.getDriver().logStep("WAIT FOR JQUERY TO EXIST AND NOT BE ACTIVE: \"" + page.getUrl() + "\"");
  Wait<WebDriver> wait = new WebDriverWait(page.getDriver(), maxJQueryWaitSeconds);
  wait.until(ExpectedConditionsAdditional.jQueryExists());
  wait.until(ExpectedConditionsAdditional.jQueryNotActive());
  return page;
}
项目:frameworkium-core    文件:HeaderComponent.java   
@Step("Testing Visibility.forceVisible()")
public void testForceVisible() {
    Wait<WebDriver> wait = BaseUITest.newDefaultWait();

    WebElement link = homeLink.getWrappedElement();
    // hide the home link
    BaseUITest.getDriver().executeScript(
            "arguments[0].style.visibility='hidden';", link);
    wait.until(ExpectedConditions.not(visibilityOf(link)));
    // test force visible works
    new Visibility().forceVisible(link);
    wait.until(visibilityOf(link));
}
项目:seauto    文件:HtmlView.java   
/**
 * Waits for an element to appear on the page before returning. Example:
 * WebElement waitElement =
 * fluentWait(By.cssSelector(div[class='someClass']));
 * 
 * @param locator locator of the element to find
 * @return Web element of found element
 */
protected WebElement waitForElementToAppear(final By locator)
{
  Wait<WebDriver> wait = new FluentWait<WebDriver>(webDriver).withTimeout(30, TimeUnit.SECONDS).pollingEvery(5, TimeUnit.SECONDS).ignoring(NoSuchElementException.class);

  WebElement element = null;
  try {
    element = wait.until(new Function<WebDriver, WebElement>() {

      @Override
      public WebElement apply(WebDriver driver)
      {
        return driver.findElement(locator);
      }
    });
  }
  catch (TimeoutException e) {
    try {
      // I want the error message on what element was not found
      webDriver.findElement(locator);
    }
    catch (NoSuchElementException renamedErrorOutput) {
      // print that error message
      renamedErrorOutput.addSuppressed(e);
      // throw new
      // NoSuchElementException("Timeout reached when waiting for element to be found!"
      // + e.getMessage(), correctErrorOutput);
      throw renamedErrorOutput;
    }
    e.addSuppressed(e);
    throw new NoSuchElementException("Timeout reached when searching for element!", e);
  }

  return element;
}
项目:BRAP    文件:Player.java   
public  void fluentWaitTillVisible(WebElement we,WebDriver driver) {
    Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
            .withTimeout(30, TimeUnit.SECONDS)
            .pollingEvery(5, TimeUnit.SECONDS)
            .ignoring(NoSuchElementException.class);
    wait.until(ExpectedConditions.visibilityOf(we));
}
项目:BRAP    文件:Player.java   
public  void fluentWaitTillClickable(WebElement we,WebDriver driver) {
    Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
            .withTimeout(30, TimeUnit.SECONDS)
            .pollingEvery(5, TimeUnit.SECONDS)
            .ignoring(NoSuchElementException.class);
    wait.until(ExpectedConditions.elementToBeClickable(we));
}
项目:automation-test-engine    文件:AbstractElementFind.java   
/**
 * @return the wait
 */
public Wait<WebDriver> getWait() {
    final Wait<WebDriver> retVal = wait;
    if (null == retVal) {
        throw new IllegalStateException("wait is not correctly populated");

    } else {
        return retVal;
    }
}
项目:seletest    文件:AbstractPage.java   
/**
 * Wait for page to load
 * @param pageLoadCondition
 */
private void waitForPageToLoad(ExpectedCondition<?> pageLoadCondition) {
    Wait wait = new FluentWait(SessionContext.getSession().getWebDriver())
            .withTimeout(LOAD_TIMEOUT, TimeUnit.SECONDS)
            .pollingEvery(REFRESH_RATE, TimeUnit.SECONDS);

    wait.until(pageLoadCondition);
}
项目:Mahesh.tutorials    文件:WrapperFunctions.java   
/**
 * @param driver
 * @param element
 * @param sec
 * @return
 */

public static boolean waitForElementToBePresent(WebDriver driver,
        By element, Integer sec) {

    Wait<WebDriver> wait = new WebDriverWait(driver, DELAY * sec);
    ExpectedCondition<WebElement> condition = new ElementPresent(element);
    try {
        @SuppressWarnings("unused")
        WebElement we = wait.until(condition);
        return true;
    } catch (WebDriverException e) {
        return false;
    }
}
项目:Mahesh.tutorials    文件:WrapperFunctions.java   
/**
 * @param driver
 * @param element
 * @param sec
 * @return
 */

public static WebElement waitForElement(WebDriver driver, By element,
        int sec) {
    Wait<WebDriver> wait = new WebDriverWait(driver, DELAY * sec);
    ExpectedCondition<WebElement> condition = new ElementPresent(element);
    try {
        WebElement we = wait.until(condition);
        return we;
    } catch (WebDriverException e) {
        return null;
    }
}
项目:sulfur    文件:SPage.java   
/**
 * Wait for SPage to Load.
 * It will wait for all the internal SPageComponent to finish loading
 *
 * @param timeout Time before giving up the waiting
 * @param timeoutUnit Time Unit used by timeout parameter
 * @param polling Time interval between checking if SPage has loaded
 * @param pollingUnit Time Unit used by polling parameter
 */
public void waitForLoad(long timeout, TimeUnit timeoutUnit, long polling, TimeUnit pollingUnit) {
    Wait<SPage> waiter = new FluentWait<SPage>(this)
            .pollingEvery(polling, pollingUnit)
            .withTimeout(timeout, timeoutUnit);

    waiter.until(new Function<SPage, Boolean>() {
        public Boolean apply(SPage page) {
            LOG.debug(String.format("Waiting for SPage '%s' to load", getName()));
            return page.isLoaded();
        }
    });
}
项目:sulfur    文件:SPageComponent.java   
/**
 * Wait for SPageComponent to Load.
 * It will wait for {@link sulfur.SPageComponent#isLoaded()} to return "true".
 *
 * @param timeout Time before giving up the waiting
 * @param timeoutUnit Time Unit used by timeout parameter
 * @param polling Time interval between checking if SPage has loaded
 * @param pollingUnit Time Unit used by polling parameter
 */
public void waitForLoad(long timeout, TimeUnit timeoutUnit, long polling, TimeUnit pollingUnit) {
    Wait<SPageComponent> waiter = new FluentWait<SPageComponent>(this)
            .pollingEvery(polling, pollingUnit)
            .withTimeout(timeout, timeoutUnit);

    waiter.until(new Function<SPageComponent, Boolean>() {
        public Boolean apply(SPageComponent pageComponent) {
            LOG.debug(String.format("Waiting for SPageComponent '%s' in SPage '%s' to load",
                    pageComponent.getName(),
                    pageComponent.getContainingPage().getName()));
            return pageComponent.isLoaded();
        }
    });
}
项目:colibri-ui    文件:AbsFinder.java   
@Override
public WebElement waitClickable(By by) {
    Wait<WebDriver> wait = new WebDriverWait(getDriver(), getDriversSettings().getFindingTimeOutInSeconds());
    return wait.until(ExpectedConditions.elementToBeClickable(by));
}
项目:colibri-ui    文件:AbsFinder.java   
@Override
public WebElement waitVisible(By by) {
    Wait<WebDriver> wait = new WebDriverWait(getDriver(), getDriversSettings().getFindingTimeOutInSeconds());
    return wait.until(ExpectedConditions.visibilityOfElementLocated(by));
}
项目:blog-java2    文件:WebDriverWrapper.java   
protected void waitForPageLoaded() {
    Wait<WebDriver> wait = new WebDriverWait(this, 100);
    wait.until(expectation);
}
项目:web-test-framework    文件:SeleniumHelperUtil.java   
/**
 *
 * @param driver
 * @param secondsToWait
 */
public static void waitForJQueryExistsAndNotActive(WebDriver driver, Integer secondsToWait) {
      Wait<WebDriver> wait = new WebDriverWait(driver, secondsToWait);
      wait.until(ExpectedConditionsAdditional.jQueryExists());
      wait.until(ExpectedConditionsAdditional.jQueryNotActive());
  }
项目:frameworkium-core    文件:Visibility.java   
public Visibility(Wait<WebDriver> wait, JavascriptExecutor driver) {
    this.wait = wait;
    this.driver = driver;
}
项目:frameworkium-core    文件:JavascriptWait.java   
public JavascriptWait(WebDriver driver, Wait<WebDriver> wait) {
    this.wait = wait;
    this.javascriptExecutor = (JavascriptExecutor) driver;
}
项目:frameworkium-core    文件:BaseUITest.java   
/** Required for unit testing. */
static void setWait(Wait<WebDriver> newWait) {
    wait.set(newWait);
}
项目:frameworkium-core    文件:BaseUITest.java   
/** Create a new {@link Wait} for the thread local driver and default timeout. */
public static Wait<WebDriver> newDefaultWait() {
    return newWaitWithTimeout(DEFAULT_TIMEOUT_SECONDS);
}