Test Overview
This test opens a web page with radio buttons, selects a specific radio button, and verifies that it is selected.
This test opens a web page with radio buttons, selects a specific radio button, and verifies that it 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 RadioButtonTest { WebDriver driver; @BeforeEach public void setUp() { driver = new ChromeDriver(); driver.get("https://example.com/radio-buttons"); } @Test public void testSelectRadioButton() { WebElement radioButton = driver.findElement(By.id("option2")); radioButton.click(); assertTrue(radioButton.isSelected(), "Radio button option2 should be selected"); } @AfterEach public void tearDown() { driver.quit(); } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and Chrome browser opens | Chrome browser window is open, ready to navigate | - | PASS |
| 2 | Navigates to https://example.com/radio-buttons | Page with radio buttons is loaded and visible | Page title or URL confirms correct page loaded | PASS |
| 3 | Finds radio button element with id 'option2' | Radio button with id 'option2' is located in the DOM | Element is present and interactable | PASS |
| 4 | Clicks on the radio button 'option2' | Radio button 'option2' is selected visually | - | PASS |
| 5 | Checks if radio button 'option2' is selected | Radio button 'option2' state is selected | assertTrue(radioButton.isSelected()) verifies selection | PASS |
| 6 | Test ends and browser closes | Browser window is closed | - | PASS |