Selenium + Java · Lesson 15 of 44

0/44 done

Module 15: Selenium Setup

15. Maven Configuration, Browser Launching & quit() vs close()

14 minlesson

Your task

Implement safeQuitDriver:

  1. Accept WebDriver driver.
  2. If driver != null, call driver.quit().

Write it in the editor, then press Check answer (Ctrl + Enter).

Maven Dependency (pom.xml)

xml
<dependency>
    <groupId>org.openqa.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>4.26.0</version>
</dependency>

quit() vs close()

  • driver.close(): Closes the currently active browser window. If other tabs remain open, the driver session stays active.
  • driver.quit(): Terminates the entire WebDriver session, kills the browser process, and frees OS memory. Always use in @AfterEach!

Key Takeaways & Walkthrough Summary

In this lesson, we configure the Maven pom.xml with selenium-java, launch Chrome, Firefox, and Edge, and understand the critical difference between driver.close() and driver.quit(). Let's dive in!

Part of the Selenium + Java course (Selenium with Java). Practice this concept live in the Selenium Online Compiler or explore our free automation practice form.

Common Doubts & Lesson Q&A

What happens if I forget to call driver.quit()?

Orphaned chromedriver.exe and browser processes remain in memory, quickly consuming all RAM on local machines and CI agents.

Ready? Solve the task in the editor

Use Check answer to mark it complete. Hints are there if you need them.

Java
Skip