What's new
Tiêu Dật Tài / Forum

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Connect Selenium Driver to an Existing Chrome Browser Instance

tieudattai

Administrator
Staff member
During my internship at Sysco LABS (pvt) Ltd., I came across a requirement in a test automation project to automate tests on reports generated by an Oracle Forms Application. The Oracle Forms Application was run using Java Web Start Client and therefore the reports were opened in the default web browser set in the operating system once generated.

The solution which was proposed to overcome this challenge was to take advantage of Remote Debugging Mode available in Chrome web browser.

Remote Debugging is a concept which is particularly helpful when debugging a program developed for a device that cannot host the development platform. Another instance that remote debugging is helpful is when debugging applications on dedicated devices such as servers.

In our case, remote debugging was helpful as once Chrome is opened in remote debugging mode, we could connect a new Selenium Chrome Driver to that existing Chrome instance. The plan was to have Chrome running before generating the report and once report is opened in the browser to connect a Chrome Driver instance to the existing browser and run tests.

How?
Prerequisites
  1. Chrome Browser — Version 63 or higher
  2. Add Chrome Browser installation directory to Path variable (if you are using windows) — although this is not a necessity, it would be preferable as it would allow to open chrome browser from any directory using terminal/command prompt.
  3. Make Chrome Browser the default web browser (optional) — this was a special prerequisite in our case as the report will be opened in Chrome browser opened in remote debugging mode only if Chrome is the default web browser and it’s the only chrome instance running.
Steps
Once you have satisfied the prerequisites mentioned above you can follow the steps below to successfully connect a new selenium Chrome Driver instance to an existing Chrome web browser instance.

  1. Open a new Chrome Browser instance in remote debugging mode using terminal/ command prompt using one of the following commands.
/Ubuntu/
google-chrome --remote-debugging-port=<remote-port>/Windows/
chrome --remote-debugging-port=<remote-port>
In the both commands replace <remote-port> with a four digit port number which you are not using currently for any other application. — user-data-dir=<dir> can be added to the end of the above commands to start Chrome browser using a new profile.

2. Navigate to your test framework in your favorite IDE and set system property (in Java) webdriver.chrome.driver pointing to the chrome driver.

Ex :

/Ubuntu/
System.setProperty("webdriver.chrome.driver", "<path-to-chrome-driver>/chromedriver");/Windows/
System.setProperty("webdriver.chrome.driver", "<path-to-chrome-driver>/chromedriver.exe");
3. Initialize Chrome Driver as follows. (example code is provided in Java programming language)


Now you are good to go. You can run automated tests using the Chrome Driver we just initialized.

In our case, after opening Chrome browser and before initiating Chrome Driver we ran the UI tests in Oracle Forms Application and captured generated report links in the opened Chrome Browser instance.

Conclusion
Remote Debugging Mode available in Chrome browser version 63 or higher can be used to connect a new Chrome Driver to an existing Chrome browser and run automated tests in that already opened Chrome browser.

The steps to open Chrome browser can also be implemented within the test framework as otherwise it has to be done manually which is not feasible when running a test automation suit. I will be writing a separate article on implementation details on that to avoid this article being too long.
 
Top