Search code examples
javaseleniumselenium-webdriverwebdrivermanager-java

Why does browser closes automatically when latest version of WebDriverManager (5 onward) is used, is its new feature?


I recently created a new Selenium Maven project using the latest version(5.2.1) of WebDriverManager but I found that without using driver.quit() or driver.close() method, the browser closed automatically after test execution, is it a new feature of WebDriverManager (5 onward)?


Solution

  • As explained in the WebDriverManager doc, when you use the method create() for building WebDriver objects, WebDriverManager includes a shutdown hook that watches these objects correctly released before shutting down the JVM. If you want to avoid this behavior, you can use the method avoidShutdownHook(), for instance as follows:

    WebDriver driver = WebDriverManager.chromedriver().avoidShutdownHook().create();