Example usage for org.openqa.selenium.support.ui ExpectedConditions stalenessOf

List of usage examples for org.openqa.selenium.support.ui ExpectedConditions stalenessOf

Introduction

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

Prototype

public static ExpectedCondition<Boolean> stalenessOf(final WebElement element) 

Source Link

Document

Wait until an element is no longer attached to the DOM.

Usage

From source file:com.hotwire.selenium.desktop.us.billing.car.impl.accordion.AcChangePrimaryDriverForm.java

License:Open Source License

public void changePrimaryDriver(String firstName, String lastName) {
    sendKeys(this.firstName, firstName);
    sendKeys(this.lastName, lastName);
    this.submit.click();
    new WebDriverWait(getWebDriver(), 10).until(ExpectedConditions.stalenessOf(this.submit));
}

From source file:com.liferay.faces.bridge.tck.harness.TckTestCase.java

License:Open Source License

private void runTest(BrowserDriver browserDriver) {

    boolean resultObtained = false;

    for (int i = 0; i < MAX_NUMBER_ACTIONS; i++) {

        for (String xpath : RUN_TEST_XPATHS) {

            if (areElementsDisplayed(browserDriver, xpath)) {

                WebElement webElement = browserDriver.findElementByXpath(xpath);
                browserDriver.clickElement(xpath);
                browserDriver.waitFor(ExpectedConditions.stalenessOf(webElement));
                browserDriver.waitForElementDisplayed("//body");
                loadImagesIfNecessary(browserDriver);
                switchToIFrameIfNecessary(browserDriver);

                // If results page shows record result.
                if (areElementsDisplayed(browserDriver, TEST_RESULT_STATUS_XPATH)) {

                    recordResult(browserDriver);
                    resultObtained = true;
                } else {
                    runAfterEachFullPageTestAction();
                }//from  w  ww  .ja va 2s.  c o m
                // Otherwise continue clicking on elements.
            }
        }

        if (!resultObtained && !areElementsDisplayed(browserDriver, RUN_TEST_XPATHS)) {

            String failureMessage = (i + 1)
                    + " full page request action(s) have been performed on this portlet without any final result or test components to exercise.";
            failTckTestCase(failureMessage, browserDriver);
        }
    }

    if (!resultObtained) {

        String failureMessage = MAX_NUMBER_ACTIONS
                + " actions have been performed on this portlet without any final result.";
        failTckTestCase(failureMessage, browserDriver);
    }
}

From source file:com.liferay.faces.bridge.test.integration.demo.applicant.BootsFacesApplicantPortletTester.java

License:Open Source License

@Override
protected void selectProvince(BrowserDriver browserDriver) {

    // Clear the province Id field and wait for rerender.
    String provinceIdFieldXpath = getProvinceIdFieldXpath();
    WebElement provinceIdFieldElement = browserDriver.findElementByXpath(provinceIdFieldXpath);
    clearProvince(browserDriver);//from   w  ww  . j  a  va2  s . c o  m
    browserDriver.waitFor(ExpectedConditions.stalenessOf(provinceIdFieldElement));
    browserDriver.waitForElementEnabled(provinceIdFieldXpath);
    super.selectProvince(browserDriver);
}

From source file:com.liferay.faces.portal.test.integration.demo.PrimeFacesUsersPortletTester.java

License:Open Source License

public static void resetTestUsers(BrowserDriver browserDriver) {

    // Navigate to the PrimeFaces Users portlet.
    browserDriver.navigateWindowTo(getURL());
    browserDriver.setWaitTimeOut(TestUtil.getBrowserDriverWaitTimeOut(10));
    browserDriver.waitForElementDisplayed(SCREEN_NAME_COLUMN_FILTER_XPATH);

    List<WebElement> screenNameCells = browserDriver.findElementsByXpath(SCREEN_NAME_CELL_XPATH);

    // Click the hidden *Reset Users* button to reset the state of the user data in preparation
    // for testing.
    WebElement hiddenResetUsersButton = browserDriver
            .findElementByXpath("//button[contains(@id,':hiddenResetUsersButton')]");
    browserDriver.executeScriptInCurrentWindow("arguments[0].click();", hiddenResetUsersButton);

    if (!screenNameCells.isEmpty()) {
        browserDriver.waitFor(ExpectedConditions.stalenessOf(screenNameCells.get(0)));
    }//from   www  . j  a va2s.co  m

    browserDriver.waitForElementDisplayed(SCREEN_NAME_CELL_XPATH);
    browserDriver.setWaitTimeOut(TestUtil.getBrowserDriverWaitTimeOut());
}

From source file:com.liferay.faces.portal.test.integration.demo.PrimeFacesUsersPortletTester.java

License:Open Source License

@Test
public void runPrimeFacesUsersPortletTest_C_UsersFilter() {

    BrowserDriver browserDriver = getBrowserDriver();

    // 1. Click the *First Name* header to sort first names into ascending order and verify that the sort
    // indication icon is pointed up.
    browserDriver.clickElement(FIRST_NAME_SORT_BUTTON_XPATH);
    browserDriver.waitForElementDisplayed(SORTED_ASCENDING_ICON_XPATH);

    // 2. Take note of each first name in the third column of the table, clicking the *Next* button until all
    // the first names have been noted.
    String firstNameFilterText = getFirstNameFilterText();
    List<String> firstNames = extractColumnValuesFromDataTable(browserDriver, "firstName");

    // 3. Filter the initial unfiltered list of first names to obtain the expected list sorted in ascending order.
    List<String> expectedFilteredFirstNamesAscending = filterList(firstNames);
    logList(expectedFilteredFirstNamesAscending,
            "Expected list of first names (sorted in ascending order), filtered by text \"{0}\":",
            firstNameFilterText);//from   ww  w. jav  a  2  s  .c  o  m

    //J-
    // 4. On Liferay 7+, Enter "J" into the *First Name* column filter since partial matching is supported.
    // On Liferay 6.2, enter "John" into the *First Name* column filter since only exact matching is supported.
    //J+
    filterColumnByText(browserDriver, FIRST_NAME_COLUMN_FILTER_XPATH, firstNameFilterText);

    // 5. Take note of each first name in the third column of the table, clicking the *Next* button until all
    // the first names have been noted.
    List<String> actualFilteredFirstNamesAscending = extractColumnValuesFromDataTable(browserDriver,
            "firstName");
    logList(actualFilteredFirstNamesAscending,
            "Actual list of first names (sorted in ascending order), filtered by text \"{0}\":",
            firstNameFilterText);

    // 6. Verify that the list obtained from the UI matches the expected filtered list (sorted in ascending order).
    Assert.assertEquals(expectedFilteredFirstNamesAscending, actualFilteredFirstNamesAscending);

    // 7. Sort the initial unfiltered list of first names, and filter the list to obtain the expected list sorted in
    // descending order.
    List<String> expectedFilteredFirstNamesDescending = new ArrayList<String>(firstNames);
    Collections.sort(expectedFilteredFirstNamesDescending, Collections.reverseOrder());
    expectedFilteredFirstNamesDescending = filterList(expectedFilteredFirstNamesDescending);
    logList(expectedFilteredFirstNamesDescending,
            "Expected list of first names (sorted in descending order), filtered by text \"{0}\":",
            firstNameFilterText);

    // 8. Click the *First Page* button to go back to the first page of users.
    browserDriver.clickElement(getNavigationButtonXpath("First"));
    browserDriver.waitFor(pageButtonClassActive(1));

    // 9. Click the *First Name* header to sort first names into descending order and verify that the sort
    // indication icon is pointed down.
    browserDriver.clickElement(FIRST_NAME_SORT_BUTTON_XPATH);
    browserDriver.waitForElementDisplayed(SORTED_DESCENDING_ICON_XPATH);

    // 10. Take note of each first name in the third column of the table, clicking the *Next* button until all
    // the first names have been noted.
    List<String> actualfilteredFirstNamesDescending = extractColumnValuesFromDataTable(browserDriver,
            "firstName");
    logList(actualfilteredFirstNamesDescending,
            "Actual list of first names (sorted in descending order), filtered by text \"{0}\":",
            firstNameFilterText);

    // 11. Verify that the list obtained from the UI matches the expected filtered list (sorted in descending
    // order).
    Assert.assertEquals(expectedFilteredFirstNamesDescending, actualfilteredFirstNamesDescending);

    // 12. Click the *Last Page* button to go back to the last page of users.
    browserDriver.clickElement(getNavigationButtonXpath("Last"));
    browserDriver.waitFor(navigationButtonClassDisabled("Last"));

    // 13. Click the *First Name* header to sort first names into ascending order and verify that the sort
    // indication icon is pointed up.
    browserDriver.clickElement(FIRST_NAME_SORT_BUTTON_XPATH);
    browserDriver.waitForElementDisplayed(SORTED_ASCENDING_ICON_XPATH);

    // 14. Clear the filter.
    WebElement screenNameCell = browserDriver.findElementByXpath(SCREEN_NAME_CELL_XPATH);
    browserDriver.clearElement(FIRST_NAME_COLUMN_FILTER_XPATH);
    browserDriver.waitFor(ExpectedConditions.stalenessOf(screenNameCell));
    browserDriver.waitForElementDisplayed(SCREEN_NAME_CELL_XPATH);

    // 15. Take note of each first name in the third column of the table, clicking the *Next* button until all
    // the first names have been noted.
    List<String> unfilteredFirstNames = extractColumnValuesFromDataTable(browserDriver, "firstName");

    // 16. Verify that the unfiltered list of first names from the UI is larger than the filtered lists and that the
    // unfiltered list matches the original list obtained from the UI.
    Assert.assertTrue((unfilteredFirstNames.size() > actualFilteredFirstNamesAscending.size())
            && (unfilteredFirstNames.size() > actualfilteredFirstNamesDescending.size()));
    Assert.assertEquals(firstNames, unfilteredFirstNames);

    // 17. Navigate back to the portlet via GET to reset its UI state.
    browserDriver.navigateWindowTo(getURL());
    browserDriver.waitForElementDisplayed(SCREEN_NAME_CELL_XPATH);

    // 18. Count the users with last name "Adams", clicking the *Next* button until all users with last name
    // "Adams" have been noted.
    int expectedAdamsUsersCount = 0;
    List<String> lastNames = extractColumnValuesFromDataTable(browserDriver, "lastName");

    for (String lastName : lastNames) {

        if (lastName.equals("Adams")) {
            expectedAdamsUsersCount++;
        }
    }

    // 19. Type "Adams" into the *First Name* column filter to test filtering by full value.
    filterColumnByText(browserDriver, LAST_NAME_COLUMN_FILTER_XPATH, "Adams");

    // 20. Take note of each last name in the second column of the table, clicking the *Next* button until all
    // the first names have been noted.
    List<String> actualAdamsList = extractColumnValuesFromDataTable(browserDriver, "lastName");

    // 21. Verify that the expected number of users with last name "Adams" matches the actual number of users with
    // last name "Adams" obtained from the UI after filtering.
    Assert.assertEquals(expectedAdamsUsersCount, actualAdamsList.size());

    // 22. Verify that last names obtained from the UI after filtering actually match "Adams".
    for (String actualAdams : actualAdamsList) {
        Assert.assertEquals("Adams", actualAdams);
    }

    // 23. Navigate back to the portlet via GET to reset its UI state.
    browserDriver.navigateWindowTo(getURL());
    browserDriver.waitForElementDisplayed(SCREEN_NAME_CELL_XPATH);
}

