Package org.openqa.selenium.remote

Examples of org.openqa.selenium.remote.DesiredCapabilities


        }

        Validate.isEmpty(configuration.getBrowser(), "The browser is not set.");

        // construct capabilities
        DesiredCapabilities desiredCapabilities = new DesiredCapabilities(configuration.getCapabilities());

        RemoteWebDriver driver = null;

        if (configuration.isRemoteReusable()) {
            driver = createReusableDriver(remoteAddress, desiredCapabilities);
View Full Code Here


  protected WebDriver createFirefoxDriver() {
    return maximize(new FirefoxDriver());
  }

  protected WebDriver createHtmlUnitDriver() {
    DesiredCapabilities capabilities = DesiredCapabilities.htmlUnit();
    capabilities.setCapability(HtmlUnitDriver.INVALIDSELECTIONERROR, true);
    capabilities.setCapability(HtmlUnitDriver.INVALIDXPATHERROR, false);
    capabilities.setJavascriptEnabled(true);
    if (browser.indexOf(':') > -1) {
      // Use constants BrowserType.IE, BrowserType.FIREFOX, BrowserType.CHROME etc.
      String emulatedBrowser = browser.replaceFirst("htmlunit:(.*)", "$1");
      capabilities.setVersion(emulatedBrowser);
    }
    return new HtmlUnitDriver(capabilities);
  }
View Full Code Here

    try {
      Class<?> clazz = Class.forName(className);
      if (WebDriverProvider.class.isAssignableFrom(clazz)) {
        return ((WebDriverProvider)clazz.newInstance()).createDriver();
      } else {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setJavascriptEnabled(true);
        capabilities.setCapability(TAKES_SCREENSHOT, true);

        Constructor<?> constructor = Class.forName(className).getConstructor(Capabilities.class);
        return (WebDriver) constructor.newInstance(capabilities);
      }
    }
View Full Code Here

    }
  }

  protected WebDriver createRemoteDriver(String remote, String browser) {
    try {
      DesiredCapabilities capabilities = new DesiredCapabilities();
      capabilities.setBrowserName(browser);
      return new RemoteWebDriver(new URL(remote), capabilities);
    } catch (MalformedURLException e) {
      throw new IllegalArgumentException("Invalid 'remote' parameter: " + remote, e);
    }
  }
View Full Code Here

        contentSettings.put("images", 2);

        Map<String, Object> preferences = new HashMap<String, Object>();
        preferences.put("profile.default_content_settings", contentSettings);

        DesiredCapabilities caps = DesiredCapabilities.chrome();
        caps.setCapability("chrome.prefs", preferences);
        caps.setCapability("chrome.switches", Arrays.asList("--user-data-dir=/Users/yihua/temp/chrome"));
        WebDriver webDriver = new ChromeDriver(caps);
        webDriver.get("http://huaban.com/");
        WebElement webElement = webDriver.findElement(By.xpath("/html"));
        System.out.println(webElement.getAttribute("outerHTML"));
        webDriver.close();
View Full Code Here

        this.setGridUrl(gridUrl);
    }

    @Override
    public Browser openBrowser() {
        DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
       
        if (platform != null) {
            desiredCapabilities.setPlatform(platform);
        }
       
        if (browser != null) {
            desiredCapabilities.setBrowserName(browser);
        }
       
        if (browserVersion != null) {
            desiredCapabilities.setVersion(browserVersion);
        }
       
        for (Map.Entry<String, String> dc : this.desiredCapabilities.entrySet()) {
            desiredCapabilities.setCapability(dc.getKey(), dc.getValue());
        }
       
        try {
           
            WebDriver driver = new RemoteWebDriver(new URL(gridUrl), desiredCapabilities);
View Full Code Here

            "key1=value1",
            "key2+=value2",
            "key3=value31", "key3+=value32",
            "key4+=value41", "key4+=value42")));
        DriverOptions driverOptions = new DriverOptions(cli);
        DesiredCapabilities caps = new DesiredCapabilities();
        caps.merge(driverOptions.getCapabilities());
        assertThat((String) caps.getCapability("key1"), is(equalTo("value1")));
        assertThat((String[]) caps.getCapability("key2"), is(arrayContaining("value2")));
        assertThat((String[]) caps.getCapability("key3"), is(arrayContaining("value31", "value32")));
        assertThat((String[]) caps.getCapability("key4"), is(arrayContaining("value41", "value42")));
        assertThat(driverOptions.toString(), is(not("[]")));
    }
