Ben
Ben

Reputation: 173

Starting Google Chrome from Watir-WebDriver with the Remote Debugging Port Argument?

Hopefully this is a simple question, but I'm looking to pass the argument "--remote-debugging-port=9222" to a browser I instantiate using Watir-WebDriver on my Ubuntu box. I'm using ChromeDriver 2.9 and Google Chrome 32.

This is how I'd normally approach this :

b = Watir::Browser.new :chrome, :switches => %w[--remote-debugging-port=9222]
b.close

The weird thing is that the browser does open to a blank page. After about 30 seconds, the browser instance is closed - presumably because a connection cannot be made between ChromeDriver and Google Chrome.

Just as a precaution, I ran some preliminary tests. I'm able to start up a Chrome browser instance without any arguments using Watir-WebDriver with no problem. Additionally, I'm also able to start up Google Chrome from the command line using the --remote-debugging-port argument. So I know by default, Watir-WebDriver and Google Chrome is functioning correctly, leading me to believe that I'm incorrectly specifying my arguments.

Any suggestions as to what might be going wrong here?

Upvotes: 2

Views: 1969

Answers (2)

Antesser
Antesser

Reputation: 669

You can try

browser = Watir::Browser.new(
  :chrome, 
  'chromeOptions' => {'debuggerAddress': '127.0.0.1:9222'})

This will force chrome to use port 9222 for debugger

Upvotes: 0

Ben
Ben

Reputation: 173

As a follow up to this question I posted a while ago - turns out Chromedriver establishes a connection to the browser via the remote debugging port.

Attempting to override this will prevent chromedriver from communicating with the browser, causing it to timeout thereby stopping any automation I'd like to perform in its tracks.

EXTRA INFO BELOW

I managed to get around the need to attach to the remote debugging port of the browser to accomplish what I was trying to do. In case anyone is interested, I was trying to attach to the remote debugging port to capture browser level activity. Thankfully, chromedriver will collect all of the network panel information via logs that you can access either by REST API or from within your automation script.

To enable this logging, you'll need to pass some arguments to webdriver. This is how I currently do it :

caps = Selenium::WebDriver::Remote::Capabilities.chrome("loggingPrefs"=>{"browser"=>"ALL", "performance"=>"ALL"})
driver = Selenium::WebDriver.for :remote, :url => 'http://localhost:4444/wd/hub', :desired_capabilities => caps
b = Watir::Browser.new driver

Then to retrieve the logs from within your automation script, do the following :

b.driver.manage.logs.get "browser"

Just to note, there are several different types of logs you can capture, with varying levels of verbosity. Here's a few log types :

  1. "performance" captures the timeline and network panel events
  2. "browser" captures browser-level data
  3. "driver" captures driver-level data.

Hope someone else is able to use this information to their advantage!

Upvotes: 3

Related Questions