From source file:com.liferay.faces.portal.test.integration.demo.PrimeFacesUsersPortletTester.java

License:Open Source License

@Test
public void runPrimeFacesUsersPortletTest_E_DetailViewFileUpload() {

    BrowserDriver browserDriver = getBrowserDriver();

    // 1. Enter "john.adams" in the Screen Name filter so that *John Adams* appears as the only user in the
    // list.//w w w.j  a v  a2s. co m
    filterColumnByFullScreenName(browserDriver, "john.adams");

    // 2. Select *John Adams* from the list of users so that the corresponding user's data is displayed in an
    // editable form.
    browserDriver.clickElement(SCREEN_NAME_CELL_XPATH);
    browserDriver.waitForElementDisplayed(FIRST_NAME_FIELD_XPATH);

    // 3. Verify that the file upload chooser is displayed.
    String fileUploadChooserXpath = "//input[@type='file']";
    WebElement fileUploadChooser = browserDriver.findElementByXpath(fileUploadChooserXpath);

    // TECHNICAL NOTE:
    // Set PrimeFaces p:fileUpload transform style to "none" since it causes the element to not be displayed
    // according to Selenium (although the element is visible to users).
    browserDriver.executeScriptInCurrentWindow("arguments[0].style.transform = 'none';", fileUploadChooser);
    browserDriver.waitForElementEnabled(fileUploadChooserXpath + "/..");

    // 4. Prior to uploading an image, note the placeholder portrait that is displayed.
    String portraitXpath = "//div/img[contains(@id,':portrait')]";
    WebElement portraitElement = browserDriver.findElementByXpath(portraitXpath);
    Dimension originalPlaceholderPortraitSize = portraitElement.getSize();

    // 5. Click the *Choose* button and select "liferay-jsf-jersey.png" for upload.
    fileUploadChooser.sendKeys(TestUtil.JAVA_IO_TMPDIR + "liferay-jsf-jersey.png");
    browserDriver.waitFor(ExpectedConditions.stalenessOf(portraitElement));

    WaitingAsserter waitingAsserter = getWaitingAsserter();
    waitingAsserter.assertElementDisplayed(portraitXpath);
    portraitElement = browserDriver.findElementByXpath(portraitXpath);

    // 6. Verify that the displayed portrait is different than the original placeholder portrait, and note the
    // displayed portrait.
    Dimension uploadedPortraitSize = portraitElement.getSize();
    Assert.assertFalse(areImageSizesEqual(originalPlaceholderPortraitSize, uploadedPortraitSize));

    // 7. Click the *Submit* button to submit the portrait update and go back to the list of users.
    browserDriver.clickElement(SUBMIT_BUTTON_XPATH);
    browserDriver.waitForElementDisplayed(SCREEN_NAME_CELL_XPATH);

    // 8. Select *John Adams* from the list of users so that the corresponding user's data is displayed in an
    // editable form.
    browserDriver.clickElement(SCREEN_NAME_CELL_XPATH);
    browserDriver.waitForElementDisplayed(FIRST_NAME_FIELD_XPATH);

    // 9. Verify that the displayed portrait is the same uploaded portrait and different than the original
    // placeholder portrait.
    portraitElement = browserDriver.findElementByXpath(portraitXpath);

    Dimension expectedUploadedPortraitSize = uploadedPortraitSize;
    Dimension actualUploadedPortraitSize = portraitElement.getSize();
    Assert.assertTrue(areImageSizesEqual(expectedUploadedPortraitSize, actualUploadedPortraitSize));
    Assert.assertFalse(areImageSizesEqual(originalPlaceholderPortraitSize, actualUploadedPortraitSize));

    // 10. Click the *Cancel* button to go back to the list of users.
    browserDriver.clickElement(CANCEL_BUTTON_XPATH);
    browserDriver.waitForElementDisplayed(SCREEN_NAME_CELL_XPATH);

    // 11. Clear the filter to see the list of all the users again.
    browserDriver.clearElement(SCREEN_NAME_COLUMN_FILTER_XPATH);
    browserDriver.waitForElementDisplayed(SCREEN_NAME_CELL_2_XPATH);
}

