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.thoughtworks.selenium.webdriven.commands.GetCookieByName.java

License:Apache License

@Override
protected String handleSeleneseCommand(WebDriver driver, String name, String ignored) {
    Cookie cookie = driver.manage().getCookieNamed(name);
    return cookie == null ? null : cookie.getValue();
}

From source file:com.thoughtworks.selenium.webdriven.commands.IsCookiePresent.java

License:Apache License

@Override
protected Boolean handleSeleneseCommand(WebDriver driver, String name, String ignored) {
    return driver.manage().getCookieNamed(name) == null ? false : true;
}

From source file:com.tribuneqa.utilities.FrameworkUtilities.java

public void loadAndResize(WebDriver driver, String uri, int xAxis, int yAxis) {

    driver.manage().window().setSize(new Dimension(xAxis, yAxis));
    driver.get(FrameworkProperties.HOMEPAGE_URL + uri);

}

From source file:com.twiceagain.mywebdriver.driver.web.Drivers.java

License:Open Source License

/**
 * Get a driver with the specified config.
 *
 * @param config/*from  w w w. j a  va  2s. c  om*/
 * @return
 */
public static WebDriver getDriver(final Config config) {
    WebDriver wd;
    try {
        // Local firefox instance
        if (!config.useGrid) {
            // LoadGeckodriver if needed
            Config.installGeckoDriver();
            // Set geckodriver full absolute path
            System.setProperty("webdriver.gecko.driver", Config.geckodriverPath);
            wd = new FirefoxDriver(config.getDesiredCapabilities());
            // Grid instance
        } else {

            wd = new RemoteWebDriver(new URL(config.gridUrl), config.getDesiredCapabilities());

        }
    } catch (IOException ex) {
        LOG.log(Level.SEVERE, null, ex);
        return null;
    }

    // Adjust window size
    wd.manage().window().setSize(new Dimension(config.width, config.height));
    return wd;
}

From source file:com.twiceagain.mywebdriver.driver.web.Drivers.java

License:Open Source License

/**
 * Adjust page height to ensure there are no vertical scrollbars. Caution :
 * this seems to crash the browser when run in Grid mode ...
 *
 * @param wd/*from www  .  j a v a 2s . c o m*/
 */
public static void adjustPageHeight(WebDriver wd) {
    int ww = wd.manage().window().getSize().width;
    int hh = wd.manage().window().getSize().height;
    hh = Math.max(hh, Drivers.getPageHeigth(wd) + 200);
    wd.manage().window().setSize(new Dimension(ww, hh));
}

From source file:com.vaadin.testbench.TestBenchDriverTest.java

@Test
public void testTestBenchDriverActsAsProxy() {
    FirefoxDriver mockDriver = createMock(FirefoxDriver.class);
    mockDriver.close();//  w w  w  . ja v a 2s  . c o  m
    expectLastCall().once();
    WebElement mockElement = createNiceMock(WebElement.class);
    expect(mockDriver.findElement(isA(By.class))).andReturn(mockElement);
    List<WebElement> elements = Arrays.asList(mockElement);
    expect(mockDriver.findElements(isA(By.class))).andReturn(elements);
    mockDriver.get("foo");
    expectLastCall().once();
    expect(mockDriver.getCurrentUrl()).andReturn("foo");
    expect(mockDriver.getPageSource()).andReturn("<html></html>");
    expect(mockDriver.getTitle()).andReturn("bar");
    expect(mockDriver.getWindowHandle()).andReturn("baz");
    Set<String> handles = new HashSet<String>();
    expect(mockDriver.getWindowHandles()).andReturn(handles);
    Options mockOptions = createNiceMock(Options.class);
    expect(mockDriver.manage()).andReturn(mockOptions);
    Navigation mockNavigation = createNiceMock(Navigation.class);
    expect(mockDriver.navigate()).andReturn(mockNavigation);
    mockDriver.quit();
    expectLastCall().once();
    expect(((JavascriptExecutor) mockDriver).executeScript(anyObject(String.class))).andStubReturn(true);
    TargetLocator mockTargetLocator = createNiceMock(TargetLocator.class);
    expect(mockDriver.switchTo()).andReturn(mockTargetLocator);
    replay(mockDriver);

    // TestBenchDriverProxy driver = new TestBenchDriverProxy(mockDriver);
    WebDriver driver = TestBench.createDriver(mockDriver);
    driver.close();
    By mockBy = createNiceMock(By.class);
    assertTrue(driver.findElement(mockBy) instanceof TestBenchElementCommands);
    assertTrue(driver.findElements(mockBy).get(0) instanceof TestBenchElementCommands);
    driver.get("foo");
    assertEquals("foo", driver.getCurrentUrl());
    assertEquals("<html></html>", driver.getPageSource());
    assertEquals("bar", driver.getTitle());
    assertEquals("baz", driver.getWindowHandle());
    assertEquals(handles, driver.getWindowHandles());
    assertEquals(mockOptions, driver.manage());
    assertEquals(mockNavigation, driver.navigate());
    driver.quit();
    assertEquals(mockTargetLocator, driver.switchTo());

    verify(mockDriver);
}

