Example usage for org.openqa.selenium WebDriver manage

List of usage examples for org.openqa.selenium WebDriver manage

Introduction

In this page you can find the example usage for org.openqa.selenium WebDriver manage.

Prototype

Options manage();

Source Link

Document

Gets the Option interface

Usage

From source file:org.kuali.rice.testtools.selenium.WebDriverUtils.java

License:Educational Community License

public static void openTestUrl(WebDriver driver, String testUrl) {
    driver.manage().timeouts().implicitlyWait(WebDriverUtils.SETUP_URL_LOAD_WAIT_SECONDS, TimeUnit.SECONDS);

    driver.get(testUrl);// ww  w .j a v a 2s .co m
    if (!System.getProperty(SauceLabsWebDriverHelper.SAUCE_BROWSER_PROPERTY, "ff").equals("opera")) {
        driver.manage().window().maximize();
        //            driver.manage().window().setSize(new Dimension(800,600));
    }

    WebDriverUtils.jGrowl(driver, "Open URL", false, "Open " + testUrl);

    driver.manage().timeouts().implicitlyWait(WebDriverUtils.configuredImplicityWait(), TimeUnit.SECONDS);
}

From source file:org.kuali.rice.testtools.selenium.WebDriverUtils.java

License:Educational Community License

/**
 * <p>/*from  ww w  . j a v  a 2 s .  com*/
 * Return the WebElement that has the attribute name with the given value within the given seconds to wait.
 * </p>
 *
 * @param driver to get element from
 * @param attribute name to find element by
 * @param attributeValue for the attribute name to find element by
 * @param waitSeconds number of seconds to wait
 * @return WebElement
 * @throws InterruptedException
 */
public static WebElement waitAndGetElementByAttributeValue(WebDriver driver, String attribute,
        String attributeValue, int waitSeconds) throws InterruptedException {
    // jenkins implies that implicitlyWait is worse than sleep loop for finding elements by 100+ test failures on the old sampleapp
    //        driver.manage().timeouts().implicitlyWait(waitSeconds, TimeUnit.SECONDS);
    //        driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);

    driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);

    boolean failed = false;

    for (int second = 0;; second++) {
        Thread.sleep(1000);
        if (second >= waitSeconds) {
            failed = true;
        }
        try {
            if (failed || (getElementByAttributeValue(driver, attribute, attributeValue) != null)) {
                break;
            }
        } catch (Exception e) {
        }
    }

    WebElement element = getElementByAttributeValue(driver, attribute, attributeValue);
    driver.manage().timeouts().implicitlyWait(WebDriverUtils.configuredImplicityWait(), TimeUnit.SECONDS);
    return element;
}

From source file:org.kuali.rice.testtools.selenium.WebDriverUtils.java

License:Educational Community License

public static void waitToAcceptAlert(WebDriver driver, int waitSeconds, String message)
        throws InterruptedException {
    driver.manage().timeouts().implicitlyWait(IMPLICIT_WAIT_TIME_LOOP_MS, TimeUnit.MILLISECONDS);

    boolean failed = false;

    for (int second = 0;; second++) {
        Thread.sleep(1000);//  w  w  w  .j a v a 2s  . com
        if (second >= waitSeconds) {
            failed = true;
        }
        try {
            if (failed) {
                break;
            } else if (isAlertPresent(driver)) {
                acceptAlertIfPresent(driver);
                break;
            }
        } catch (Exception e) {
        }
    }

    driver.manage().timeouts().implicitlyWait(configuredImplicityWait(), TimeUnit.SECONDS);
}

From source file:org.kuali.rice.testtools.selenium.WebDriverUtils.java

License:Educational Community License

/**
 * <p>//from   w  ww  . ja  va2 s  . co m
 * Wait for the given amount of seconds, for the given by, using the given driver.  The message is displayed if the
 * by cannot be found.  No action is performed on the by, so it is possible that the by found is not visible or enabled.
 * </p>
 *
 * @param driver WebDriver to wait on
 * @param waitSeconds seconds to wait
 * @param by By to wait for
 * @param message to display if by is not found in waitSeconds
 * @throws InterruptedException
 */
public static WebElement waitFor(WebDriver driver, int waitSeconds, By by, String message)
        throws InterruptedException {
    // jenkins implies that implicitlyWait is worse than sleep loop for finding elements by 100+ test failures on the old sampleapp
    //        driver.manage().timeouts().implicitlyWait(waitSeconds, TimeUnit.SECONDS);
    //        driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);

    driver.manage().timeouts().implicitlyWait(IMPLICIT_WAIT_TIME_LOOP_MS, TimeUnit.MILLISECONDS);

    boolean failed = false;
    WebElement element = null;

    for (int second = 0;; second++) {
        Thread.sleep(1000);
        if (second >= waitSeconds) {
            failed = true;
        }
        try {
            if (failed) {
                break;
            } else if ((driver.findElements(by)).size() > 0) {
                element = findElement(driver, by); // NOTICE just the find, no action, so by is found, but might not be visible or enabled.
                highlightElement(driver, element);
                break;
            }
        } catch (Exception e) {
        }
    }

    driver.manage().timeouts().implicitlyWait(configuredImplicityWait(), TimeUnit.SECONDS);
    return element;
}

