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.fitting.selenium.fixture.CookieFixture.java

License:Apache License

/**
 * Clears all cookies on the provided domain.
 *
 * @param driver The web driver./*w  ww  .j av  a 2 s  .  c o m*/
 * @param domain The domain.
 */
private void clearAllCookiesOnDomain(final WebDriver driver, String domain) {
    handleCookie(domain, new CookieCallback() {
        @Override
        public void execute() {
            driver.manage().deleteAllCookies();
        }
    });
}

From source file:org.fitting.selenium.fixture.CookieFixture.java

License:Apache License

/**
 * Clears all cookies on the provided domain.
 *
 * @param driver The web driver./*  ww w  . j a  va2s .c o m*/
 * @param name   The name of the cookie.
 * @param domain The domain.
 */
private void deleteCookieWithNameOnDomain(final WebDriver driver, final String name, String domain) {
    handleCookie(domain, new CookieCallback() {
        @Override
        public void execute() {
            driver.manage().deleteCookieNamed(name);
        }
    });
}

From source file:org.fitting.selenium.fixture.CookieFixture.java

License:Apache License

/**
 * Indicates if a cookie with the given name exists on the given domain.
 *
 * @param driver The web driver.//w  ww  .  j a v  a 2 s .co  m
 * @param name   The name of the cookie.
 * @param domain The domain.
 *
 * @return <code>true</code> if cookie is present, else <code>false</code>.
 */
private boolean isCookieWithNamePresentOnDomain(final WebDriver driver, final String name, String domain) {
    final boolean[] exists = { false };
    handleCookie(domain, new CookieCallback() {
        @Override
        public void execute() {
            if (driver.manage().getCookieNamed(name) != null) {
                exists[0] = true;
            }
        }
    });
    return exists[0];
}

From source file:org.glowroot.agent.webdriver.tests.WebDriverSetup.java

License:Apache License

private static WebDriverSetup createSetup(boolean shared) throws Exception {
    int uiPort = getAvailablePort();
    File baseDir = Files.createTempDir();
    File configFile = new File(baseDir, "config.json");
    Files.write("{\"ui\":{\"port\":" + uiPort + "}}", configFile, Charsets.UTF_8);
    Container container;/*from   w w w  .  j av a2 s.c  o m*/
    if (Containers.useJavaagent()) {
        container = new JavaagentContainer(baseDir, true, false,
                ImmutableList.of("-Dglowroot.collector.host="));
    } else {
        container = new LocalContainer(baseDir, true, ImmutableMap.of("glowroot.collector.host", ""));
    }
    if (SauceLabs.useSauceLabs()) {
        return new WebDriverSetup(container, uiPort, shared, null, null);
    } else {
        SeleniumServer seleniumServer = new SeleniumServer();
        seleniumServer.start();
        // currently tests fail with default nativeEvents=true
        // (can't select radio buttons on capture point page)
        DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
        capabilities.setCapability("nativeEvents", false);
        // single webdriver instance for much better performance
        WebDriver driver;
        if (USE_LOCAL_IE) {
            driver = new InternetExplorerDriver(capabilities);
        } else {
            driver = new FirefoxDriver(capabilities);
        }
        // 768 is bootstrap media query breakpoint for screen-sm-min
        // 992 is bootstrap media query breakpoint for screen-md-min
        // 1200 is bootstrap media query breakpoint for screen-lg-min
        driver.manage().window().setSize(new Dimension(1200, 800));
        return new WebDriverSetup(container, uiPort, shared, seleniumServer, driver);
    }
}

From source file:org.glowroot.tests.webdriver.WebDriverSetup.java

License:Apache License

private static WebDriverSetup createSetup(boolean shared) throws Exception {
    Container container = Containers.getSharedContainer();
    if (SauceLabs.useSauceLabs()) {
        // glowroot must listen on one of the ports that sauce connect proxies
        // see https://saucelabs.com/docs/connect#localhost
        UserInterfaceConfig userInterfaceConfig = container.getConfigService().getUserInterfaceConfig();
        userInterfaceConfig.setPort(4000);
        container.getConfigService().updateUserInterfaceConfig(userInterfaceConfig);
        return new WebDriverSetup(container, null, null, shared);
    } else {/*from  www. j a  v  a  2  s .  c  om*/
        SeleniumServer seleniumServer = new SeleniumServer();
        seleniumServer.start();
        // currently tests fail with default nativeEvents=true
        // (can't select radio buttons on capture point page)
        DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
        capabilities.setCapability("nativeEvents", false);
        // single webdriver instance for much better performance
        WebDriver driver;
        if (USE_LOCAL_IE) {
            driver = new InternetExplorerDriver(capabilities);
        } else {
            driver = new FirefoxDriver(capabilities);
        }
        // 992 is bootstrap media query breakpoint for screen-md-min
        // 1200 is bootstrap media query breakpoint for screen-lg-min
        driver.manage().window().setSize(new Dimension(1200, 800));
        return new WebDriverSetup(container, seleniumServer, driver, shared);
    }
}

