How to launch Chrome remotely with arguments?

311 views
Skip to first unread message

Chris Merrill

unread,
Nov 1, 2013, 11:15:45 AM11/1/13
to webd...@googlegroups.com
I'm trying to modify one part of our framework that launches Chrome like this:

ChromeOptions options = new ChromeOptions();
options.addArguments("-incognito");
options.addArguments("--user-data-dir=");
ChromeDriver driver = new ChromeDriver(new ChromeDriverService.Builder().usingDriverExecutable(new
File(DRIVER_LOCATION)).usingAnyFreePort().build(), options);


Instead, I want to use an instance of the ChromeDriver service that is already running,
using a RemoteWebDriver.

I'm doing this:
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("chrome.switches", Arrays.asList("-incognito", "--user-data-dir="));
//caps.setCapability("args", Arrays.asList("-incognito", "--user-data-dir="));
RemoteWebDriver driver = new RemoteWebDriver(new URL(DRIVER_ADDRESS), caps);

Chrome launches fine and seems to functional, but the arguments are not passed to
the command line. I can see this in the UI (incognito icon missing) and also
verified the command-line params using ProcessExplorer. I'm running on Win7,
if it matters.


Is there some other way I should be going about this?



For purposes of this discussion, please ignore the specific arguments in this
example - I'm trying to determine how to do this for any set of Chrome arguments.

Chris


--
------------------------------------------------------------------------ -
Chris Merrill | Web Performance, Inc.
ch...@webperformance.com | http://webperformance.com
919-433-1762 | 919-845-7601

Web Performance: Website Load Testing Software & Services
------------------------------------------------------------------------ -

Chris Merrill

unread,
Nov 1, 2013, 3:04:46 PM11/1/13
to webd...@googlegroups.com
After perusing the ChromeDriverService sources, I've been able to partially answer
this myself. The ChromeOptions class has a toCapabilities() method that would
let me replace

ChromeDriver driver = new ChromeDriver(new ChromeDriverService.Builder().usingDriverExecutable(new
File(DRIVER_LOCATION)).usingAnyFreePort().build(), options);

with

RemoteWebDriver driver = new RemoteWebDriver(new URL(DRIVER_ADDRESS), options.toCapabilities());

Unfortunately, for reasons that are not at all obvious to me, the toCapabilities() method
in ChromeOptions requires package access...which prevents this usage.

But I can duplicate the critical parts of the code in that protected method like this:

DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
RemoteWebDriver driver = new RemoteWebDriver(new URL(DRIVER_ADDRESS), capabilities);


Problem solved - arguments are passed to Chrome as required when connecting to an
already-running instance of ChromeDriver.exe via a RemoteWebDriver.


But my original question remains - is this the recommended way to do this? Seems like
this usage of ChromeOptions and Capabilities is less obvious than one might expect.



Chris

Krishnan Mahadevan

unread,
Dec 20, 2013, 4:08:12 AM12/20/13
to webdriver
You mean something like this ?

ChromeOptions options = new ChromeOptions();
options.addArguments("--ignore-certificate-errors");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/


--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webdriver+...@googlegroups.com.
To post to this group, send email to webd...@googlegroups.com.
Visit this group at http://groups.google.com/group/webdriver.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages