Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why won't PhantomJSDriver use the capabilities I set?

I'm setting some capabilities for PhantomJsDriver.

DesiredCapabilities caps = new DesiredCapabilities();
caps.setJavascriptEnabled(true);
caps.setCapability("cssSelectorsEnabled", false);
caps.setCapability("applicationCacheEnabled", true);
caps.setCapability("acceptSslCerts",true);
caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,phantomJsPath); 
this.driver = new PhantomJSDriver(caps);

Then, I check what capabilities the driver is using:

System.out.println(driver.getCapabilities());

Output:

Capabilities [{
platform=XP, 
acceptSslCerts=false, 
javascriptEnabled=true, 
browserName=phantomjs,
rotatable=false,
driverVersion=1.1.0, 
locationContextEnabled=false, 
version=1.9.7, 
cssSelectorsEnabled=true, 
databaseEnabled=false, 
handlesAlerts=false, 
browserConnectionEnabled=false, 
proxy={proxyType=direct}, 
nativeEvents=true, 
webStorageEnabled=false, 
driverName=ghostdriver, 
applicationCacheEnabled=false, 
takesScreenshot=true}]

It shows:

cssSelectorsEnabled=true, 
applicationCacheEnabled=false,
acceptSslCerts=false

Why is the driver running without the capabilities I set?

like image 424
Kerem356 Avatar asked Mar 07 '14 10:03

Kerem356


2 Answers

PhantomJS uses different mechanism in setting capabilities

static ArrayList<String> cliArgsCap = new ArrayList<String>();
capabilities = DesiredCapabilities.phantomjs();
cliArgsCap.add("--web-security=false");
cliArgsCap.add("--ssl-protocol=any");
cliArgsCap.add("--ignore-ssl-errors=true");
capabilities.setCapability("takesScreenshot", true);
capabilities.setCapability(
    PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cliArgsCap);
capabilities.setCapability(
    PhantomJSDriverService.PHANTOMJS_GHOSTDRIVER_CLI_ARGS,
        new String[] { "--logLevel=2" });
this.driver = new PhantomJSDriver(capabilities);

For more information about its command line, you could reference http://phantomjs.org/api/command-line.html

like image 143
Nguyen Vu Hoang Avatar answered Sep 19 '22 13:09

Nguyen Vu Hoang


With phantomjsdriver-1.1 I had to pass the follow arguments to get this to work.

cliArgsCap.add("--web-security=no");
cliArgsCap.add("--ignore-ssl-errors=yes");
like image 35
Jules Clements Avatar answered Sep 19 '22 13:09

Jules Clements