Test Overview
This test checks if holding down the SHIFT key while typing in an input box results in uppercase text. It verifies that keyboard actions like keyDown and keyUp work correctly.
This test checks if holding down the SHIFT key while typing in an input box results in uppercase text. It verifies that keyboard actions like keyDown and keyUp work correctly.
import org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.interactions.Actions; 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 KeyboardActionsTest { WebDriver driver; Actions actions; @BeforeEach public void setUp() { driver = new ChromeDriver(); actions = new Actions(driver); driver.get("https://example.com/keyboard-input"); } @Test public void testShiftKeyDownAndUp() { WebElement inputBox = driver.findElement(By.id("input-text")); inputBox.click(); actions.keyDown(Keys.SHIFT) .sendKeys("hello") .keyUp(Keys.SHIFT) .perform(); String enteredText = inputBox.getAttribute("value"); assertEquals("HELLO", enteredText); } @AfterEach public void tearDown() { driver.quit(); } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and Chrome browser opens | Browser window is open and ready | - | PASS |
| 2 | Navigates to https://example.com/keyboard-input | Page with input box loaded | Page loaded successfully | PASS |
| 3 | Finds input box element by id 'input-text' | Input box is visible and interactable | Element located | PASS |
| 4 | Clicks on the input box to focus | Input box is focused and ready for typing | - | PASS |
| 5 | Performs keyDown SHIFT, types 'hello', then keyUp SHIFT | Input box contains typed text | Keyboard actions executed correctly | PASS |
| 6 | Gets the value attribute from input box | Input box value is 'HELLO' | Assert that input value equals 'HELLO' | PASS |
| 7 | Test ends and browser closes | Browser closed | - | PASS |