Example usage for org.openqa.selenium.support.ui Wait until

List of usage examples for org.openqa.selenium.support.ui Wait until

Introduction

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

Prototype

<T> T until(Function<? super F, T> isTrue);

Source Link

Document

Implementations should wait until the condition evaluates to a value that is neither null nor false.

Usage

From source file:org.callimachusproject.webdriver.helpers.WebBrowserDriver.java

License:Apache License

public void waitUntilModalOpen() {
    Wait<WebDriver> wait = new WebDriverWait(driver, 240);
    assertTrue(wait.until(new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver wd) {
            List<WebElement> modals = wd.findElements(By.cssSelector(".modal.fade.in"));
            if (modals.isEmpty())
                return false;
            for (WebElement modal : modals) {
                if (!modal.getCssValue("opacity").equals("1"))
                    return false;
            }//from ww w  . j a v a2 s .co m
            return true;
        }

        public String toString() {
            return "modal to open";
        }
    }));
}

From source file:org.eclipse.che.selenium.pageobject.intelligent.CommandsToolbar.java

License:Open Source License

/** 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());
}

From source file:org.eclipse.che.selenium.pageobject.PullRequestPanel.java

License:Open Source License

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();
}

From source file:org.eclipse.che.selenium.pageobject.Swagger.java

License:Open Source License

/** expand 'workspace' item */
private void expandWorkSpaceItem() {
    Wait fluentWait = new FluentWait(seleniumWebDriver).withTimeout(ELEMENT_TIMEOUT_SEC, SECONDS)
            .pollingEvery(MINIMUM_SEC, SECONDS)
            .ignoring(StaleElementReferenceException.class, NoSuchElementException.class);
    fluentWait.until((ExpectedCondition<Boolean>) input -> workSpaceLink.isEnabled());
    workSpaceLink.click();//from  ww w  .jav  a  2s .  co m
}

From source file:org.eclipse.skalli.selenium.pageobjects.AbstractPage.java

License:Open Source License

/**
 * Explicitly waits for the page to load (until {@link #isDisplayed()} returns {@code true})
 *///from   w  ww .j  a  v a2s . co m
public void explicitWaitForPage() {
    Wait<WebDriver> wait = new WebDriverWait(driver, WAIT_FOR_PAGE_TO_LOAD_TIME);

    wait.until(new ExpectedCondition<WebElement>() {
        @Override
        public WebElement apply(WebDriver driver) {
            try {
                if (isDisplayed()) {
                    return explicitWaitReturn();
                }
            } catch (Exception e) {
                //avoid that any exception causes the wait to be stopped
                //print out the error message to identify which UI element cannot be found
                System.out.println(e.getMessage());
            }

            return null;
        }
    });
}

From source file:org.jboss.arquillian.jbehave.examples.client.ExchangeCurrenciesPage.java

License:Apache License

public ExchangeCurrenciesPage(WebDriver driver, URL contextRoot) {
    this.driver = driver;
    this.contextPath = contextRoot;
    Wait<WebDriver> wait = new WebDriverWait(driver, 15);
    wait.until(PageUtilities.visibilityOfElementLocated(By.id("inputForm")));
    if (!driver.getCurrentUrl().equals(contextPath.toString())
            && !driver.getCurrentUrl().equals(contextPath + PAGE_NAME)) {
        throw new IllegalStateException("This is not the Index page.");
    }//from  ww  w  .  j  a va2s  .c  om
}

From source file:org.jboss.arquillian.jbehave.examples.client.ExchangeCurrenciesPage.java

License:Apache License

public BigDecimal getQuoteFromPage() {
    Wait<WebDriver> wait = new WebDriverWait(driver, 15);
    wait.until(PageUtilities.visibilityOfElementLocated(By.id("inputForm:quote")));
    WebElement quote = driver.findElement(By.id("inputForm:quote"));
    return new BigDecimal(quote.getText());
}

From source file:org.jboss.forge.scaffold.angularjs.scenario.dronetests.manytoone.ManyStoreOrderAndOneCustomerViewsClient.java

License:Open Source License

