Does the PhantomJS driver support command line arguments? I need to run Selenium tests with the PhantomJS driver and disable web security. I have tried:
PhantomJSOptions options = new PhantomJSOptions();
options.AddAdditionalCapability("web-security",false);
driver = new PhantomJSDriver(Environment.CurrentDirectory + @"\drivers", options);
but this does not seem to work. Does the PhantomJSDriver allow for passing command line arguments?
You can specify PhantomJS' --web-security
command line options using PhantomJSDriverService.WebSecurity Property, rather than pass it as PhantomJSOptions
.
This is added in Selenium 2.32.0, a quote from CHANGELOG:
(on behalf of GeoffMcElhanon) Added support to pass arguments to
PhantomJS. The PhantomJSDriverService now has type-safe properties
for all of the command-line switches supported by PhantomJS. These
can be passed directly on the command line, or can be serialized
into a JSON file for passing with the --config command line switch
to PhantomJS.
Below is the untested code, please refer to the documentation (the WebDriver.chm in your Selenium zip file) when necessary.
var service = PhantomJSDriverService.CreateDefaultService(Environment.CurrentDirectory + @"\drivers");
service.WebSecurity = false;
var driver = new PhantomJSDriver(service);
PhantomJSDriverService
has other pre-defined command line arguments one can specify, please check documentation. Also
there are methods to add your own arguments.
AddArgument(): Adds a single argument to the list of arguments to be appended to the PhantomJS.exe command line.
AddArguments(IEnumerable): Adds arguments to be appended to the PhantomJS.exe command line.
AddArguments(String[]): Adds arguments to be appended to the PhantomJS.exe command line.