Example usage for org.openqa.selenium.support.ui WebDriverWait WebDriverWait

List of usage examples for org.openqa.selenium.support.ui WebDriverWait WebDriverWait

Introduction

In this page you can find the example usage for org.openqa.selenium.support.ui WebDriverWait WebDriverWait.

Prototype

public WebDriverWait(WebDriver driver, Duration timeout) 

Source Link

Document

Wait will ignore instances of NotFoundException that are encountered (thrown) by default in the 'until' condition, and immediately propagate all others.

Usage

From source file:com.elastica.webelements.BasePage.java

License:Apache License

public void waitForElementPresent(final By by) {
    TestLogging.logWebStep(null, "wait for " + by.toString() + " to be present.", false);

    WebDriverWait wait = new WebDriverWait(driver, explictWaitTimeout);
    wait.until(ExpectedConditions.presenceOfElementLocated(by));
}

From source file:com.elastica.webelements.BasePage.java

License:Apache License

public void waitForElementPresent(final By by, final int timeout) {
    TestLogging.logWebStep(null, "wait for " + by.toString() + " to be present.", false);

    WebDriverWait wait = new WebDriverWait(driver, timeout);
    wait.until(ExpectedConditions.presenceOfElementLocated(by));
}

From source file:com.elastica.webelements.BasePage.java

License:Apache License

public void waitForElementPresent(final HtmlElement element) {
    Assert.assertNotNull(element, "Element can't be null");
    TestLogging.logWebStep(null, "wait for " + element.toString() + " to be present.", false);

    WebDriverWait wait = new WebDriverWait(driver, explictWaitTimeout);
    wait.until(ExpectedConditions.presenceOfElementLocated(element.getBy()));
}

From source file:com.elastica.webelements.BasePage.java

License:Apache License

public void waitForElementToBeVisible(final HtmlElement element) {
    Assert.assertNotNull(element, "Element can't be null");
    TestLogging.logWebStep(null, "wait for " + element.toString() + " to be visible.", false);

    WebDriverWait wait = new WebDriverWait(driver, explictWaitTimeout);
    wait.until(ExpectedConditions.visibilityOfElementLocated(element.getBy()));
}

From source file:com.elastica.webelements.BasePage.java

License:Apache License

public void waitForElementToDisappear(final HtmlElement element) {
    Assert.assertNotNull(element, "Element can't be null");
    TestLogging.logWebStep(null, "wait for " + element.toString() + " to disappear.", false);

    WebDriverWait wait = new WebDriverWait(driver, explictWaitTimeout);
    wait.until(ExpectedConditions.invisibilityOfElementLocated(element.getBy()));
}

From source file:com.elastica.webelements.BasePage.java

License:Apache License

public void waitForTextPresent(final HtmlElement element, final String text) {
    Assert.assertNotNull(text, "Text can't be null");
    TestLogging.logWebStep(null, "wait for text \"" + text + "\" to be present.", false);

    WebDriverWait wait = new WebDriverWait(driver, explictWaitTimeout);
    wait.until(ExpectedConditions.textToBePresentInElement(element.getBy(), text));
}

From source file:com.elastica.webelements.HtmlElement.java

License:Apache License

/**
 * Wait element to present using Explicit Waits with timeout in seconds. This method is used for special element
 * which needs long time to present.//from w  w  w . j a v a 2s.  c  om
 */
public void waitForPresent(final int timeout) {
    TestLogging.logWebStep(null, "wait for " + this.toString() + " to present.", false);

    Wait<WebDriver> wait = new WebDriverWait(driver, timeout);
    wait.until(new ExpectedCondition<WebElement>() {
        public WebElement apply(final WebDriver driver) {
            return driver.findElement(by);
        }
    });
}

From source file:com.example.getstarted.basicactions.UserJourneyTestIT.java

License:Apache License