From source file:com.liferay.faces.test.alloy.showcase.datatable.DataTableSortMultipleColumnsTester.java

License:Open Source License

@Test
public void runDataTableSortMultipleColumnsTest() throws Exception {

    // 1. Navigate to the "Sort (Multiple Column)" use case in order to reset the state of the UI.
    BrowserDriver browserDriver = getBrowserDriver();
    String componentUseCase = "sort-multiple-columns";
    navigateToUseCase(browserDriver, DATA_TABLE, componentUseCase);

    // 2. Verify that the tabular data is paginate according to expected behavior of the pagination buttons.
    WaitingAsserter waitingAsserter = getWaitingAsserter();
    testPaginator(browserDriver, waitingAsserter, componentUseCase);

    // 3. Navigate to the "Sort (Multiple Column)" use case in order to reset the state of the UI.
    navigateToUseCase(browserDriver, DATA_TABLE, componentUseCase);

    // 4. Select "100" from the *Rows Per Page" dropdown list (reduces the number of *Next* button clicks in the
    // following steps).
    clickOptionAndWaitForRerender(browserDriver, getDropDownListXpath("Rows Per Page", "100"));

    // 5. Click the *Last Name* header in order to sort the table primarily by last name in ascending order and
    // verify that the sort indication icon is pointed up.
    browserDriver.centerElementInCurrentWindow(LAST_NAME_HEADER_XPATH);
    browserDriver.clickElementAndWaitForRerender(LAST_NAME_HEADER_XPATH);
    waitingAsserter.assertElementDisplayed(SORTED_ASCENDING_ICON_XPATH);

    // 6. Click the *Date of Birth* header while holding down the meta or command key in order to sort the table
    // secondarily by date of birth in ascending order.
    WebElement rerenderElement = browserDriver.findElementByXpath(DATE_OF_BIRTH_HEADER_XPATH);
    browserDriver.centerElementInCurrentWindow(DATE_OF_BIRTH_HEADER_XPATH);
    metaOrCommandClick(browserDriver, DATE_OF_BIRTH_HEADER_XPATH);
    browserDriver.waitFor(ExpectedConditions.stalenessOf(rerenderElement));
    browserDriver.waitForElementDisplayed(DATE_OF_BIRTH_HEADER_XPATH);

    // 7. Take note of each customer shown in the table, clicking the *Next* button until all the customers in
    // the table have been noted.
    List<Customer> actualCustomers = extractCustomersFromAllPages(browserDriver, componentUseCase);

    // 8. Verify that the list of noted customers is sorted primarily by last name, and secondarily by date of
    // birth./*w w w.  j  a va  2  s  .  c o  m*/
    List<Customer> expectedCustomers = new ArrayList<Customer>(actualCustomers);
    Collections.sort(expectedCustomers, new CustomerComparator());
    Assert.assertEquals(actualCustomers.size(), TOTAL_CUSTOMERS);
    Assert.assertEquals(expectedCustomers, actualCustomers);
}

