Java Code Examples for org.openqa.selenium.remote.DesiredCapabilities#setJavascriptEnabled()

The following examples show how to use org.openqa.selenium.remote.DesiredCapabilities#setJavascriptEnabled() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public static WebDriver getFirefoxDriver(){
    /*
        Need to have an updated Firefox, but also need
        to download and put the geckodriver in your own home dir.
        See:

        https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver
        https://github.com/mozilla/geckodriver/releases

        However, drivers for FireFox have been often unstable.
        Therefore, I do recommend to use Chrome instead
     */

    setupDriverExecutable("geckodriver", "webdriver.gecko.driver");

    DesiredCapabilities desiredCapabilities = DesiredCapabilities.firefox();
    desiredCapabilities.setCapability("marionette", true);
    desiredCapabilities.setJavascriptEnabled(true);

    return  new FirefoxDriver(desiredCapabilities);
}
 
Example 2
public static WebDriver getFirefoxDriver(){
    /*
        Need to have an updated Firefox, but also need
        to download and put the geckodriver in your own home dir.
        See:

        https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver
        https://github.com/mozilla/geckodriver/releases

        However, drivers for FireFox have been often unstable.
        Therefore, I do recommend to use Chrome instead
     */

    setupDriverExecutable("geckodriver", "webdriver.gecko.driver");

    DesiredCapabilities desiredCapabilities = DesiredCapabilities.firefox();
    desiredCapabilities.setCapability("marionette", true);
    desiredCapabilities.setJavascriptEnabled(true);

    return  new FirefoxDriver(desiredCapabilities);
}
 
Example 3
public static WebDriver getFirefoxDriver(){
    /*
        Need to have an updated Firefox, but also need
        to download and put the geckodriver in your own home dir.
        See:

        https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver
        https://github.com/mozilla/geckodriver/releases

        However, drivers for FireFox have been often unstable.
        Therefore, I do recommend to use Chrome instead
     */

    setupDriverExecutable("geckodriver", "webdriver.gecko.driver");

    DesiredCapabilities desiredCapabilities = DesiredCapabilities.firefox();
    desiredCapabilities.setCapability("marionette", true);
    desiredCapabilities.setJavascriptEnabled(true);

    return  new FirefoxDriver(desiredCapabilities);
}
 
Example 4
public static WebDriver getFirefoxDriver(){
    /*
        Need to have an updated Firefox, but also need
        to download and put the geckodriver in your own home dir.
        See:

        https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver
        https://github.com/mozilla/geckodriver/releases

        However, drivers for FireFox have been often unstable.
        Therefore, I do recommend to use Chrome instead
     */

    setupDriverExecutable("geckodriver", "webdriver.gecko.driver");

    DesiredCapabilities desiredCapabilities = DesiredCapabilities.firefox();
    desiredCapabilities.setCapability("marionette", true);
    desiredCapabilities.setJavascriptEnabled(true);

    return  new FirefoxDriver(desiredCapabilities);
}
 
Example 5
Source Project: selenium   File: DriverFactoryTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testShouldConsiderJavascriptCapabilities() {
  DesiredCapabilities nojavascript = new DesiredCapabilities("browser", "v1", Platform.LINUX);
  nojavascript.setJavascriptEnabled(false);
  DesiredCapabilities javascript = new DesiredCapabilities("browser", "v1", Platform.LINUX);
  javascript.setJavascriptEnabled(true);

  DriverProvider nojavascriptProvider = mockDriverProviderFor(nojavascript);
  DriverProvider javascriptProvider = mockDriverProviderFor(javascript);

  factory.registerDriverProvider(nojavascriptProvider);
  factory.registerDriverProvider(javascriptProvider);

  assertEquals(nojavascriptProvider, factory.getProviderMatching(nojavascript));
  assertEquals(javascriptProvider, factory.getProviderMatching(javascript));
}
 
Example 6
Source Project: yuzhouwan   File: HtmlExporterUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
     * 初始化配置 PhantomJS Driver.
     *
     * @param url         目标 URL
     * @param addedCookie 添加 cookie
     * @return 初始化过的 PhantomJS Driver
     */
    public static PhantomJSDriver prepare(String url, Cookie addedCookie, Integer width, Integer height) {
        // chrome driver maybe not necessary
        // download from https://sites.google.com/a/chromium.org/chromedriver/downloads
//        System.setProperty("webdriver.chrome.driver",
//                DirUtils.RESOURCES_PATH.concat(
//                        PropUtils.getInstance().getProperty("html.exporter.webdriver.chrome.driver")));

        DesiredCapabilities phantomCaps = DesiredCapabilities.chrome();
        phantomCaps.setJavascriptEnabled(true);
        PropUtils p = PropUtils.getInstance();
        phantomCaps.setCapability("phantomjs.page.settings.userAgent",
                p.getProperty("html.exporter.user.agent"));

        PhantomJSDriver driver = new PhantomJSDriver(phantomCaps);
        driver.manage().timeouts().implicitlyWait(Integer.parseInt(
                p.getProperty("html.exporter.driver.timeouts.implicitly.seconds")), TimeUnit.SECONDS);
        driver.manage().timeouts().pageLoadTimeout(Integer.parseInt(
                p.getProperty("html.exporter.driver.timeouts.page.load.seconds")), TimeUnit.SECONDS);
        driver.manage().timeouts().setScriptTimeout(Integer.parseInt(
                p.getProperty("html.exporter.driver.timeouts.script.seconds")), TimeUnit.SECONDS);

        if (width == null || height == null) driver.manage().window().maximize();
        else driver.manage().window().setSize(new Dimension(width, height));

        if (addedCookie != null) driver.manage().addCookie(addedCookie);

        driver.get(url);
//        try {
//            // timeout is not work, so fix it by sleeping thread
//            Thread.sleep(Integer.valueOf(PropUtils.getInstance()
//                    .getProperty("html.exporter.driver.timeouts.implicitly.seconds")) * 1000);
//        } catch (InterruptedException e) {
//            throw new RuntimeException(e);
//        }
        return driver;
    }
 
