There are different ways to close browser[s] using selenium after tests are run.
Depending on scenarios, if single or multiple browsers are opened, we can close or quit browser.
let’s see the usage of close, quit and dispose methods.
driver.close() method will close current browser / browser window, that is in focus or hold by the driver (driver means WebDriver driver).
If there are more than one browser opened, let’s say we click on a link and browser opened in a new window, and we need to close all the browsers that are opened by the driver instance, then use driver.quit().
driver.quit() / driver.dispose()
this method basically calls the dispose() method, to close all the browsers [including browser windows] that are opened by the driver instance and to dispose the driver object itself to safely end the session.
Note:
Whether single or multiple browser windows opened, it’s better to use driver.quit() always to avoid memory leakage, else driver session files would not remove from hard disc.