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:applicationdriverlayer.pageobjects.squash.SquashBasePage.java

License:Apache License

private final void load(boolean alreadyLoading, Optional<WebElement> cachedWebElement,
        Optional<Boolean> expectChangedS3Page) {
    loadRecursionDepth++;//from  ww  w.ja va 2s  . c  o m
    if (!alreadyLoading) {
        Optional<String> url = getUrl();
        if (url.isPresent()) {
            // We have an URL and the page is not already loading, so let's initiate
            // page retrieval.
            driver.get(url.get());
        } else {
            fail("Cannot initiate a page get without an URL");
        }
    }

    if (cachedWebElement.isPresent()) {
        // We have a cached web element, so first wait for it to become stale
        new WebDriverWait(driver, explicitWaitTimeoutSeconds)
                .until(ExpectedConditions.stalenessOf(cachedWebElement.get()));
    }

    // Now wait for the page load to complete
    waitForLoadToComplete();

    // Give our derived class a chance to update its cached web element
    Optional<WebElement> updatedCachedWebElement = updateCachedWebElement();

    if (expectChangedS3Page.isPresent() && !isS3PageConsistent(expectChangedS3Page.get())) {
        // If page not in its eventually-consistent state, re-get the current url
        // N.B. current url may differ from result of getUrl() e.g. by having
        // different query params (such as the date in the case of bookings pages)
        if (loadRecursionDepth > 20) {
            fail("Load recursion depth limit exceeded in SquashBasePage");
        }
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            System.out.println("Sleep before re-get-ing for S3 consistency was interrupted");
        }
        driver.get(driver.getCurrentUrl());
        load(true, updatedCachedWebElement, expectChangedS3Page);
    }

    loadRecursionDepth = 0;
}

From source file:com.cognifide.qa.bb.aem.ui.parsys.AemParsys.java

License:Apache License

private void waitForComponentToBeRemoved(WebElement webElement) {
    wait.withTimeout(Timeouts.SMALL).until(ExpectedConditions.stalenessOf(webElement));
}

From source file:com.comcast.dawg.house.AdvanceFilterUIIT.java

License:Apache License

private void performSearchAndCheckDevices(RemoteWebDriver driver, String[] deviceIdsToHave,
        String[] deviceIdsNotToHave) {
    WebElement filteredTable = driver.findElementByClassName(IndexPage.FILTERED_TABLE);

    WebDriverWait wait = new WebDriverWait(driver, 20);
    driver.findElementByClassName(IndexPage.BTN_SEARCH).click();

    /** Need two waits... first for the original table to be removed from the DOM, then for it
     * to be present again *//*ww w .  j a  va 2  s .  c o  m*/
    wait.until(ExpectedConditions.stalenessOf(filteredTable));
    wait.until(ExpectedConditions.presenceOfElementLocated(By.className(IndexPage.FILTERED_TABLE)));
    filteredTable = driver.findElementByClassName(IndexPage.FILTERED_TABLE);

    if (deviceIdsToHave != null) {
        hasDevices(filteredTable, deviceIdsToHave, true);
    }
    if (deviceIdsNotToHave != null) {
        hasDevices(filteredTable, deviceIdsNotToHave, false);
    }
}

From source file:com.comcast.dawg.house.EditDeviceUIIT.java

License:Apache License

/**
 *
 * @param save true if the changes should be saved
 * @param refreshedName The value given for the property "name" when the page is refreshed
 * @param isModified If the property should be marked as modified when the page is refreshed
 * @author Kevin Pearson/*w ww  .  j a v  a 2 s.c o  m*/
 * @throws IOException
 */