From source file:org.glowroot.tests.WebDriverSetup.java

License:Apache License

private static WebDriverSetup createSetup(boolean shared) throws Exception {
    int uiPort = getAvailablePort();
    File testDir = Files.createTempDir();
    Container container;/*from w  w w . j a  v  a2s  .  c o  m*/
    if (useCentral) {
        CassandraWrapper.start();
        Cluster cluster = Cluster.builder().addContactPoint("127.0.0.1").build();
        Session session = cluster.newSession();
        session.execute("create keyspace if not exists glowroot_unit_tests with replication ="
                + " { 'class' : 'SimpleStrategy', 'replication_factor' : 1 }");
        session.execute("use glowroot_unit_tests");
        session.execute("drop table if exists agent");
        session.execute("drop table if exists agent_rollup");
        session.execute("drop table if exists user");
        session.execute("drop table if exists role");
        session.execute("drop table if exists central_config");
        session.close();
        cluster.close();
        container = createCentralAndContainer(uiPort, testDir);
    } else {
        container = createContainer(uiPort, testDir);
    }
    if (SauceLabs.useSauceLabs()) {
        return new WebDriverSetup(container, uiPort, shared, null);
    } else {
        // single webdriver instance for much better performance
        WebDriver driver;
        if (USE_FIREFOX) {
            File geckoDriverExecutable = downloadGeckoDriverIfNeeded();
            System.setProperty("webdriver.gecko.driver", geckoDriverExecutable.getAbsolutePath());
            driver = new FirefoxDriver();
        } else {
            driver = new JBrowserDriver();
        }
        // 768 is bootstrap media query breakpoint for screen-sm-min
        // 992 is bootstrap media query breakpoint for screen-md-min
        // 1200 is bootstrap media query breakpoint for screen-lg-min
        driver.manage().window().setSize(new Dimension(1200, 800));
        return new WebDriverSetup(container, uiPort, shared, driver);
    }
}

From source file:org.gradle.needle.selenium.CaptureScreenshot.java

License:Apache License

public static String screenShot(BrowserFactory bf) {
    String dir = "screenshot"; // TODO
    String time = new SimpleDateFormat("yyyyMMdd-HH:mm:ss").format(new Date());
    String screenShotPath = dir + File.separator + time + ".png";
    WebDriver augmentedDriver = null;
    if (GlobalSettings.browserCoreType == 1 || GlobalSettings.browserCoreType == 3) {
        augmentedDriver = bf.getBrowserCore();
        augmentedDriver.manage().window().setPosition(new Point(0, 0));
        augmentedDriver.manage().window().setSize(new Dimension(9999, 9999));
    } else if (GlobalSettings.browserCoreType == 2) {
        augmentedDriver = new Augmenter().augment(bf.getBrowserCore());
    } else {/*from   ww  w . j ava2 s.co  m*/
        return "";
    }

    try {
        File sourceFile = ((TakesScreenshot) augmentedDriver).getScreenshotAs(OutputType.FILE);
        FileUtils.copyFile(sourceFile, new File(screenShotPath));

    } catch (Exception e) {
        e.printStackTrace();
        return "";
    }

    return screenShotPath.replace("\\", "/");
}

From source file:org.jboss.arquillian.drone.webdriver.factory.remote.reusable.ftest.TestReusingCookies.java

License:Apache License

@Test
@InSequence(1)//from w  w  w. ja v  a2 s  .  c  o m
public void testCookieWasNotThere(@Drone @Reusable WebDriver driver) {
    driver.get(HUB_URL.toString());
    Assert.assertNull("Cookie is not there", driver.manage().getCookieNamed("foo"));
}

From source file:org.jboss.arquillian.drone.webdriver.factory.remote.reusable.ftest.TestReusingCookies.java

License:Apache License

@Test
@InSequence(2)/*  w  ww  .j a v a  2 s.c o m*/
public void testCookieWasStored(@Drone @Reusable WebDriver driver) {
    driver.get(HUB_URL.toString());
    driver.manage().addCookie(new Cookie("foo", "bar"));
    Assert.assertNotNull("Cookie was stored", driver.manage().getCookieNamed("foo"));
    Assert.assertEquals("Cookie was stored", "bar", driver.manage().getCookieNamed("foo").getValue());
}

From source file:org.jboss.arquillian.drone.webdriver.factory.remote.reusable.ftest.TestReusingCookies.java

License:Apache License

@Test
@InSequence(3)/*w ww  .  j  a  v  a2  s .co  m*/
public void testCookieWasDeleted(@Drone @Reusable WebDriver driver) {
    driver.get(HUB_URL.toString());
    Assert.assertNull("Cookie is not there", driver.manage().getCookieNamed("foo"));
}