Example 7
Source Project: carina   File: HTMLUnitCapabilities.java    License: Apache License 2.0 5 votes vote down vote up
public DesiredCapabilities getCapability(String testName) {
    DesiredCapabilities capabilities = DesiredCapabilities.htmlUnit();
    String platform = Configuration.getPlatform();
    if (!platform.equals("*")) {
        capabilities.setPlatform(Platform.extractFromSysProperty(platform));
    }
    capabilities.setJavascriptEnabled(true);
    return capabilities;
}
 
Example 8
Source Project: selenium   File: JsonTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void shouldProperlyFillInACapabilitiesObject() {
  DesiredCapabilities capabilities =
      new DesiredCapabilities("browser", CapabilityType.VERSION, Platform.ANY);
  capabilities.setJavascriptEnabled(true);
  String text = new Json().toJson(capabilities);

  Capabilities readCapabilities = new Json().toType(text, DesiredCapabilities.class);

  assertThat(readCapabilities).isEqualTo(capabilities);
}
 
Example 9
Source Project: windup   File: TestReportUtil.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public TestReportUtil()
{
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setBrowserName("firefox");
    capabilities.setJavascriptEnabled(true);
    this.driver = new WindupHtmlUnitDriver(capabilities);
}
 
Example 10
public Capabilities getChromeCapabilities() {
	ChromeOptions option = new ChromeOptions();
	option.addArguments("start-maximized");
	DesiredCapabilities chrome = DesiredCapabilities.chrome();
	chrome.setJavascriptEnabled(true);
	chrome.setCapability(ChromeOptions.CAPABILITY, option);
	return chrome;
}
 
Example 11
Source Project: mamute   File: AcceptanceTestBase.java    License: Apache License 2.0 5 votes vote down vote up
private static WebDriver ghostDriver() {
	DesiredCapabilities capabilities = new DesiredCapabilities();
	capabilities.setJavascriptEnabled(true);
	capabilities.setCapability("takesScreenshot", true);
	try {
		return new RemoteWebDriver(new URL("http://localhost:8787/"),
				capabilities);
	} catch (MalformedURLException e) {
		throw new RuntimeException("could not build ghost driver", e);
	}
}
 
Example 12
private WebDriver webDriver() {
    final ChromeOptions chromeOptions = new ChromeOptions();
    chromeOptions.setBinary(System.getProperty("google.chrome"));
    chromeOptions.addArguments("--headless");
    chromeOptions.addArguments("--disable-gpu");
    final DesiredCapabilities dc = new DesiredCapabilities();
    dc.setJavascriptEnabled(true);
    dc.setCapability(
        ChromeOptions.CAPABILITY, chromeOptions
    );
    return new ChromeDriver(dc);
}
 
Example 13
Source Project: selenium   File: DriverFactoryTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testShouldReturnDriverWhereTheMostCapabilitiesMatch_lotsOfRegisteredDrivers() {
  DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
  desiredCapabilities.setBrowserName(FIREFOX);
  desiredCapabilities.setVersion("");
  desiredCapabilities.setJavascriptEnabled(true);
  desiredCapabilities.setPlatform(Platform.ANY);

  assertEquals(FIREFOX, factory.getProviderMatching(desiredCapabilities)
      .getProvidedCapabilities().getBrowserName());
}
 
Example 14
private WebDriver webDriver() {
	final ChromeOptions chromeOptions = new ChromeOptions();
    chromeOptions.setBinary(System.getProperty("google.chrome"));
    chromeOptions.addArguments("--headless");
    chromeOptions.addArguments("--disable-gpu");
    final DesiredCapabilities dc = new DesiredCapabilities();
    dc.setJavascriptEnabled(true);
    dc.setCapability(
        ChromeOptions.CAPABILITY, chromeOptions
    );
    return new ChromeDriver(dc);

}
 
