1

When running plain PhantomJS a config.json can be set which sets some options. How I can setup PhantomJS with JSON file when using the Selenium WebDriver?

I have this:

DesiredCapabilities caps = new DesiredCapabilities();
caps.setJavascriptEnabled(true);
caps.setCapability("takesScreenshot", false);
caps.setCapability(
        PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
         "/usr/local/bin/phantomjs");
driver = new PhantomJSDriver(caps);
1
  • i see here:phantomjs.org/api/command-line.html that i can configure phantomjs driver with json..but i not understand how i can this in java Commented Mar 13, 2015 at 16:27

1 Answer 1

2

In plain PhantomJS a --config=config.json commandline option can be specified when running it as seen here. The same can be specified when invoking PhantomJS through the selenium webdriver by passing this commandline option through the capabilities:

ArrayList<String> cliArgsCap = new ArrayList<String>();
cliArgsCap.add("--config=config.json");
DesiredCapabilities capabilities = DesiredCapabilities.phantomjs();
capabilities.setCapability(
    PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cliArgsCap);
capabilities.setCapability("takesScreenshot", false);
capabilities.setCapability(
    PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
     "/usr/local/bin/phantomjs");
WebDriver driver = new PhantomJSDriver(capabilities);

This is adapted from my answer here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.