List of usage examples for org.openqa.selenium.support.ui WebDriverWait WebDriverWait
public WebDriverWait(WebDriver driver, Duration timeout)
From source file:com.autocognite.appium.lib.base.AbstractAppiumUiDriver.java
License:Apache License
protected void init(RunConfiguration runConfig, AutomationContext context, String appPath) throws Exception { this.context = context; this.setAppPath(appPath); switch (context) { case MOBILE_WEB: this.setWaitTime(Integer.parseInt(runConfig.get(UiAutomator.MOBILE_WEB_WAIT_TIME))); case MOBILE_NATIVE: this.setWaitTime(Integer.parseInt(runConfig.get(UiAutomator.MOBILE_NATIVE_WAIT_TIME))); default:/*w ww .j a va 2s . co m*/ this.setWaitTime(Integer.parseInt(runConfig.get(UiAutomator.MOBILE_WAIT_TIME))); } this.setUiTestEngineName(UiDriverEngine.APPIUM); DesiredCapabilities capabilities = new DesiredCapabilities(); URL hubUrl = new URL(String.format(runConfig.get(AppiumAutomator.APPIUM_HUB_URL), runConfig.get(AppiumAutomator.APPIUM_HUB_HOST), runConfig.get(AppiumAutomator.APPIUM_HUB_PORT))); String platform = runConfig.get(UiAutomator.MOBILE_PLATFORM_NAME); if (!AppiumAutomator.isAllowedAppiumPlatform(platform)) { throwUnsupportedPlatformException("constructor", platform); } AppiumMobilePlatformType platformType = AppiumMobilePlatformType.valueOf(platform.toUpperCase()); setCapabilities(platformType, capabilities); try { switch (platformType) { case ANDROID: driver = new AndroidDriver<MobileElement>(hubUrl, capabilities); break; case IOS: driver = new IOSDriver<MobileElement>(hubUrl, capabilities); break; } } catch (UnreachableBrowserException e) { throwUnreachableBrowserException(platformType, e); } this.setWaiter(new WebDriverWait(this.getDriver(), this.getWaitTime())); }
From source file:com.autocognite.selenium.lib.SeleniumWebUiDriver.java
License:Apache License
public void initWait() { this.setWaiter(new WebDriverWait(this.getDriver(), getWaitTime())); if (this.getBrowser() != Browser.SAFARI) { getDriver().manage().timeouts().pageLoadTimeout(getWaitTime(), TimeUnit.SECONDS); }//from www . j av a 2 s . c o m }
From source file:com.axatrikx.webdriver.AxaDriver.java
License:Apache License
/** * Waits for page to complete loading//from w ww. j a va 2s . co m */ public void waitForPageLoad() { WebDriverWait wait = new WebDriverWait(driver, 100); wait.until(new Predicate<WebDriver>() { @Override public boolean apply(WebDriver driver) { return ((JavascriptExecutor) driver).executeScript("return document.readyState").equals("complete"); } }); }
From source file:com.axonivy.ivy.supplements.primeui.tester.AjaxHelper.java
License:Apache License
public <T> T waitAtMost(long waitingTime, TimeUnit timeUnit, ExpectedCondition<T> condition) { driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS); try {//from ww w . j a v a 2s . co m return new WebDriverWait(driver, timeUnit.toSeconds(waitingTime)).until(condition); } catch (TimeoutException ex) { System.out.println("Timed out while " + condition + " in source code: " + driver.getPageSource()); throw ex; } finally { driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); } }
From source file:com.babu.zadoqa.util.WaitTool.java
License:Open Source License
/** * Wait for the List<WebElement> to be present in the DOM, regardless of being displayed or not. * Returns all elements within the current page DOM. * /* ww w.java 2 s .c o m*/ * @param WebDriver The driver object to be used * @param By selector to find the element * @param int The time in seconds to wait until returning a failure * * @return List<WebElement> all elements within the current page DOM, or null (if the timeout is reached) */ public static List<WebElement> waitForListElementsPresent(WebDriver driver, final By by, int timeOutInSeconds) { List<WebElement> elements; try { driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); //nullify implicitlyWait() WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds); wait.until((new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver driverObject) { return areElementsPresent(driverObject, by); } })); elements = driver.findElements(by); driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); //reset implicitlyWait return elements; //return the element } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:com.babu.zadoqa.util.WaitTool.java
License:Open Source License
/** * Wait for an element to appear on the refreshed web-page. * And returns the first WebElement using the given method. *// w ww . j av a 2s . c om * This method is to deal with dynamic pages. * * Some sites I (Mark) have tested have required a page refresh to add additional elements to the DOM. * Generally you (Chon) wouldn't need to do this in a typical AJAX scenario. * * @param WebDriver The driver object to use to perform this element search * @param locator selector to find the element * @param int The time in seconds to wait until returning a failure * * @return WebElement the first WebElement using the given method, or null(if the timeout is reached) * * @author Mark Collin */ public static WebElement waitForElementRefresh(WebDriver driver, final By by, int timeOutInSeconds) { WebElement element; try { driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); //nullify implicitlyWait() new WebDriverWait(driver, timeOutInSeconds) { }.until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver driverObject) { driverObject.navigate().refresh(); //refresh the page **************** return isElementPresentAndDisplay(driverObject, by); } }); element = driver.findElement(by); driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); //reset implicitlyWait return element; //return the element } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:com.babu.zadoqa.util.WaitTool.java
License:Open Source License
/** * Wait for the Text to be present in the given element, regardless of being displayed or not. *// w ww .j ava 2s. c o m * @param WebDriver The driver object to be used to wait and find the element * @param locator selector of the given element, which should contain the text * @param String The text we are looking * @param int The time in seconds to wait until returning a failure * * @return boolean */ public static boolean waitForTextPresent(WebDriver driver, final By by, final String text, int timeOutInSeconds) { boolean isPresent = false; try { driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); //nullify implicitlyWait() new WebDriverWait(driver, timeOutInSeconds) { }.until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver driverObject) { return isTextPresent(driverObject, by, text); //is the Text in the DOM } }); isPresent = isTextPresent(driver, by, text); driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); //reset implicitlyWait return isPresent; } catch (Exception e) { e.printStackTrace(); } return false; }
From source file:com.babu.zadoqa.util.WaitTool.java
License:Open Source License
/** * Waits for the Condition of JavaScript. * * * @param WebDriver The driver object to be used to wait and find the element * @param String The javaScript condition we are waiting. e.g. "return (xmlhttp.readyState >= 2 && xmlhttp.status == 200)" * @param int The time in seconds to wait until returning a failure * //from w w w . ja v a 2s . c o m * @return boolean true or false(condition fail, or if the timeout is reached) **/ public static boolean waitForJavaScriptCondition(WebDriver driver, final String javaScript, int timeOutInSeconds) { boolean jscondition = false; try { driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); //nullify implicitlyWait() new WebDriverWait(driver, timeOutInSeconds) { }.until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver driverObject) { return (Boolean) ((JavascriptExecutor) driverObject).executeScript(javaScript); } }); jscondition = (Boolean) ((JavascriptExecutor) driver).executeScript(javaScript); driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); //reset implicitlyWait return jscondition; } catch (Exception e) { e.printStackTrace(); } return false; }
From source file:com.babu.zadoqa.util.WaitTool.java
License:Open Source License
/** Waits for the completion of Ajax jQuery processing by checking "return jQuery.active == 0" condition. * * @param WebDriver - The driver object to be used to wait and find the element * @param int - The time in seconds to wait until returning a failure * /*from ww w.ja v a 2s. c om*/ * @return boolean true or false(condition fail, or if the timeout is reached) * */ public static boolean waitForJQueryProcessing(WebDriver driver, int timeOutInSeconds) { boolean jQcondition = false; try { driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); //nullify implicitlyWait() new WebDriverWait(driver, timeOutInSeconds) { }.until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver driverObject) { return (Boolean) ((JavascriptExecutor) driverObject).executeScript("return jQuery.active == 0"); } }); jQcondition = (Boolean) ((JavascriptExecutor) driver).executeScript("return jQuery.active == 0"); driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); //reset implicitlyWait return jQcondition; } catch (Exception e) { e.printStackTrace(); } return jQcondition; }
From source file:com.bitbreeds.webrtc.signaling.BrowserTest.java
License:Open Source License
@Test public void testFull() throws Exception { String firefoxPath = System.getProperty("firefox.path"); //OS X * /Firefox.app/Contents/MacOS/firefox System.setProperty("com.bitbreeds.keystore", "./src/test/resources/ws2.jks"); System.setProperty("com.bitbreeds.keystore.alias", "websocket"); System.setProperty("com.bitbreeds.keystore.pass", "websocket"); if (firefoxPath != null) { SimpleSignalingExample.main();//from w ww . j av a2 s.c o m File fl = new File(".././web/index.html"); String url = "file://" + fl.getAbsolutePath(); System.out.println(url); FirefoxBinary binary = new FirefoxBinary(new File(firefoxPath)); FirefoxProfile firefoxProfile = new FirefoxProfile(); WebDriver driver = new FirefoxDriver(binary, firefoxProfile); driver.get(url); (new WebDriverWait(driver, 20)).until((ExpectedCondition<Boolean>) d -> { assert d != null; return d.findElement(By.id("status")).getText().equalsIgnoreCase("ONMESSAGE"); }); driver.quit(); } }