Example 15
public DesiredCapabilities createCapabilities(final DriverConfig cfg) {
    DesiredCapabilities capability = null;
    capability = DesiredCapabilities.safari();

    if (cfg.isEnableJavascript()) {
        capability.setJavascriptEnabled(true);
    } else {
        capability.setJavascriptEnabled(false);
    }

    capability.setCapability(CapabilityType.TAKES_SCREENSHOT, true);
    capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);

    if (cfg.getBrowserVersion() != null) {
        capability.setVersion(cfg.getBrowserVersion());
    }

    if (cfg.getWebPlatform() != null) {
        capability.setPlatform(cfg.getWebPlatform());
    }

    if (cfg.getProxyHost() != null) {
        Proxy proxy = cfg.getProxy();
        capability.setCapability(CapabilityType.PROXY, proxy);
    }

    return capability;
}
 
Example 16
/**
 * 
 * @param config
 * @return A FirefoxDriver.
 */
@Override
public RemoteWebDriver make(HashMap<String, String> config) {
    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setJavascriptEnabled(true);
    if (System.getProperty(PHANTOMJS_PATH_PROPERTY) != null) {
        path = System.getProperty(PHANTOMJS_PATH_PROPERTY);
    }
    caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
                    path);
    return new PhantomJSDriver(caps);
}
 
Example 17
public Capabilities getPhantomJsCapability() {
	DesiredCapabilities cap = DesiredCapabilities.phantomjs();
	cap.setJavascriptEnabled(true);
	return cap;
}
 
Example 18
private static Capabilities capabilities(String browserName, String version,
    Platform platform, boolean isJavaScriptEnabled) {
  DesiredCapabilities dc = new DesiredCapabilities(browserName, version, platform);
  dc.setJavascriptEnabled(isJavaScriptEnabled);
  return dc;
}
 
Example 19
public DesiredCapabilities createCapabilities(final DriverConfig cfg) {

        // Set IEDriver for Local Mode
        if (cfg.getMode() == DriverMode.LOCAL) {
            if (cfg.getIeDriverPath() != null) {
                System.setProperty("webdriver.ie.driver", cfg.getIeDriverPath());
            } else {
                if (System.getenv("webdriver.ie.driver") != null) {
                    System.out.println("Get IE Driver from property:" + System.getenv("webdriver.ie.driver"));
                    System.setProperty("webdriver.ie.driver", System.getenv("webdriver.ie.driver"));
                } else {
                    try {
                        handleExtractResources();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }

        }

        DesiredCapabilities capability = DesiredCapabilities.internetExplorer();

        capability.setBrowserName(DesiredCapabilities.internetExplorer().getBrowserName());

        if (cfg.isEnableJavascript()) {
            capability.setJavascriptEnabled(true);
        } else {
            capability.setJavascriptEnabled(false);
        }

        capability.setCapability(CapabilityType.TAKES_SCREENSHOT, true);
        capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
        capability.setCapability("ignoreZoomSetting", true);

        if (cfg.getBrowserVersion() != null) {
            capability.setVersion(cfg.getBrowserVersion());
        }

        if (cfg.getWebPlatform() != null) {
            capability.setPlatform(cfg.getWebPlatform());
        }

        if (cfg.getProxyHost() != null) {
            Proxy proxy = cfg.getProxy();
            capability.setCapability(CapabilityType.PROXY, proxy);
        }

        capability.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
        return capability;
    }
 
Example 20
Source Project: caja   File: WebDriverHandle.java    License: Apache License 2.0 4 votes vote down vote up
private static RemoteWebDriver makeDriver() {
  DesiredCapabilities dc = new DesiredCapabilities();

  String browserType = TestFlag.BROWSER.getString("firefox");

  if ("chrome".equals(browserType)) {
    // Chrome driver is odd in that the path to Chrome is specified
    // by a desiredCapability when you start a session. The other
    // browser drivers will read a java system property on start.
    // This applies to both remote Chrome and local Chrome.
    ChromeOptions chromeOpts = new ChromeOptions();
    String chromeBin = TestFlag.CHROME_BINARY.getString(null);
    if (chromeBin != null) {
      chromeOpts.setBinary(chromeBin);
    }
    String chromeArgs = TestFlag.CHROME_ARGS.getString(null);
    if (chromeArgs != null) {
      String[] args = chromeArgs.split(";");
      chromeOpts.addArguments(args);
    }
    dc.setCapability(ChromeOptions.CAPABILITY, chromeOpts);
  }

  String url = TestFlag.WEBDRIVER_URL.getString("");

  if (!"".equals(url)) {
    dc.setBrowserName(browserType);
    dc.setJavascriptEnabled(true);
    try {
      return new RemoteWebDriver(new URL(url), dc);
    } catch (MalformedURLException e) {
      throw new RuntimeException(e);
    }
  } else if ("chrome".equals(browserType)) {
    return new ChromeDriver(dc);
  } else if ("firefox".equals(browserType)) {
    return new FirefoxDriver();
  } else if ("safari".equals(browserType)) {
    // TODO(felix8a): local safari doesn't work yet
    return new SafariDriver();
  } else {
    throw new RuntimeException("No local driver for browser type '"
        + browserType + "'");
  }
}