1

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)?

Boni García
  • 4,618
  • 5
  • 28
  • 44
user2044296
  • 504
  • 1
  • 7
  • 18

1 Answers1

2

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();
Boni García
  • 4,618
  • 5
  • 28
  • 44
  • Thanks for the response, so considering this shutdown hook I will not need a tearDown() method (@AfterMethod in TestNg) to quit the driver if I haven't avoided it, right? – user2044296 Jul 11 '22 at 08:10
  • 1
    When using WebDriverManager's `create()` method, yes, you can relay in WebDriverManager to close browsers gracefully. – Boni García Jul 12 '22 at 08:22