Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
404 views
in Technique[技术] by (71.8m points)

c# - Specify PhantomJS command line optionsto Selenium PhantomJSDriver

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...