From source file:com.liferay.faces.test.selenium.browser.internal.BrowserDriverImpl.java

License:Open Source License

@Override
public void performAndWaitForRerender(Action action, String rerenderXpath) {

    WebElement rerenderElement = findElementByXpath(rerenderXpath);
    action.perform();//  www . j a v  a2s  .  c om
    logger.info("Waiting for element {} to be stale.", rerenderXpath);
    waitFor(ExpectedConditions.stalenessOf(rerenderElement));
    logger.info("Element {} is stale.", rerenderXpath);
    waitForElementDisplayed(rerenderXpath);
}

From source file:com.liferay.faces.test.selenium.browser.TestUtil.java

License:Open Source License

public static void signIn(BrowserDriver browserDriver, String signInURL, String loginXpath, String login,
        String passwordXpath, String password, String signInButtonXpath) {

    browserDriver.navigateWindowTo(signInURL);
    browserDriver.waitForElementEnabled(loginXpath);
    browserDriver.clearElement(loginXpath);
    browserDriver.sendKeysToElement(loginXpath, login);
    browserDriver.clearElement(passwordXpath);
    browserDriver.sendKeysToElement(passwordXpath, password);

    WebElement loginElement = browserDriver.findElementByXpath(loginXpath);
    browserDriver.clickElement(signInButtonXpath);
    browserDriver.waitFor(ExpectedConditions.stalenessOf(loginElement));
    browserDriver.waitForElementDisplayed("//body");
}

From source file:com.liferay.faces.test.showcase.buttonlink.ButtonLinkTester.java

License:Open Source License

private void clickButtonLink(BrowserDriver browserDriver, String xpath) {

    WebElement webElement = browserDriver.findElementByXpath(xpath);
    String tagName = webElement.getTagName();
    String onclick = webElement.getAttribute("onclick");
    browserDriver.clickElement(xpath);/*from   w  ww.  j a  v a  2s .c  om*/

    // If the clicking the button/link will cause the page to reload.
    if (!"button".equals(tagName) || ((onclick != null) && !"".equals(onclick))) {

        browserDriver.waitFor(ExpectedConditions.stalenessOf(webElement));
        waitForShowcasePageReady(browserDriver);
    }
}