@Test(dataProvider = "testChangeValueData")
public void testChangeValue(boolean save, String refreshedName, boolean isModified) throws IOException {
    RemoteWebDriver driver = BrowserServiceManager.getDriver(Browser.chrome);
    MetaStb stb = MetaStbBuilder.build().uid(DEVICE_PREF).stb();
    addStb(stb);
    String token = MetaStbBuilder.getUID("testtoken");
    EditDeviceOverlay edOverlay = loadPageAndLaunchEditOverlay(driver, token, stb.getId());
    String nameChange = "nameChange";

    EditDeviceRow row = edOverlay.getRow("name");
    Assert.assertFalse(row.isModified());
    row.changeValue(nameChange);
    Assert.assertTrue(row.isModified());
    EditDeviceOverlay edOverlayNext;
    if (save) {
        edOverlay.save();

        /** Wait until page loads */
        waitForNewPageToLoad(driver, edOverlay.getOverlayUI());
        edOverlayNext = launchEditOverlay(driver, stb.getId());
    } else {
        Assert.assertTrue(edOverlay.getOverlayUI().isDisplayed());
        edOverlay.close();
        Assert.assertFalse(edOverlay.getOverlayUI().isDisplayed());
        /** Refresh */
        edOverlayNext = loadPageAndLaunchEditOverlay(driver, token, stb.getId());
    }
    Assert.assertTrue(ExpectedConditions.stalenessOf(edOverlay.getOverlayUI()).apply(driver));
    row = edOverlayNext.getRow("name");
    Assert.assertEquals(row.isModified(), isModified);
    Assert.assertEquals(row.getValueText(), refreshedName);
}

From source file:com.comcast.dawg.house.EditDeviceUIIT.java

License:Apache License

/**
 * This method checks editing the Stb model name with valid, invalid names
 * and verifies the populated family and capabilities based on modified
 * model name//www  .ja  v  a  2 s . c  o  m
 *
 * @param newModelName
 *            the new model name
 * @param expectedCapabilities
 *            expected capabilities that should be populated
 * @param expectedFamily
 *            expected family that should be populated
 * @param validModelName
 *            set true if the given model name is valid and present in database
 * @param modifiedProps
 *            if set true, will change the isModified property of family and
 *            capabilities to true
 * @throws IOException
 */
@Test(dataProvider = "testChangeModelNameData")
public void testChangeModelName(String newModelName, String expectedCapabilities, String expectedFamily,
        boolean validModelName, boolean modifiedProps) throws IOException {
    RemoteWebDriver driver = BrowserServiceManager.getDriver(Browser.chrome);
    MetaStb stb = MetaStbBuilder.build().uid(DEVICE_PREF).stb();
    addStb(stb);
    String token = MetaStbBuilder.getUID("testtoken");
    EditDeviceOverlay edOverlay = loadPageAndLaunchEditOverlay(driver, token, stb.getId());
    EditDeviceRow model = edOverlay.getRow("model");
    EditDeviceRow family = edOverlay.getRow("family");
    EditDeviceRow capabilities = edOverlay.getRow("capabilities");
    Assert.assertFalse(model.isModified());
    if (modifiedProps) {
        family.changeValue("TestFamily");
        capabilities.changeValue("TestCap1, TestCap2");
    }
    model.changeValue(newModelName);
    EditDeviceOverlay edOverlayNext;
    edOverlay.save();

    /** Wait until page loads */
    waitForNewPageToLoad(driver, edOverlay.getOverlayUI());
    edOverlayNext = launchEditOverlay(driver, stb.getId());
    Assert.assertTrue(ExpectedConditions.stalenessOf(edOverlay.getOverlayUI()).apply(driver));
    if (!validModelName && !modifiedProps) {
        MetaStb updated = client.getById(stb.getId());
        Map<String, Object> data = updated.getData();
        Assert.assertNull(data.get("family"));
        Assert.assertNull(data.get("capabilities"));
    } else {
        model = edOverlayNext.getRow("model");
        Assert.assertEquals(model.getValueText(), newModelName);
        family = edOverlayNext.getRow("family");
        Assert.assertEquals(family.getValueText(), expectedFamily);
        capabilities = edOverlayNext.getRow("capabilities");
        Assert.assertEquals(capabilities.getValueText(), expectedCapabilities);
    }
}

From source file:com.comcast.dawg.house.EditDeviceUIIT.java

License:Apache License

/**
 * Launch overlay, mark modified, refresh page, launch overlay, verify it is still marked modified,
 * mark unmodified, refresh page, verify it is still marked unmodified
 * @author Kevin Pearson/*from  w  w  w . j  ava2s  .co  m*/
 * @throws IOException
 */