From source file:com.virtusa.isq.vtaf.runtime.SeleniumTestBase.java

License:Apache License

/**
 * Opens an URL in the test frame. This accepts both relative and absolute
 * URLs. The "open" command <br>// w  ww.j  a v a 2 s  .  co m
 * waits for the page to load before proceeding, ie. the "AndWait" suffix is
 * implicit. Note: The URL <br>
 * must be on the same domain as the runner HTML due to security
 * restrictions in the browser <br>
 * (Same Origin Policy). If you need to open an URL on another domain, use
 * the Selenium Server <br>
 * to start a new browser session on that domain.
 * 
 * @param locator
 *            : url of the openning page
 * @param waitTime
 *            : time to wait till the page is loaded.
 * 
 * */
private void doOpen(final ObjectLocator locator, final String waitTime) {
    String url = "";
    WebDriver driver = getDriver();
    try {
        url = locator.getActualLocator();
        if ("default".equalsIgnoreCase(url)) {
            PropertyHandler propertyHandler = new PropertyHandler("runtime.properties");
            url = propertyHandler.getRuntimeProperty("DEFAULT_URL");
            if ("".equals(url)) {
                throw new WebDriverException("Empty URL : " + url);
            }
        }
        setCommandStartTime(getCurrentTime());
        driver.get(url);

        try {
            driver.manage().timeouts().implicitlyWait(Integer.parseInt(waitTime), TimeUnit.MILLISECONDS);
        } catch (Exception e) {
            e.printStackTrace();
        }

        reportresult(true, "OPEN : " + url + "", "PASSED", url);
    } catch (WebDriverException e) {

        String errorString = e.getMessage();
        reportresult(true, "OPEN : " + url + "", "FAILED",
                "Cannot access the empty URL. URL : " + url + ". Actual Error : " + errorString);
        checkTrue(false, true, "Cannot access the empty URL. URL : " + url + ". Actual Error : " + errorString);
    } catch (Exception e) {
        String errorString = e.getMessage();
        reportresult(true, "OPEN : " + url + "", "FAILED",
                "Cannot access the URL. URL : " + url + ". Actual Error : " + errorString);
        checkTrue(false, true, "Cannot access the URL. URL : " + url + ". Actual Error : " + errorString);
    }

}

From source file:com.virtusa.isq.vtaf.runtime.SeleniumTestBase.java

License:Apache License

/**
 * Arguments: <br>/* w w w . j a v a 2  s .  c  o m*/
 * <br>
 * 
 * windowID - the JavaScript window ID of the window to select<br>
 * 
 * Selects a popup window using a window locator; once a popup window has
 * been selected, all commands go to that window. To select the main window
 * again, use null as the target.<br>
 * <br>
 * 
 * Window locators provide different ways of specifying the window object:
 * by title, by internal JavaScript "name," or by JavaScript variable.<br>
 * <br>
 * 
 * title=My Special Window: Finds the window using the text that appears in
 * the title bar. Be careful; two windows can share the same title. If that
 * happens, this locator will just pick one.<br>
 * name=myWindow: Finds the window using its internal JavaScript "name"
 * property. This is the second parameter "windowName" passed to the
 * JavaScript method window.open(url, windowName, windowFeatures,
 * replaceFlag) (which Selenium intercepts).<br>
 * var=variableName: Some pop-up windows are unnamed (anonymous), but are
 * associated with a JavaScript variable name in the current application
 * window, e.g. "window.foo = window.open(url);". In those cases, you can
 * open the window using "var=foo".<br>
 * <br>
 * 
 * If no window locator prefix is provided, we'll try to guess what you mean
 * like this:<br>
 * <br>
 * 
 * 1.) if windowID is null, (or the string "null") then it is assumed the
 * user is referring to the original window instantiated by the browser).<br>
 * <br>
 * 
 * 2.) if the value of the "windowID" parameter is a JavaScript variable
 * name in the current application window, then it is assumed that this
 * variable contains the return value from a call to the JavaScript
 * window.open() method.<br>
 * <br>
 * 
 * 3.) Otherwise, selenium looks in a hash it maintains that maps string
 * names to window "names".<br>
 * <br>
 * 
 * 4.) If that fails, we'll try looping over all of the known windows to try
 * to find the appropriate "title". Since "title" is not necessarily unique,
 * this may have unexpected behavior.<br>
 * <br>
 * 
 * If you're having trouble figuring out the name of a window that you want
 * to manipulate, look at the Selenium log messages which identify the names
 * of windows created via window.open (and therefore intercepted by
 * Selenium). You will see messages like the following for each window as it
 * is opened:<br>
 * <br>
 * 
 * debug: window.open call intercepted; window ID (which you can use with
 * selectWindow()) is "myNewWindow"<br>
 * <br>
 * 
 * In some cases, Selenium will be unable to intercept a call to window.open
 * (if the call occurs during or before the "onLoad" event, for example).
 * (This is bug SEL-339.) In those cases, you can force Selenium to notice
 * the open window's name by using the Selenium openWindow command, using an
 * empty (blank) url, like this: openWindow("", "myFunnyWindow").<br>
 * <br>
 * 
 * @param locator
 *            : Logical name of the window assigned by the test scriptor
 * 
 * 
 * */