@Test
public void userJourney() throws Exception {
    // Do selenium tests on the deployed version, if applicable
    String endpoint = "http://localhost:8080";
    if (!LOCAL_TEST) {
        endpoint = String.format("https://%s-dot-%s.appspot.com", APP_VERSION, APP_ID);
    }//from www. jav  a 2s.  com
    System.out.println("Testing endpoint: " + endpoint);
    driver.get(endpoint);

    try {
        WebElement button = checkLandingPage();

        if (LOCAL_TEST) {
            WebElement loginButton = driver.findElement(By.linkText("Login"));
            loginButton.click();
            (new WebDriverWait(driver, 10)).until(ExpectedConditions.urlMatches("login"));

            login(EMAIL);
            (new WebDriverWait(driver, 10)).until(ExpectedConditions.urlMatches("/books"));

            button = checkLandingPage(EMAIL);

            button.click();
            (new WebDriverWait(driver, 10)).until(ExpectedConditions.urlMatches(".*/create$"));

            checkAddBookPage();

            submitForm(TITLE, AUTHOR, PUBLISHED_DATE, DESCRIPTION);
            (new WebDriverWait(driver, 10)).until(ExpectedConditions.urlMatches(".*/read\\?id=[0-9]+$"));

            checkReadPage(TITLE, AUTHOR, PUBLISHED_DATE, DESCRIPTION, EMAIL);

            logout(EMAIL);
            (new WebDriverWait(driver, 10))
                    .until(ExpectedConditions.presenceOfElementLocated(By.linkText("Login")));

        } else {
            button.click();
            (new WebDriverWait(driver, 10)).until(ExpectedConditions.urlMatches(".*/create$"));

            checkAddBookPage();

            submitForm(TITLE, AUTHOR, PUBLISHED_DATE, DESCRIPTION);
            (new WebDriverWait(driver, 10)).until(ExpectedConditions.urlMatches(".*/read\\?id=[0-9]+$"));

            checkReadPage(TITLE, AUTHOR, PUBLISHED_DATE, DESCRIPTION, "Anonymous");

            // Now check the list of books for the one we just submitted
            driver.findElement(By.linkText("Books")).click();
            (new WebDriverWait(driver, 10)).until(ExpectedConditions.urlMatches(".*/$"));

            checkBookList(TITLE, AUTHOR, PUBLISHED_DATE, DESCRIPTION);
        }
    } catch (Exception e) {
        System.err.println(driver.getPageSource());
        throw e;
    }
}

From source file:com.example.selenium.action.ExecuteJavaScript.java

@Test
public void testJavaScriptCalls() throws Exception {
    JavascriptExecutor js = (JavascriptExecutor) driver;
    if (driver instanceof JavascriptExecutor) {
        ((JavascriptExecutor) driver).executeScript("sendgetreq()");
        new WebDriverWait(driver, 10).until(ExpectedConditions.alertIsPresent());
        // Get the Alert
        Alert alert = driver.switchTo().alert();
        String response = alert.getText();
        Thread.sleep(1000);//from  www.j av  a  2  s. co m
        alert.accept();
        Assert.assertEquals("HTTP Respose Success", response);
    }
}

From source file:com.example.selenium.FormPage.java

public boolean validateFormPage(UserForm bean) {
    try {/*w ww  . j  a  va  2s .c o m*/
        textInput.sendKeys(bean.getText1());
        Thread.sleep(1000);
        placeHolder.sendKeys(bean.getText2());
        Thread.sleep(1000);

        //File Upload
        file.click();
        Thread.sleep(2000);
        StringSelection ss = new StringSelection(bean.getFilePath());
        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null);
        //imitate mouse events like ENTER, CTRL+C, CTRL+V
        Robot robot = new Robot();
        robot.keyPress(KeyEvent.VK_CONTROL);
        robot.keyPress(KeyEvent.VK_V);
        robot.keyRelease(KeyEvent.VK_V);
        robot.keyRelease(KeyEvent.VK_CONTROL);
        robot.keyPress(KeyEvent.VK_ENTER);
        robot.keyRelease(KeyEvent.VK_ENTER);
        Thread.sleep(2000);

        textArea.sendKeys(bean.getTextArea());
        Thread.sleep(1000);
        if (bean.isCheckBox1()) {
            checkBox1.click();
        } else if (bean.isCheckBox2()) {
            checkBox2.click();
        } else if (bean.isCheckBox3()) {
            checkBox3.click();
        }
        Thread.sleep(1000);
        inlineCheckBox.click();

        if (bean.isRadio1()) {
            radioButton1.click();
        } else if (bean.isRadio2()) {
            radioButton2.click();
        } else if (bean.isRadio3()) {
            radioButton3.click();
        }
        radioButton1.click();
        Thread.sleep(1000);
        radioInline.click();

        dropDown.click();
        Select dropSelect = new Select(dropDown);
        dropSelect.selectByIndex(Integer.parseInt(bean.getDropDownSelect()));
        Thread.sleep(1000);

        multidropDown.click();
        Select multidropSelect = new Select(multidropDown);
        for (String str : bean.getDropMultiSelect()) {
            multidropSelect.selectByIndex(Integer.parseInt(str));
        }
        Thread.sleep(1000);
        submit.click();
        new WebDriverWait(selenium, 10).until(ExpectedConditions.alertIsPresent());
        // Get the Alert
        Alert alert = selenium.switchTo().alert();
        alert.accept();
    } catch (Exception ex) {
        Logger.getLogger(FormPage.class.getName()).log(Level.SEVERE, null, ex);
    }
    return true;
}