Test Overview
This test opens a web page with a search input box, types the text "Selenium testing" into it using sendKeys, and verifies that the input box contains the typed text.
This test opens a web page with a search input box, types the text "Selenium testing" into it using sendKeys, and verifies that the input box contains the typed text.
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.junit.Assert; import org.junit.After; import org.junit.Before; import org.junit.Test; public class TypingTextTest { private WebDriver driver; @Before public void setUp() { driver = new ChromeDriver(); } @Test public void testTypingText() { driver.get("https://example.com/search"); WebElement searchInput = driver.findElement(By.id("search-box")); searchInput.sendKeys("Selenium testing"); String enteredText = searchInput.getAttribute("value"); Assert.assertEquals("Selenium testing", enteredText); } @After 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 URL https://example.com/search | Browser displays the search page with input box having id 'search-box' | - | PASS |
| 3 | Finds the input element by id 'search-box' | Input element is located and ready for interaction | - | PASS |
| 4 | Types text 'Selenium testing' into the input box using sendKeys | Input box now contains the text 'Selenium testing' | - | PASS |
| 5 | Retrieves the value attribute of the input box | Value attribute is 'Selenium testing' | Assert that the input box value equals 'Selenium testing' | PASS |
| 6 | Test ends and browser closes | Browser window is closed | - | PASS |