From source file:org.kuali.rice.testtools.selenium.WebDriverUtils.java

License:Educational Community License

/**
 * <p>//w  w w .  j av a2 s .co  m
 * Wait for the given amount of seconds, for the given by, using the given driver.  The message is displayed if the
 * by cannot be found.  No action is performed on the by, so it is possible that the by found is not visible or enabled.
 * </p>
 *
 * @param driver WebDriver to wait on
 * @param waitSeconds seconds to wait
 * @param by By to wait for
 * @param message to display if by is not found in waitSeconds
 * @return List of WebElements found
 * @throws InterruptedException
 */
public static List<WebElement> waitFors(WebDriver driver, int waitSeconds, By by, String message)
        throws InterruptedException {
    // jenkins implies that implicitlyWait is worse than sleep loop for finding elements by 100+ test failures on the old sampleapp
    //        driver.manage().timeouts().implicitlyWait(waitSeconds, TimeUnit.SECONDS);
    //        driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);

    driver.manage().timeouts().implicitlyWait(IMPLICIT_WAIT_TIME_LOOP_MS, TimeUnit.MILLISECONDS);

    boolean failed = false;

    for (int second = 0;; second++) {
        Thread.sleep(1000);
        if (second >= waitSeconds) {
            failed = true;
        }
        try {
            if (failed || (driver.findElements(by)).size() > 0) {
                break;
            }
        } catch (Exception e) {
        }
    }

    driver.manage().timeouts().implicitlyWait(configuredImplicityWait(), TimeUnit.SECONDS);
    return driver.findElements(by); // NOTICE just the find, no action, so by is found, but might not be visible or enabled.
}

From source file:org.kurento.room.test.RoomTest.java

License:Open Source License

protected List<WebDriver> createBrowsers(int numUsers)
        throws InterruptedException, ExecutionException, TimeoutException {

    final List<WebDriver> browsers = Collections.synchronizedList(new ArrayList<WebDriver>());

    parallelBrowserInit(numUsers, 0, browsers);

    if (browsers.size() < numUsers) {
        int required = numUsers - browsers.size();
        log.warn("Not enough browsers were created, will retry to " + "recreate the missing ones: {}",
                required);//from ww  w.j a va2s . co m
        parallelBrowserInit(required, browsers.size(), browsers);
    }

    if (browsers.size() < numUsers)
        fail("Unable to create the required number of browsers: " + numUsers);

    int row = 0;
    int col = 0;
    for (WebDriver browser : browsers) {

        browser.manage().window().setSize(new Dimension(BROWSER_WIDTH, BROWSER_HEIGHT));
        browser.manage().window().setPosition(
                new Point(col * BROWSER_WIDTH + LEFT_BAR_WIDTH, row * BROWSER_HEIGHT + TOP_BAR_WIDTH));
        col++;
        if (col * BROWSER_WIDTH + LEFT_BAR_WIDTH > MAX_WIDTH) {
            col = 0;
            row++;
        }
    }

    browsersClosed = false;
    return browsers;
}

From source file:org.mitre.mpf.wfm.ITWebUI.java

License:Open Source License

protected static WebDriver getDriver() {
    WebDriver driver = null;
    driver = new FirefoxDriver(firefoxProfile);
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    driver.manage().window().setSize(new Dimension(1600, 900)); // Xvfb window size .maximize();does not work in Xvfb for headless

    //driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    //driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
    //driver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS);

    return driver;
}

From source file:org.mozilla.zest.core.v1.ZestClientAssignCookie.java

License:Mozilla Public License

@Override
public String invoke(ZestRuntime runtime) throws ZestClientFailException {
    WebDriver wd = runtime.getWebDriver(this.getWindowHandle());
    String val = "";

    if (cookieName != null && cookieName.length() > 0) {
        // A named cookie
        Cookie cookie = wd.manage().getCookieNamed(cookieName);
        if (cookie != null) {
            val = cookie.getValue();
        }/* w w  w  .j  a  va  2s. c o  m*/
    } else {
        // return all of them
        StringBuilder sb = new StringBuilder();
        for (Cookie cookie : wd.manage().getCookies()) {
            sb.append(cookie.getName());
            sb.append("=");
            sb.append(cookie.getValue());
            sb.append("; ");
        }
        val = sb.toString();
    }

    runtime.setVariable(this.variableName, val);
    return val;
}

From source file:org.mozilla.zest.impl.ZestBasicRunner.java

License:Mozilla Public License

@Override
public void addWebDriver(String handle, WebDriver wd) {
    webDriverMap.put(handle, wd);/*from ww  w.j a v a  2  s.c om*/
    wd.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}

From source file:org.neo4j.server.webdriver.WebdriverSauceLabsDriver.java

License:Open Source License

public static WebDriver createDriver(DesiredCapabilities capabilities) throws MalformedURLException {
    String sauceLabsUrl = System.getProperty(WEBDRIVER_SAUCE_LABS_URL);
    if (sauceLabsUrl == null) {
        throw new IllegalArgumentException(String
                .format("To use SauceLabs, %s system property must be provided", WEBDRIVER_SAUCE_LABS_URL));
    }//from w  w  w  . jav  a  2s  . c  o m

    WebDriver driver = new RemoteWebDriver(new URL(sauceLabsUrl), capabilities);
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    return driver;
}