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:com.atanas.kanchev.testframework.selenium.driverfactory.DriverFactory.java

License:Apache License

private WebDriver confTimeouts(WebDriver driver) {
    logger.debug("Setting implicitly wait to: " + DEFAULT_IMPL_WAIT + " ms.");
    driver.manage().timeouts().implicitlyWait(DEFAULT_IMPL_WAIT, TimeUnit.MILLISECONDS);
    logger.debug("Setting page load timeout to: " + DEFAULT_PAGE_LOAD_TIMEOUT + " ms.");
    driver.manage().timeouts().pageLoadTimeout(DEFAULT_PAGE_LOAD_TIMEOUT, TimeUnit.MILLISECONDS);
    return driver;
}

From source file:com.atanas.kanchev.testframework.selenium.driverfactory.DriverFactory.java

License:Apache License

private WebDriver confResolution(WebDriver driver) {

    if (isStartMaximized()) {
        logger.debug("Maximising browser window");
        driver.manage().window().maximize();
    } else {/*from   w w w  .j a  v a 2s .  c  om*/
        logger.debug("Setting resolution to: " + DEFAULT_BROWSER_RES_WIDTH + "*" + DEFAULT_BROWSER_RES_HEIGHT);
        driver.manage().window().setSize(new Dimension(DEFAULT_BROWSER_RES_WIDTH, DEFAULT_BROWSER_RES_HEIGHT));
    }

    return driver;
}

From source file:com.automatewebtesting.framework.testdata.TestSuiteContext.java

private void launchBrowser() {
    //driver = new FirefoxDriver();
    System.setProperty("webdriver.chrome.driver",
            "C:\\Automation\\NewConnect2Yes\\chromedriver\\chromedriver.exe");
    System.out.println("Driver :" + System.getProperty("webdriver.chrome.driver"));
    WebDriver driver = new ChromeDriver();
    driver.manage().window().maximize();
}

From source file:com.axatrikx.webdriver.DriverLoader.java

License:Apache License

public WebDriver getDriver() {
    WebDriver driver = null;
    if (browser.toLowerCase().startsWith("f")) {
        driver = getFirefoxDriver();//from  w ww .  j a  v a  2s .  c o m
    } else if (browser.toLowerCase().startsWith("c")) {
        driver = getChromeDriver();
    } else if (browser.toLowerCase().startsWith("i")) {
        driver = getIEDriver();
    } else if (browser.toLowerCase().startsWith("h")) {
        driver = getHTMLUnitDriver();
    } else {
        throw new ConfigurationException("Invalid browser specified : " + this.browser);
    }

    // Set default timeout
    driver.manage().timeouts().implicitlyWait(defaultTimeOut, TimeUnit.SECONDS);

    // set maximize window
    if (maximizeWindow)
        driver.manage().window().maximize();

    return driver;
}

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. 
  * // www.  j  a  v  a 2 s  .  c om
  * @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.
  *//from   w w w.  j ava 2s  . c  o m
  * 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.
  */*from   w ww. j ava 2  s .co  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
 * //w w w  .j a  v  a2 s  . co  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
 * /* w  ww  . ja  v  a2s . 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.booleanworks.kryptopterus.selenium.testsuite001.BaseWelcomePageTest.java

@Test
@Ignore/*w w  w.  j  av  a2  s . com*/
public void testSimple() throws Exception {
    // Create a new instance of the Firefox driver
    // Notice that the remainder of the code relies on the interface, 
    // not the implementation.

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("phantomjs.page.settings.userAgent",
            "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/53.0.2785.143 Chrome/53.0.2785.143 Safari/537.36");
    capabilities.setCapability("phantomjs.page.settings.localToRemoteUrlAccessEnabled", true);
    capabilities.setCapability("phantomjs.page.settings.browserConnectionEnabled", true);
    capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
            "/usr/local/bin/phantomjs");
    capabilities.setCapability("takesScreenshot", true);

    WebDriver driver = new PhantomJSDriver((Capabilities) capabilities);
    driver.manage().window().setSize(new Dimension(1200, 800));
    driver.manage().timeouts().implicitlyWait(120, TimeUnit.SECONDS);

    // And now use this to visit NetBeans
    driver.get("http://localhost:8084/kryptopterus/");
    // Alternatively the same thing can be done like this
    // driver.navigate().to("http://www.netbeans.org");

    // Check the title of the page
    // Wait for the page to load, timeout after 10 seconds
    (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
        @Override
        public Boolean apply(WebDriver d) {
            return d.getTitle().contains("NetBeans");
        }
    });

    //Close the browser
    driver.quit();
}