Attach to a manually opened Chrome browser using debuggerAddress

Problem

Watir-Classic can attach to manually opened browsers. This is a great benefit when using Watir to aid manual testing efforts. It is also helpful when developing automated tests. However, for the longest time, this was not possible with Watir(-Webdriver).

The ChromeOptions page mentions a debuggerAddress option:

An address of a Chrome debugger server to connect to, in the form of , e.g. ‘127.0.0.1:38947’

Can we use this option to attach to manually opened browsers?

Solution

From Issue 710, I was able to attach to a browser using the following steps:

  1. Close all Chrome browsers
  2. Manually start Chrome using chrome.exe --remote-debugging-port=8181 (any port number will do, but it must be used to open the first window)
  3. In the Watir script, initialize the browser using the debuggerAddress option with the same port:
    require 'watir'
    
    browser = Watir::Browser.new(
      :chrome, 
      'chromeOptions' => {'debuggerAddress': '127.0.0.1:8181'})
    

Limitations

Unfortunately, ChromeDriver mentions that there are some limitations. For example, maximizing the browser is not supported:

browser.window.maximize
#=> Selenium::WebDriver::Error::UnknownError: 
#=>   unknown error: operation is unsupported with remote debugging

While I need to investigate which commands are not supported, it looks promising. At least the manual testing scripts tested so far, which include navigation and form filling, work.

Advertisements
This entry was posted in Watir, Watir-Webdriver and tagged , , . Bookmark the permalink.

One Response to Attach to a manually opened Chrome browser using debuggerAddress

  1. joe strain says:

    great piece of info. I’ve missed the ability to attach and debug

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s