Test Overview
This test opens a web page with a text input field, enters some text, then clears the field. It verifies that the field is empty after clearing.
This test opens a web page with a text input field, enters some text, then clears the field. It verifies that the field is empty after clearing.
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.assertEquals; public class ClearFieldTest { WebDriver driver; @BeforeEach public void setUp() { driver = new ChromeDriver(); } @Test public void testClearInputField() { driver.get("https://example.com/form"); WebElement inputField = driver.findElement(By.id("username")); inputField.sendKeys("testuser"); inputField.clear(); String fieldValue = inputField.getAttribute("value"); assertEquals("", fieldValue, "Input field should be empty after clearing"); } @AfterEach public void tearDown() { driver.quit(); } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Test framework initializes ChromeDriver | - | PASS |
| 2 | Browser opens Chrome | Chrome browser window is open and ready | - | PASS |
| 3 | Navigates to https://example.com/form | Page with input field having id 'username' is loaded | - | PASS |
| 4 | Finds input field by id 'username' | Input field element is located on the page | - | PASS |
| 5 | Enters text 'testuser' into input field using sendKeys | Input field now contains text 'testuser' | - | PASS |
| 6 | Clears the input field using clear() method | Input field is now empty | - | PASS |
| 7 | Gets the value attribute of input field | Retrieved value is '' (empty string) | Assert that input field value equals '' | PASS |
| 8 | Test ends and browser closes | Browser window is closed, WebDriver quits | - | PASS |