View Full Code Here

*/
public class PhantomJSDriverFactory extends WebDriverFactory {

    @Override
    public WebDriver newInstance(DriverOptions driverOptions) {
        DesiredCapabilities caps = setupProxy(DesiredCapabilities.phantomjs(), driverOptions);
        if (driverOptions.has(PHANTOMJS)) {
            File binary = new File(driverOptions.get(PHANTOMJS));
            if (!binary.canExecute())
                throw new IllegalArgumentException("Missing PhantomJS binary: " + binary);
            caps.setCapability(PHANTOMJS_EXECUTABLE_PATH_PROPERTY, binary.getPath());
        }
        caps.merge(driverOptions.getCapabilities());
        if (driverOptions.has(CLI_ARGS)) {
            Object cliArgs = caps.getCapability(PHANTOMJS_CLI_ARGS);
            if (cliArgs == null) {
                cliArgs = ArrayUtils.EMPTY_STRING_ARRAY;
            } else {
                if (cliArgs instanceof String)
                    cliArgs = new String[] { (String) cliArgs };
                else if (!(cliArgs instanceof String[]))
                    throw new IllegalArgumentException("Invalid " + PHANTOMJS_CLI_ARGS + ": " + cliArgs);
            }
            cliArgs = ArrayUtils.addAll((String[]) cliArgs, driverOptions.getCliArgs());
            caps.setCapability(PHANTOMJS_CLI_ARGS, cliArgs);
        }
        PhantomJSDriverService service = CustomPhantomJSDriverServiceFactory.createDefaultService(caps);
        PhantomJSDriver driver = new PhantomJSDriver(service, caps);
        setInitialWindowSize(driver, driverOptions);
        return driver;
View Full Code Here

    @Override
    public WebDriver newInstance(DriverOptions driverOptions) {
        if (!OS.isFamilyWindows())
            throw new UnsupportedOperationException("Unsupported platform: " + Platform.getCurrent());
        DesiredCapabilities caps = setupProxy(DesiredCapabilities.internetExplorer(), driverOptions);
        if (driverOptions.has(IEDRIVER)) {
            String executable = PathUtils.normalize(driverOptions.get(IEDRIVER));
            if (!new File(executable).canExecute())
                throw new IllegalArgumentException("Missing IEDriverServer: " + executable);
            System.setProperty(InternetExplorerDriverService.IE_DRIVER_EXE_PROPERTY, executable);
        }
        InternetExplorerDriverService service = new InternetExplorerDriverService.Builder()
            .usingAnyFreePort()
            .withEnvironment(driverOptions.getEnvVars())
            .build();
        caps.merge(driverOptions.getCapabilities());
        InternetExplorerDriver driver = new InternetExplorerDriver(service, caps);
        setInitialWindowSize(driver, driverOptions);
        return driver;
    }
View Full Code Here

        return false;
    }

    @Override
    public WebDriver newInstance(DriverOptions driverOptions) {
        DesiredCapabilities caps = setupProxy(DesiredCapabilities.safari(), driverOptions);
        caps.merge(driverOptions.getCapabilities());
        SafariDriver driver = new SafariDriver(caps);
        setInitialWindowSize(driver, driverOptions);
        return driver;
    }
View Full Code Here

TOP

Related Classes of org.openqa.selenium.remote.DesiredCapabilities

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.