@Test
@InSequence(1)//  www .  j  av a 2  s.co m
public void testSaveNewCustomer(@ArquillianResource URL baseUrl) throws Exception {
    Wait<WebDriver> wait = new WebDriverWait(driver, 10);

    // Click on the Customers nav entry
    driver.get(baseUrl.toString() + "app.html#/");
    driver.findElement(By.linkText("Customers")).click();
    wait.until(new HasLandedOnSearchCustomerView());

    // Choose to create a new customer 
    driver.findElement(By.id("Create")).click();
    wait.until(new HasLandedOnNewCustomerView());

    // Enter the customer details and save
    driver.findElement(By.id("firstName")).clear();
    driver.findElement(By.id("firstName")).sendKeys("John Doe");
    driver.findElement(By.id("dateOfBirth")).clear();
    driver.findElement(By.id("dateOfBirth")).sendKeys("2013-01-10");
    driver.findElement(By.id("saveCustomer")).click();

    // Verify the details are presented in the Edit view 
    wait.until(new HasLandedOnEditCustomerView());
    assertEquals(baseUrl.toString() + "app.html#/Customers/edit/1", driver.getCurrentUrl());
    assertEquals("John Doe", driver.findElement(By.id("firstName")).getAttribute("value"));
    assertEquals("2013-01-10", driver.findElement(By.id("dateOfBirth")).getAttribute("value"));

    // Browse to search customer view and verify if searching for the customer works 
    driver.findElement(By.id("cancel")).click();
    wait.until(new HasLandedOnSearchCustomerView());
    driver.findElement(By.id("firstName")).clear();
    driver.findElement(By.id("firstName")).sendKeys("John");
    wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("id(\"search-results-body\")/tr")));
    List<WebElement> searchResults = driver.findElements(By.xpath("id(\"search-results-body\")/tr"));
    assertEquals(1, searchResults.size());

    // Browse to the edit View of a search result and verify if the details are displayed
    driver.findElement(By.xpath("id(\"search-results-body\")/tr[1]/td[1]/a")).click();
    wait.until(new HasLandedOnEditCustomerView());
    assertEquals("John Doe", driver.findElement(By.id("firstName")).getAttribute("value"));
    assertEquals("2013-01-10", driver.findElement(By.id("dateOfBirth")).getAttribute("value"));

    // Edit the details, save and reverify the details
    driver.findElement(By.id("firstName")).clear();
    driver.findElement(By.id("firstName")).sendKeys("Jane Doe");
    driver.findElement(By.id("saveCustomer")).click();
    wait.until(new HasLandedOnEditCustomerView());
    assertEquals("Jane Doe", driver.findElement(By.id("firstName")).getAttribute("value"));
    assertEquals("2013-01-10", driver.findElement(By.id("dateOfBirth")).getAttribute("value"));
}

From source file:org.jboss.forge.scaffold.angularjs.scenario.dronetests.manytoone.ManyStoreOrderAndOneCustomerViewsClient.java

License:Open Source License

