What are the Scenarios When Remote Debugging In Required In Selenium WebDriver?
In Automation, We have plenty of scenarios where remote debugging is required but listing some of the scenario here and remaining if you like to mention you can add in comment to improved this scenario list.
1- Let’s say multiple team members are working to automate an end to end-user workflow, you are automating one or two pages in the end to end automation and you don’t have the complete script. In such a scenario, you can navigate to the page assigned to you, manually, from there you can continue with your automation script.
2- If captcha is implemented with some login credential that you don’t want to expose to anyone. In such scenario you can setup your login process manually and handover the session to automation script to use the same browser session.
3- If application hybrid where some of the part is coming from some API or desktop application and remaining part is web page which can be handled through Selenium.
4- What if some application is failing on end user mobile application and you want to deal with this scenario. In this case you can ask end user to share the browser session or application session using remote debugger address feature provided in chrome.
5- What if some click action is not working properly and you need to do manual intervention.
How to launch a chrome browser with a remote debugger address?
To launch a chrome browser in remote debug mode, you need to follow these steps.
1- Navigate to chrome.exe path through command line.
2- Type following line of code on command line.
Let’s understand the parts of the above command
- chrome.exe: Chrome Browser Binary ( This is will different in all other operating systems like Unix, Mac, Linux)
- –remote-debugging-port: This is Chrome Preference to launch the browser in remote debug mode on a certain port, We can also use –remote-debugging-address.
- –user-date-dir: this is a directory where the browser stores the user profile, So we should always provide a new profile directory to save your default browser profile preferences.
3- Navigate to the page where you want to start your debugging.
4- In browser, type <machine ip>:9222.
This will open the page on your machine using remote debugging mode.
How to Connect Selenium To Existing Chrome Browser?
In Selenium, ChromeOptions are used to interact with already open chrome browser in remote debug mode.
line of code used
1- Open the Command line and run this command on windows machine
chrome.exe –remote-debugging-port=9222 –user-data-dir=”D:\selenium\RemoteProfile”
2- In the newly launched browser, Open https://abodeqa.com
3- Click on Contact Us Page.
4- Get back to the selenium script and run it. ( I have already written one code which will enter text in all the field on contact us page.)
Here is the complete code:
Above code will use the same chrome session, which is launched using step 1 and continue from step 4.