private void doSelectWindow(final ObjectLocator locator) {
    int counter = getRetryCount();
    String targetWindow = null;
    WebDriver driver = getDriver();

    // Getting the actual object identification from the object map
    String window = locator.getActualLocator();
    try {
        checkForNewWindowPopups();

        /*
         * START DESCRIPTION following for loop was added to make the
         * command more consistent try the command for give amount of time
         * (can be configured through class variable RETRY) command will be
         * tried for "RETRY" amount of times or untill command works. any
         * exception thrown within the tries will be handled internally.
         * 
         * can be exited from the loop under 2 conditions 1. if the command
         * succeeded 2. if the RETRY count is exceeded
         */
        while (counter > 0) {
            try {
                counter--;

                targetWindow = getMatchingWindowFromCurrentWindowHandles(driver, window);

                if (targetWindow != null) {

                    driver.switchTo().window(targetWindow);

                    driver.manage().window().maximize();
                    focusToCurrentWindow(driver);

                    reportresult(true, "SELECT WINDOW :" + locator.getLogicalName() + "", "PASSED", "");
                    break;
                } else {
                    throw new WebDriverException("Window Not Found" + window);
                }
            } catch (WebDriverException ex) {
                sleep(retryInterval);
                if (!(counter > 0)) {
                    String errorString = ex.getMessage();
                    String objectName = locator.getLogicalName();
                    reportresult(true, "SELECT WINDOW :" + objectName + "", "FAILED",
                            "selectWindow command  :Element (" + objectName + ") [" + window
                                    + "] is not accessible. Actual Error : " + errorString);
                    checkTrue(false, true, "selectWindow command  :Element (" + objectName + ") [" + window
                            + "] is not accessible. Actual Error : " + errorString);
                }
            }
        }

    } catch (Exception e) {
        e.printStackTrace();
        String objectName = locator.getLogicalName();
        // if any exception is raised, report failure
        reportresult(true, "SELECT WINDOW :" + objectName + "", "FAILED",
                "selectWindow command  :Element (" + objectName + ") [" + window + "] not present");
        checkTrue(false, true,
                "selectWindow command  :Element (" + objectName + ") [" + window + "] not present");

    }

}

From source file:com.volkhart.selenium.util.Window.java

License:Apache License

/**
 * Maximizes the browser window./*from  w w w  .j a  v a 2s. c o m*/
 * 
 * @param driver
 *            WebDriver instance being maximized
 */
public static void maximize(WebDriver driver) {
    Toolkit t = Toolkit.getDefaultToolkit();
    java.awt.Dimension screenSize = t.getScreenSize();
    Dimension screenRes = new Dimension(screenSize.width, screenSize.height);
    driver.manage().window().setSize(screenRes);
}

From source file:com.webdriver1.MouseOver.java

public static void main(String[] args) throws InterruptedException {
    WebDriver driver = new FirefoxDriver();
    //maximize window
    driver.manage().window().maximize();
    //wait for page load
    driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);
    //Go to URL/*from w  w  w  .  j  a  va 2  s.co m*/
    driver.get("http://flex.apache.org/");
    //Get web element
    WebElement element = driver.findElement(By.xpath("//ul[@id='nav']/li[2]/a"));
    //Thread.sleep(1000);
    //Get sub web element/html/body/div[1]/div[1]/
    WebElement element1 = driver.findElement(By.xpath("//a[contains(text(),'License & Trademarks')]"));
    //Declare Actions Object
    Actions action = new Actions(driver);
    //Mouse over on element items
    action.moveToElement(element).build().perform();
    //wait for items
    Thread.sleep(2000);
    //click on element1 items
    action.moveToElement(element1).clickAndHold().build().perform();

}