List of usage examples for org.openqa.selenium.support.ui ExpectedConditions stalenessOf
public static ExpectedCondition<Boolean> stalenessOf(final WebElement element)
From source file:com.liferay.faces.test.showcase.facesrequestcontext.FacesRequestContextGeneralTester.java
License:Open Source License
@Test public void runFacesRequestContextGeneralTest() throws Exception { Browser browser = Browser.getInstance(); navigateToUseCase(browser, "util", "FacesRequestContext", "general"); // Test that clicking the "Show Modal" button shows the modal. browser.click("(//*[contains(@value,'Show Modal')])[1]"); browser.waitForElementVisible(submitButton1Xpath); String modalDialogXpath = "//div[contains(@class,'modal-dialog')]"; SeleniumAssert.assertElementVisible(browser, modalDialogXpath); // Test that the modal is still visible (and shows an error message) when an empty value is submitted. browser.clickAndWaitForAjaxRerender(submitButton1Xpath); SeleniumAssert.assertElementVisible(browser, modalDialogXpath); SeleniumAssert.assertElementTextVisible(browser, error1Xpath, "Email: Validation Error: Value is required."); // Test that the modal is still visible (and shows an error message) when an invalid value is submitted. String emailAddressInputTextXpath = "(//input[contains(@id,':text')])[1]"; browser.sendKeys(emailAddressInputTextXpath, "HelloWorldcom"); browser.clickAndWaitForAjaxRerender(submitButton1Xpath); SeleniumAssert.assertElementVisible(browser, modalDialogXpath); SeleniumAssert.assertElementTextVisible(browser, error1Xpath, "Invalid E-Mail Address"); // Test that a valid value submits successfully and the modal disappears. browser.clear(emailAddressInputTextXpath); browser.sendKeys(emailAddressInputTextXpath, "hello@world.com"); WebElement submitButton1 = browser.findElementByXpath(submitButton1Xpath); submitButton1.click();/*from www .j a v a 2 s .co m*/ browser.waitUntil(ExpectedConditions.stalenessOf(submitButton1)); browser.waitForElementPresent(submitButton1Xpath); WebElement modalElement = browser.findElementByXpath(modalDialogXpath); Assert.assertTrue("Element " + modalDialogXpath + " is displayed.", !modalElement.isDisplayed()); }
From source file:com.liferay.faces.test.showcase.select.SelectTester.java
License:Open Source License
/** * Click an option and wait for Ajax to rerender the option. This method exists because {@link * Browser#clickAndWaitForAjaxRerender(java.lang.String)} does not work on selectOneMenu, selectManyListbox, and * SelectManyMenu. For more information see method comments. *//*from www . j av a 2 s . c om*/ protected void clickOptionAndWaitForAjaxRerender(Browser browser, String optionXpath) { // SelectOneMenu and SelectManyMenu tests occasionally fail due to elements moving off screen, so center the // element in the view. if (this.getClass().getName().contains("Menu")) { browser.centerElementInView(optionXpath); } WebElement optionElement = browser.findElementByXpath(optionXpath); // Note: clicking a selectOneMenu option on Chrome and PhantomJS via Actions.click(WebElement) (which is used // by Browser.clickAndWaitForAjaxRerender(String)) does not fire the select element's change event, so the // element must be clicked via Element.click(). optionElement.click(); // phantomjs browser does not fire a change event when a <select multiple="multiple"> <option> is clicked, so // the event must be fired manually. if ("phantomjs".equals(browser.getName())) { try { WebElement selectElement = optionElement.findElement(By.xpath("..")); Select select = new Select(selectElement); if (select.isMultiple()) { browser.executeScript(FIRE_SELECT_CHANGE_EVENT_SCRIPT, optionElement); } } catch (StaleElementReferenceException e) { // do nothing. The element is stale because an ajax rerender has correctly occured. } } browser.waitUntil(ExpectedConditions.stalenessOf(optionElement)); browser.waitForElementVisible(optionXpath); }
From source file:com.liferay.faces.test.showcase.TesterBase.java
License:Open Source License
/** * Click an option and wait for Ajax to rerender the option. This method exists because {@link * BrowserDriver#clickElementAndWaitForRerender(java.lang.String)} does not work on selectOneMenu, * selectManyListbox, and SelectManyMenu. For more information see method comments. *//*from w w w.j a va 2 s .co m*/ protected void clickOptionAndWaitForRerender(BrowserDriver browserDriver, String optionXpath) { browserDriver.centerElementInCurrentWindow(optionXpath); WebElement optionElement = browserDriver.findElementByXpath(optionXpath); // Note: clicking a selectOneMenu option on Chrome and PhantomJS via Actions.click(WebElement) (which is used // by Browser.clickAndWaitForAjaxRerender(String)) does not fire the select element's change event, so the // element must be clicked via Element.click(). optionElement.click(); // phantomjs browser does not fire a change event when a <select multiple="multiple"> <option> is clicked, // so the event must be fired manually. if ("phantomjs".equals(browserDriver.getBrowserName())) { try { WebElement selectElement = optionElement.findElement(By.xpath("..")); Select select = new Select(selectElement); if (select.isMultiple()) { browserDriver.executeScriptInCurrentWindow(FIRE_SELECT_CHANGE_EVENT_SCRIPT, optionElement); } } catch (StaleElementReferenceException e) { // do nothing. The element is stale because an ajax rerender has correctly occured. } } browserDriver.waitFor(ExpectedConditions.stalenessOf(optionElement)); browserDriver.waitForElementEnabled(optionXpath); }
From source file:com.twiceagain.mywebdriver.generators.WebPageBasic.java
License:Open Source License
/** * Tries to move to next page. If no next page, return false. * * @return true if next page sucessfully loaded. *//*from w ww . j av a 2 s. c o m*/ @Override public boolean goToNextPage() { if (limiter.shouldStop()) { return false; } // When pages never have next pages. if (xpNextPageClick == null) { loadedElements = null; return false; } // check for hasNextPage, if it is defined if (xpHasNextPage != null) { try { wd.findElement(By.xpath(xpHasNextPage)); } catch (Exception ex) { loadedElements = null; LOG.info(ex.getLocalizedMessage()); return false; } } // Identify staleness marker WebElement stale = null; if (xpStalenessMarker != null) { try { stale = wd.findElements(By.xpath(xpStalenessMarker)).get(0); } catch (Exception ex) { stale = null; LOG.info(ex.getLocalizedMessage()); // ignore ... } } // try to click for goToNextPage if (xpNextPageClick != null) { try { wd.findElement(By.xpath(xpNextPageClick)).click(); } catch (Exception ex) { loadedElements = null; LOG.info(ex.getLocalizedMessage()); return false; } } // Wait for stalenessmarker to become stale. if (stale != null) { try { (new WebDriverWait(wd, maxWaitSeconds)).until(ExpectedConditions.stalenessOf(stale)); } catch (Exception ex) { LOG.info(ex.getLocalizedMessage()); // ignore ... } } preloadElements(); return loadedElements != null; }
From source file:de.knowwe.uitest.UITestUtils.java
License:Open Source License
public static void awaitRerender(WebDriver driver, By by) { try {/*w w w . ja v a 2s .c o m*/ List<WebElement> elements = driver.findElements(by); if (!elements.isEmpty()) { new WebDriverWait(driver, 5).until(ExpectedConditions.stalenessOf(elements.get(0))); } } catch (TimeoutException ignore) { } new WebDriverWait(driver, 5).until(ExpectedConditions.presenceOfElementLocated(by)); }
From source file:jhc.redsniff.webdriver.ExtraExpectedConditions.java
License:Apache License
/** * Wait until an element is no longer attached to the DOM. The version in {@link ExpectedConditions} is unstable if the element's toString calls any method on the element * * @param element The element to wait for. * @return false is the element is still attached to the DOM, true * otherwise./* ww w.j a v a2 s. c o m*/ */ public static ExpectedCondition<Boolean> stalenessOf(final WebElement element) { final String elementDescription;//need to get the element description first to avoid causing a stale element exception in the description - when it becomes stale too fast try { elementDescription = asString(element); } catch (StaleElementReferenceException e) { return TRUE_CONDITION; } return new ExpectedCondition<Boolean>() { @Override public String toString() { return "Element to become 'stale':" + elementDescription; } @Override public Boolean apply(WebDriver input) { return ExpectedConditions.stalenessOf(element).apply(input); } }; }
From source file:jhc.redsniff.webdriver.ExtraExpectedConditions.java
License:Apache License
/** * Wait until an element is no longer attached to the DOM. * * @param element The element to wait for. * @return false is the element is still attached to the DOM, true * otherwise.//from w ww .j av a 2 s . c o m //TODO - add descriptions of elements expected to be stale */ public static ExpectedCondition<Boolean> stalenessOfAnyOf(final Collection<WebElement> elements) { return new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver input) { for (WebElement element : elements) if (ExpectedConditions.stalenessOf(element).apply(input)) return true; return false; } @Override public String toString() { return "Staleness of any of a list of elements (description TBA)"; } }; }
From source file:library.functions.WebFunctions.java
License:Open Source License
public void waitForElementNotPresent(By by) throws IOException { if (!getBrowser().equalsIgnoreCase("InternetExplorer")) { try {// w w w. j a va2 s . com if (isPageObjectPresent(by)) { WebDriverWait wait = new WebDriverWait(getWebDriver(), 120); Boolean res = wait.until(ExpectedConditions.stalenessOf(getWebDriver().findElement(by))); } } catch (Exception e) { takeScreenshot(); } } }
From source file:library.functions.WebFunctions.java
License:Open Source License
public void waitForElementNotPresent(By by, int t) throws IOException { try {//from ww w .j a v a2 s. c o m WebDriverWait wait = new WebDriverWait(getWebDriver(), t); Boolean res = wait.until(ExpectedConditions.stalenessOf(getWebDriver().findElement(by))); } catch (Exception e) { takeScreenshot(); } }
From source file:org.alfresco.po.common.util.Utils.java
License:Open Source License
/** * Helper method to wait for the staleness of an element *//* w w w . j ava 2 s . co m*/ public static void waitForStalenessOf(WebElement webElement) { webDriverWait().until(ExpectedConditions.stalenessOf(webElement)); }