Example usage for org.openqa.selenium.remote RemoteWebDriver manage

List of usage examples for org.openqa.selenium.remote RemoteWebDriver manage

Introduction

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

Prototype

@Override
    public Options manage() 

Source Link

Usage

From source file:com.ariatemplates.seleniumjavarobot.LocalRobotizedBrowserFactory.java

License:Apache License

protected IBrowser createBrowser() {
    RemoteWebDriver driver = createWebDriver();
    driver.manage().window().maximize();
    return new RemoteWebDriverBrowser(driver);
}

From source file:com.digitalpebble.stormcrawler.protocol.selenium.RemoteDriverProtocol.java

License:Apache License

@Override
public void configure(Config conf) {
    super.configure(conf);

    // see https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setJavascriptEnabled(true);

    String userAgentString = getAgentString(conf);

    // custom capabilities
    Map<String, Object> confCapabilities = (Map<String, Object>) conf.get("selenium.capabilities");
    if (confCapabilities != null) {
        Iterator<Entry<String, Object>> iter = confCapabilities.entrySet().iterator();
        while (iter.hasNext()) {
            Entry<String, Object> entry = iter.next();
            Object val = entry.getValue();
            // substitute variable $useragent for the real value
            if (val instanceof String && "$useragent".equalsIgnoreCase(val.toString())) {
                val = userAgentString;
            }/*from   w ww.ja  v a 2s .  co m*/
            capabilities.setCapability(entry.getKey(), entry.getValue());
        }
    }

    // load adresses from config
    List<String> addresses = ConfUtils.loadListFromConf("selenium.addresses", conf);
    if (addresses.size() == 0) {
        throw new RuntimeException("No value found for selenium.addresses");
    }
    try {
        for (String cdaddress : addresses) {
            RemoteWebDriver driver = new RemoteWebDriver(new URL(cdaddress), capabilities);
            Timeouts touts = driver.manage().timeouts();
            int implicitWait = ConfUtils.getInt(conf, "selenium.implicitlyWait", 0);
            int pageLoadTimeout = ConfUtils.getInt(conf, "selenium.pageLoadTimeout", -1);
            int setScriptTimeout = ConfUtils.getInt(conf, "selenium.setScriptTimeout", 0);
            touts.implicitlyWait(implicitWait, TimeUnit.MILLISECONDS);
            touts.pageLoadTimeout(pageLoadTimeout, TimeUnit.MILLISECONDS);
            touts.setScriptTimeout(setScriptTimeout, TimeUnit.MILLISECONDS);
            drivers.add(driver);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.griddynamics.cd.selenium.WebDriverFactory.java

License:Apache License

public WebDriver createDriver(Capabilities capabilities) {
    DesiredCapabilities finalCapabilities = new DesiredCapabilities(capabilities);
    finalCapabilities = withProxy(finalCapabilities);
    finalCapabilities = withChromeOptions(finalCapabilities);
    try {/*from  w w  w  .  j a  v  a  2  s. co  m*/
        RemoteWebDriver driver = new RemoteWebDriver(new URL(webDriverUrl), finalCapabilities);
        //otherwise it may fail from time to time because of performance/network glitches on the node
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        return driver;
    } catch (MalformedURLException e) {
        throw new IllegalArgumentException("Couldn't start WebDriver Session with: " + webDriverUrl, e);
    }
}

From source file:com.tractionsoftware.reshoot.Reshoot.java

License:Apache License

private static void setBrowserSize(RemoteWebDriver driver, Region region) {
    if (region != null && (region.width > 0 || region.height > 0)) {
        Options manage = driver.manage();
        Window window = manage.window();

        Dimension current = window.getSize();

        int width = getDimension(region.width, current.width);
        int height = getDimension(region.height, current.height);

        window.setSize(new Dimension(width, height));
    }/*from w  w w.j av  a  2s.  co  m*/
}

From source file:com.tractionsoftware.reshoot.Reshoot.java

License:Apache License

private static boolean isRetina(RemoteWebDriver driver, BufferedImage img) {
    Dimension size = driver.manage().window().getSize();
    return (size.width == img.getWidth() / 2);
}

From source file:com.watchrabbit.crawler.auth.service.AuthServiceImpl.java

License:Apache License

@Override
public Collection<Cookie> getSession(String domain) {
    Collection<Cookie> cookies = sessionRepository.findByDomain(domain);
    if (cookies != null) {
        return cookies;
    }// ww  w  .  j a  v  a  2 s  .  c  om
    RemoteWebDriver driver = remoteWebDriverFactory.produceDriver();
    try {
        AuthData authData = authDataDao.findByDomain(domain);
        if (authData == null) {
            LOGGER.info("Cannot find auth data for {}", domain);
            return emptyList();
        }
        driver.get(authData.getAuthEndpointUrl());
        loaderService.waitFor(driver);

        WebElement loginForm = locateLoginForm(driver);
        if (loginForm == null) {
            LOGGER.error("Cannot locate any form that matches criteria on {}", authData.getAuthEndpointUrl());
            return emptyList();
        }
        WebElement password = findPasswordInput(loginForm);
        LOGGER.debug("Found password field with name {}", password.getAttribute("name"));
        WebElement login = findLoginInput(loginForm);
        LOGGER.debug("Found login field with name {}", login.getAttribute("name"));

        login.sendKeys(authData.getLogin());
        password.sendKeys(authData.getPassword());
        loginForm.submit();
        loaderService.waitFor(driver);

        cookies = driver.manage().getCookies();
        Calendar now = clock.getCalendar();
        now.add(Calendar.SECOND, authData.getSessionDuration());
        sessionRepository.save(domain, cookies, now.getTime());
        return cookies;
    } finally {
        remoteWebDriverFactory.returnWebDriver(driver);
    }
}

From source file:com.watchrabbit.crawler.driver.factory.FirefoxWebDriverFactory.java

License:Apache License

@Override
public void returnWebDriver(RemoteWebDriver driver) {
    if (driver != null) {
        LOGGER.debug("Moving {} driver back to pool", driver.getWindowHandle());
        if (drivers.size() > maxWaitingDriverSessions) {
            LOGGER.debug("Maximum waiting sessions exceeded, quitting driver");
            driver.quit();//from w ww .  j  a va  2s .  c o  m
        } else {
            driver.manage().deleteAllCookies();
            drivers.add(driver);
        }
    }
}

From source file:com.watchrabbit.crawler.driver.factory.FirefoxWebDriverFactoryIT.java

License:Apache License

@Test
public void shouldExtractCookie() {
    RemoteWebDriver driver = null;//from  w  ww .  j  ava 2  s  . co  m
    RemoteWebDriver driver2 = null;
    try {
        driver = firefoxFactory.produceDriver();
        driver.get("https://verif.pl:4848/");

        driver2 = firefoxFactory.produceDriver();
        driver2.get("https://verif.pl:4848/");

        driver2.manage().deleteAllCookies();
        driver2.manage().addCookie(driver.manage().getCookieNamed("JSESSIONID"));

        assertThat(driver.manage().getCookieNamed("JSESSIONID").getValue())
                .isEqualTo(driver2.manage().getCookieNamed("JSESSIONID").getValue());
    } finally {
        firefoxFactory.returnWebDriver(driver);
        firefoxFactory.returnWebDriver(driver2);
    }
}

From source file:com.watchrabbit.crawler.executor.service.CrawlExecutorServiceImpl.java

License:Apache License

private void enableSession(RemoteWebDriver driver, CrawlForm form, Collection<Cookie> session) {
    driver.get(form.getUrl());/*from w ww .j  ava2 s .  c  om*/
    loaderService.waitFor(driver);
    if (!session.isEmpty()) {
        driver.manage().deleteAllCookies();
        session.forEach(driver.manage()::addCookie);

        driver.get(form.getUrl());
        loaderService.waitFor(driver);
    }
    if (StringUtils.isNotEmpty(form.getKeyword())) {
        Optional<SearchForm> searchFormOptional = findSearchInput(driver);
        searchFormOptional.ifPresent(searchForm -> {
            searchForm.input.sendKeys(form.getKeyword());
            loaderService.waitFor(driver);
            searchForm.submit.click();
            loaderService.waitFor(driver);
        });

    }
}

From source file:de.knowwe.uitest.UITestUtils.java

License:Open Source License

public static RemoteWebDriver setUp(String browser, String testClassName, Platform os, WikiTemplate template,
        String testName, boolean devMode) throws IOException, InterruptedException {

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(CapabilityType.BROWSER_NAME, browser);
    String chromeBinary = System.getProperty("knowwe.chrome.binary");
    if (chromeBinary != null) {
        ChromeOptions chromeOptions = new ChromeOptions();
        chromeOptions.setBinary(chromeBinary);
        capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
    }//from ww  w .jav a2s .c  om

    RemoteWebDriver driver;
    if (devMode) {
        driver = new RemoteWebDriver(new URL("http://localhost:9515"), capabilities);
    } else {
        capabilities.setCapability("name", testClassName);
        capabilities.setCapability("platform", os);
        driver = new RemoteWebDriver(
                new URL("http://d3web:8c7e5a48-56dd-4cde-baf0-b17f83803044@ondemand.saucelabs.com:80/wd/hub"),
                capabilities);
    }
    driver.manage().window().setSize(new Dimension(1024, 768));
    driver.get(UITestUtils.getKnowWEUrl(template, "Main", devMode));
    if (!UITestUtils.isLoggedIn(driver, template)) {
        UITestUtils.logIn(driver, "UiTest", "fyyWWyVeHzzHfkUMZxUQ?3nDBPbTT6", NORMAL_PAGE, template);
    }
    driver.get(getKnowWEUrl(template, testName, devMode));
    if (!pageExists(template, driver)) {
        createDummyPage(template, driver);
    }
    return driver;
}