Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare the base test class with WebDriver setup.
Selenium Java
public class BaseTest { protected WebDriver driver; @BeforeMethod public void setUp() { driver = new [1](); driver.manage().window().maximize(); } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using FirefoxOptions instead of a driver class.
Trying to instantiate WebElement directly.
Using Actions class which is for user interactions.
✗ Incorrect
The WebDriver instance must be initialized with a browser driver like ChromeDriver to control the browser.
2fill in blank
mediumComplete the code to close the browser after each test method.
Selenium Java
public class BaseTest { protected WebDriver driver; @AfterMethod public void [1]() { if (driver != null) { driver.quit(); } } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using setUp which is for starting tests.
Naming the method initialize which is unclear.
Using startDriver which is not a standard name.
✗ Incorrect
The tearDown method is commonly used to clean up resources after tests, such as closing the browser.
3fill in blank
hardFix the error in the base test class to correctly import the TestNG annotation for setup.
Selenium Java
import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.testng.annotations.[1]; public class BaseTest { protected WebDriver driver; @[1] public void setUp() { driver = new ChromeDriver(); } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using @AfterMethod which runs after tests.
Using @Test which marks test methods.
Using @BeforeClass which runs once before all tests.
✗ Incorrect
The @BeforeMethod annotation tells TestNG to run the method before each test method, which is correct for setup.
4fill in blank
hardFill both blanks to create a base test class that initializes and quits the WebDriver properly.
Selenium Java
public class BaseTest { protected WebDriver driver; @[1] public void setUp() { driver = new [2](); } @AfterMethod public void tearDown() { if (driver != null) { driver.quit(); } } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using @AfterClass which runs after all tests.
Using FirefoxDriver when ChromeDriver is expected.
Mixing annotations and driver classes incorrectly.
✗ Incorrect
The setup method should be annotated with @BeforeMethod and initialize the driver with ChromeDriver for proper browser control.
5fill in blank
hardFill all three blanks to implement a base test class with setup, teardown, and a sample test method.
Selenium Java
public class BaseTest { protected WebDriver driver; @[1] public void setUp() { driver = new [2](); } @AfterMethod public void tearDown() { if (driver != null) { driver.quit(); } } @Test public void [3]() { driver.get("https://example.com"); Assert.assertEquals(driver.getTitle(), "Example Domain"); } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using FirefoxDriver instead of ChromeDriver.
Naming the test method unclearly or missing @Test annotation.
Using wrong annotations for setup.
✗ Incorrect
The setup uses @BeforeMethod and ChromeDriver. The test method named testHomePage checks the page title.