Selenium + Java · Lesson 37 of 44
Module 37: Test Lifecycle
Your task
Implement executeWithLifecycle:
Write it in the editor, then press Check answer (Ctrl + Enter).
public class BaseTest {
protected WebDriver driver;
public void setUp() {
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless=new");
driver = new ChromeDriver(options);
driver.manage().window().maximize();
}
public void tearDown() {
if (driver != null) {
driver.quit();
}
}
}Managing WebDriver lifecycles properly guarantees that crashed tests do not leave abandoned browser processes consuming CPU and memory. In this lesson, you will structure clean BaseTest classes with setup and teardown guarantees. Let's master the test lifecycle!
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.
If an assertion fails or an exception occurs during the test, a finally block guarantees the browser process is still cleanly closed.
Ready? Solve the task in the editor
Use Check answer to mark it complete. Hints are there if you need them.
___