Test Overview
This test opens a webpage with a checkbox, clicks the checkbox to select it, and verifies that the checkbox is selected.
This test opens a webpage with a checkbox, clicks the checkbox to select it, and verifies that the checkbox is selected.
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertTrue; public class CheckboxTest { private WebDriver driver; @BeforeEach public void setUp() { driver = new ChromeDriver(); } @Test public void testCheckboxSelection() { driver.get("https://example.com/checkboxpage"); WebElement checkbox = driver.findElement(By.id("subscribeCheckbox")); if (!checkbox.isSelected()) { checkbox.click(); } assertTrue(checkbox.isSelected(), "Checkbox should be selected after clicking."); } @AfterEach public void tearDown() { driver.quit(); } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and Chrome browser opens | Chrome browser window is open and ready | - | PASS |
| 2 | Navigates to https://example.com/checkboxpage | Page with checkbox loaded in browser | - | PASS |
| 3 | Finds checkbox element by id 'subscribeCheckbox' | Checkbox element is located on the page | - | PASS |
| 4 | Checks if checkbox is not selected, then clicks it | Checkbox is now selected | - | PASS |
| 5 | Asserts checkbox is selected | Checkbox remains selected | assertTrue(checkbox.isSelected()) verifies checkbox is selected | PASS |
| 6 | Test ends and browser closes | Browser window closed | - | PASS |