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

The following examples show how to use org.openqa.selenium.remote.DesiredCapabilities#setJavascriptEnabled() . 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
Source File: SeleniumDriverHandler.java    From testing_security_development_enterprise_systems with GNU Lesser General Public License v3.0 6 votes vote down vote up
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
Source File: SeleniumDriverHandler.java    From testing_security_development_enterprise_systems with GNU Lesser General Public License v3.0 6 votes vote down vote up
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
Source File: SeleniumDriverHandler.java    From testing_security_development_enterprise_systems with GNU Lesser General Public License v3.0 6 votes vote down vote up
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
Source File: SeleniumDriverHandler.java    From testing_security_development_enterprise_systems with GNU Lesser General Public License v3.0 6 votes vote down vote up
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 File: DriverFactoryTest.java    From selenium with 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 File: AcceptanceTestBase.java    From mamute with 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 7
Source File: PhantomJsFactory.java    From Asqatasun with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 
 * @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 8
Source File: SafariCapabilitiesFactory.java    From seleniumtestsframework with Apache License 2.0 5 votes vote down vote up
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 9
Source File: SitemapXmlCrawlITCase.java    From charles with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 10
Source File: DriverFactoryTest.java    From selenium with 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 11
Source File: GraphCrawlITCase.java    From charles with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 12
Source File: HtmlExporterUtils.java    From yuzhouwan with 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 13
Source File: ChromeBrowser.java    From SeleniumCucumber with GNU General Public License v3.0 5 votes vote down vote up
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 14
Source File: TestReportUtil.java    From windup with 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 15
Source File: JsonTest.java    From selenium with 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 16
Source File: HTMLUnitCapabilities.java    From carina with 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 17
Source File: PhantomJsBrowser.java    From SeleniumCucumber with GNU General Public License v3.0 4 votes vote down vote up
public Capabilities getPhantomJsCapability() {
	DesiredCapabilities cap = DesiredCapabilities.phantomjs();
	cap.setJavascriptEnabled(true);
	return cap;
}
 
Example 18
Source File: CapabilitiesComparatorTest.java    From selenium with Apache License 2.0 4 votes vote down vote up
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
Source File: IECapabilitiesFactory.java    From seleniumtestsframework with Apache License 2.0 4 votes vote down vote up
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 File: WebDriverHandle.java    From caja with 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 + "'");
  }
}