@Test
public void testMarkPropModified() throws IOException {
    RemoteWebDriver driver = BrowserServiceManager.getDriver(Browser.chrome);
    MetaStb stb = MetaStbBuilder.build().uid(DEVICE_PREF).stb();
    addStb(stb);
    String token = MetaStbBuilder.getUID("testtoken");
    EditDeviceOverlay edOverlay = loadPageAndLaunchEditOverlay(driver, token, stb.getId());

    EditDeviceRow row = edOverlay.getRow(MetaStb.MAKE);
    Assert.assertFalse(row.isModified());
    row.toggleModified();
    Assert.assertTrue(row.isModified());
    edOverlay.save();
    waitForNewPageToLoad(driver, edOverlay.getOverlayUI());

    // make sure page was refreshed by checking staleness
    Assert.assertTrue(ExpectedConditions.stalenessOf(edOverlay.getOverlayUI()).apply(driver));
    edOverlay = launchEditOverlay(driver, stb.getId());
    row = edOverlay.getRow(MetaStb.MAKE);
    Assert.assertTrue(row.isModified());
    row.toggleModified();
    Assert.assertFalse(row.isModified());
    edOverlay.save();
    waitForNewPageToLoad(driver, edOverlay.getOverlayUI());

    // make sure page was refreshed by checking staleness
    Assert.assertTrue(ExpectedConditions.stalenessOf(edOverlay.getOverlayUI()).apply(driver));
    edOverlay = launchEditOverlay(driver, stb.getId());
    row = edOverlay.getRow(MetaStb.MAKE);
    Assert.assertFalse(row.isModified());
}

From source file:com.comcast.dawg.house.EditDeviceUIIT.java

License:Apache License

private void waitForNewPageToLoad(RemoteWebDriver driver, WebElement oldPageElement) {
    WebDriverWait wait = new WebDriverWait(driver, 20);
    wait.until(ExpectedConditions.stalenessOf(oldPageElement));
    wait.until(ExpectedConditions.presenceOfElementLocated(By.className(IndexPage.FILTERED_TABLE)));
}

From source file:com.comcast.dawg.house.pages.IndexPage.java

License:Apache License

/**
 * Types the tag name and clicks the bulk tag button.
 *
 * @param  tagName  the tag names/*from   ww w  .j a v a2s. c  om*/
 */
public void enterTagNameAndClickSubmit(String tagName) {

    // Enter the tag name.
    typeOnBulkTagTextElement(tagName);

    /**
     * If already tag is present in the tag cloud the element modification need to be evaluated for correct wait
     * time.
     **/
    String tagCloudElementText = getTagCloudElementText();
    boolean isTagPresent = false;
    List<WebElement> listOfContainedTag = new ArrayList<WebElement>();

    for (String tag : tagName.split(" ")) {

        if (tagCloudElementText.contains(tag)) {
            isTagPresent = true;
            listOfContainedTag
                    .add(driver.findElementByXPath(TAG_ID_DIV_XPATH.replace(REPLACEABLE_ELEMENT, tag)));
        }
    }

    // Clicking on bulk tag add button.
    clickOnBulkTagAddButton();

    WebDriverWait wait = new WebDriverWait(driver, 20);

    // If tag is present waiting for it to get refreshed.
    if (isTagPresent) {

        for (WebElement element : listOfContainedTag) {
            wait.until(ExpectedConditions.stalenessOf(element));
        }
    }

    // Since multi tag addition is supported.
    for (String tag : tagName.split(" ")) {
        wait.until(ExpectedConditions
                .presenceOfElementLocated(By.xpath(TAG_ID_DIV_XPATH.replace(REPLACEABLE_ELEMENT, tag))));
    }
}

From source file:com.comcast.dawg.selenium.SeleniumWaiter.java

License:Apache License

/**
 * Wait until an element is no longer attached to the DOM.
 *
 * @param   element       The element to wait for.
 * @param   timeoutInSec  timeout in seconds.
 *
 * @return  false is the element is still attached to the DOM, true otherwise.
 *//*  w  w w. jav a 2  s  .  co  m*/
public boolean waitForStaleness(WebElement element, int timeoutInSec) {
    WebDriverWait wait = new WebDriverWait(driver, timeoutInSec);

    return wait.until(ExpectedConditions.stalenessOf(element));
}

From source file:com.gwtplatform.carstore.cucumber.application.BasePage.java

License:Apache License

protected void waitUntilElementIsDetached(WebElement element) {
    webDriverWait().until(ExpectedConditions.stalenessOf(element));
}