@Test
@InSequence(2)/*from w  ww. j  av  a  2s  .c o  m*/
public void testSaveNewStoreOrder(@ArquillianResource URL baseUrl) throws Exception {
    Wait<WebDriver> wait = new WebDriverWait(driver, 10);

    // Click on the StoreOrders nav entry
    driver.get(baseUrl.toString() + "app.html#/");
    driver.findElement(By.linkText("StoreOrders")).click();
    wait.until(new HasLandedOnSearchStoreOrderView());

    // Choose to create a new store order
    driver.findElement(By.id("Create")).click();
    wait.until(new HasLandedOnNewStoreOrderView());

    // Enter the store order details and save
    driver.findElement(By.id("product")).clear();
    driver.findElement(By.id("product")).sendKeys("Apples");
    driver.findElement(By.id("orderDate")).clear();
    driver.findElement(By.id("orderDate")).sendKeys("2013-01-10");
    driver.findElement(By.id("saveStoreOrder")).click();

    // Verify the details are presented in the Edit view 
    wait.until(new HasLandedOnEditStoreOrderView());
    assertEquals(baseUrl.toString() + "app.html#/StoreOrders/edit/2", driver.getCurrentUrl());
    assertEquals("Apples", driver.findElement(By.id("product")).getAttribute("value"));
    assertEquals("2013-01-10", driver.findElement(By.id("orderDate")).getAttribute("value"));

    // Browse to search customer view and verify if searching for the store order works 
    driver.findElement(By.id("cancel")).click();
    wait.until(new HasLandedOnSearchStoreOrderView());
    driver.findElement(By.id("product")).clear();
    driver.findElement(By.id("product")).sendKeys("Apple");
    wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("id(\"search-results-body\")/tr")));
    List<WebElement> searchResults = driver.findElements(By.xpath("id(\"search-results-body\")/tr"));
    assertEquals(1, searchResults.size());

    // Browse to the edit View of a search result and verify if the details are displayed
    driver.findElement(By.xpath("id(\"search-results-body\")/tr[1]/td[1]/a")).click();
    wait.until(new HasLandedOnEditStoreOrderView());
    assertEquals("Apples", driver.findElement(By.id("product")).getAttribute("value"));
    assertEquals("2013-01-10", driver.findElement(By.id("orderDate")).getAttribute("value"));

    // Edit the details, save and reverify the details
    driver.findElement(By.id("product")).clear();
    driver.findElement(By.id("product")).sendKeys("Oranges");
    driver.findElement(By.id("saveStoreOrder")).click();
    wait.until(new HasLandedOnEditStoreOrderView());
    assertEquals("Oranges", driver.findElement(By.id("product")).getAttribute("value"));
    assertEquals("2013-01-10", driver.findElement(By.id("orderDate")).getAttribute("value"));
}

From source file:org.jboss.forge.scaffold.angularjs.scenario.dronetests.manytoone.ManyStoreOrderAndOneCustomerViewsClient.java

License:Open Source License

@Test
@InSequence(3)/*  ww w .  j a v  a 2s .c  o m*/
public void testEstablishCustomerStoreOrderRelation(@ArquillianResource URL baseUrl) throws Exception {
    Wait<WebDriver> wait = new WebDriverWait(driver, 10);

    // Click on the StoreOrders nav entry
    driver.get(baseUrl.toString() + "app.html#/");
    driver.findElement(By.linkText("StoreOrders")).click();
    wait.until(new HasLandedOnSearchStoreOrderView());

    // Choose to create a new store order
    driver.findElement(By.id("Create")).click();
    wait.until(new HasLandedOnNewStoreOrderView());

    // Enter the store order details and save
    driver.findElement(By.id("product")).clear();
    driver.findElement(By.id("product")).sendKeys("Apples");
    driver.findElement(By.id("orderDate")).clear();
    driver.findElement(By.id("orderDate")).sendKeys("2013-01-10");
    WebElement customerElement = driver.findElement(By.id("customer"));
    Select customers = new Select(customerElement);
    customers.selectByVisibleText("1");
    driver.findElement(By.id("saveStoreOrder")).click();

    // Verify the details are presented in the Edit view 
    wait.until(new HasLandedOnEditStoreOrderView());
    assertEquals(baseUrl.toString() + "app.html#/StoreOrders/edit/3", driver.getCurrentUrl());
    assertEquals("Apples", driver.findElement(By.id("product")).getAttribute("value"));
    assertEquals("2013-01-10", driver.findElement(By.id("orderDate")).getAttribute("value"));
    customerElement = driver.findElement(By.id("customer"));
    customers = new Select(customerElement);
    assertEquals("1", customers.getFirstSelectedOption().getText());

    // Browse to search customer view and verify if searching for the store order through HTML dropdowns work
    driver.findElement(By.id("cancel")).click();
    wait.until(new HasLandedOnSearchStoreOrderView());
    customerElement = driver.findElement(By.id("customer"));
    customers = new Select(customerElement);
    customers.selectByVisibleText("1");
    wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("id(\"search-results-body\")/tr")));
    List<WebElement> searchResults = driver.findElements(By.xpath("id(\"search-results-body\")/tr"));
    assertEquals(1, searchResults.size());
}