Test Overview
This test opens a webpage, finds a button, clicks and holds it, then verifies the button's text changes to show it is held.
This test opens a webpage, finds a button, clicks and holds it, then verifies the button's text changes to show it is held.
import org.openqa.selenium.By; 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 ClickAndHoldTest { WebDriver driver; Actions actions; @BeforeEach public void setUp() { driver = new ChromeDriver(); actions = new Actions(driver); } @Test public void testClickAndHoldButton() { driver.get("https://example.com/click-and-hold"); WebElement button = driver.findElement(By.id("hold-button")); actions.clickAndHold(button).perform(); String buttonText = button.getText(); assertEquals("Holding", buttonText); } @AfterEach public void tearDown() { driver.quit(); } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Test environment initialized, ChromeDriver ready | - | PASS |
| 2 | Browser opens Chrome | Chrome browser window opened, blank page | - | PASS |
| 3 | Navigates to https://example.com/click-and-hold | Page with a button having id 'hold-button' loaded | - | PASS |
| 4 | Finds element by id 'hold-button' | Button element located on the page | Element is present and interactable | PASS |
| 5 | Clicks and holds the button using Actions.clickAndHold().perform() | Button visually pressed and held down | - | PASS |
| 6 | Gets button text after click and hold | Button text changed to 'Holding' | Button text equals 'Holding' | PASS |
| 7 | Test ends and browser closes | Browser closed, resources released | - | PASS |