Search This Blog

Breaking

Wednesday, 16 June 2021

Execute Selenium Script in Already Open browser [Windows]

 This is a part of my learning series where recent ally I read an article about how to execute selenium script in an already open browser. This is needed when some of our test cases get fails and we put a fix. When we want to test that fix, then our script starts from scratch and this process becomes tedious when our fix doesn't work and we again and again put our fixes. A lot of time spends in unnecessary execution of same steps which are already working.

So, to avoid this situation, and to run our execution exactly from where it's failing, we can use chrome browser native debugging option. 

What we need to do to achieve this is, we need to launch our chrome in debugging mode. Below are the steps which we can follow to achieve this:













1. Find the chorome.exe in your machine. In my case, it is in, C:\Program Files\Google\Chrome\Application.

2. Create a directory in your machine. I created C:\Users\deepak.mathpal\Documents\chromedata

3. Now run this command.

C:\Program Files\Google\Chrome\Application>chrome.exe --remote-debugging-port=9222 --user-data-dir=C:\Users\deepak.mathpal\Documents\chromedata

4. It will open a new chrome browser, where we can debug our fix.

5. Now in your automation script, put a option in your chromedriver for debugging.

 options.setExperimentalOption("debuggerAddress", "localhost:9222");

6. Provide this option to your chromedriver.

In My case, it was something like this:

capabilities.setCapability(ChromeOptions.CAPABILITY, options);

 System.setProperty("webdriver.chrome.driver", chromeDriverPath);

  driver = new ChromeDriver(capabilities);

7. Now when you will run your script it will run in this alredy open browser.


Note: Port number, directory location is optional.

References: 

1. https://chromedevtools.github.io/devtools-protocol/

2. https://www.youtube.com/watch?v=Rrkj4tdXngY




No comments:

Post a Comment