Test Overview
This test uses Selenium in Java to open a webpage, move the mouse to a button, click it using an action chain, and verify the button's text changes to confirm the click worked.
This test uses Selenium in Java to open a webpage, move the mouse to a button, click it using an action chain, and verify the button's text changes to confirm the click worked.
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 ActionChainTest { WebDriver driver; Actions actions; @BeforeEach public void setUp() { driver = new ChromeDriver(); actions = new Actions(driver); } @Test public void testActionChainClick() { driver.get("https://example.com/buttonpage"); WebElement button = driver.findElement(By.id("actionButton")); actions.moveToElement(button).click().perform(); String buttonText = button.getText(); assertEquals("Clicked", buttonText); } @AfterEach public void tearDown() { driver.quit(); } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and ChromeDriver is initialized | Browser window opens, ready for commands | - | PASS |
| 2 | Browser navigates to https://example.com/buttonpage | Page with a button having id 'actionButton' is loaded | - | PASS |
| 3 | Find element with id 'actionButton' | Button element is located on the page | - | PASS |
| 4 | Create action chain: move mouse to button and click, then perform the action | Mouse pointer moves over the button and clicks it | - | PASS |
| 5 | Get the button text after click | Button text is retrieved from the page | Verify button text equals 'Clicked' | PASS |
| 6 | Test ends and browser closes | Browser window is closed | - | PASS |