Reputation: 1
I'm trying to implement WebDriverManager to my integration testing. When I'm trying to debug tests, I don't want the driver to quit immediately after failing so I can interact with the webpage and figure out what went wrong. I added .avoidShutdownHook()
to my chromedriver, but the browser is closing anyway. I'm using Selenium 4.0.0 and Chromedriver 120.
I made sure my teardown method doesn't have driver.quit()
in it (it's commented out). I tried a test I knew would pass and one I knew would fail in case I didn't understand that it would always quit on fail or something. Both always quit, regardless of the shutdown hook. I don't want to use the screenshot or recording aspect because I want to be able to just inspect element right on that page, and it takes a lot of setup to get back to that spot sometimes.
Here's how my driver is setup:
WebDriverManager.chromedriver().setup();
Main.main(new String[]{"standalone", "--port", Integer.toString(remotePort)});
driver = WebDriverManager.chromedriver()
.remoteAddress("http://" + remoteServer + ":" + remotePort + "/wd/hub")
.capabilities(options)
.avoidShutdownHook()
.create();
Upvotes: 0
Views: 80
Reputation: 4858
The problem here is not WebDriverManager. Since you are starting Selenium Grid programmatically, once it is closed (on JVM's shutdown), it closes all the sessions. You can see it in the traces:
10:56:33.229 INFO [LocalNode.stopAllSessions] - Trying to stop all running sessions before shutting down...
You can check that avoidShutdownHook()
works as expected by starting manually a selenium server (e.g., java -jar selenium-server-4.17.0.jar standalone
) and using the local URL (http://localhost:4444) for remoteAddress
.
Upvotes: 0
Reputation: 45
For Chrome, use the option- options.add_experimental_option("detach", True);
This detaches the chromedriver from the browser session after the test has run, and keeps the window open.
In Firefox and Edge the default behaviour is to keep windows open after the test.
If including the option doesn't work, then make sure that you're not calling the quit command driver.Quit();
Upvotes: 0