Is it possible somehow to reuse already opened browser while operating in selenium webdriver?


Q: Is it possible somehow to reuse already opened browser while operating in selenium webdriver?

As far as I know selenium webdriver has no inbuilt feature that would allow to maintain/reuse already opened browser. Every time to see the code changes you have to run a test from scratch in a new browser session and it is kind of torment to wait till the actual test is executed

I use TestNG/java while creating tests. My level of automation is novice. I would appreciate if you could highlight this topic in one of your chapters dedicated to selenium webdriver

It would be nice if you could provide step-by-step instructions (code) how to implement this for those who have basic knowledge of all required technologies: Java, TestNG and etc.

Thank you in advance!


Petr Default Asked on October 2, 2015 in Selenium WebDriver.
Add Comment
1 Answer(s)

Basically if you want to use the same driver through the session dont call driver.quit or close on it. Also make sure that the same driver object that you create is passed around to different tests. It is a broad question that you have asked and it has many possible solutions.

I would suggest that you create a browser factory which delivers you browsers on demand. In the factory make sure that you maintain the same instance of the browser.

I think I had posted the code earlier once. Let me see and come back to this again, However you can take a look at Factory Design pattern here


Virender Singh Professor Answered on October 5, 2015.

Thanks for your response, Virender

Indeed my initial question was too general, let me make it more certain.
The main problem for me is debugging of my tests.
I have to run a new browser session everytime I need to see my code changes because webdriver creates a new instance of the browser. In my case:
driver = new ChromeDriver();
My intention: run my debugged test on the same browser page where I suspended last time without starting a new session.
I need webdriver to pick up already opened browser window to run the debugged test


on October 5, 2015.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.