0
0
Selenium Javatesting~10 mins

Action chain execution (perform) in Selenium Java - Test Execution Trace

Choose your learning style9 modes available
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.

Test Code - JUnit
Selenium Java
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();
    }
}
Execution Trace - 6 Steps
StepActionSystem StateAssertionResult
1Test starts and ChromeDriver is initializedBrowser window opens, ready for commands-PASS
2Browser navigates to https://example.com/buttonpagePage with a button having id 'actionButton' is loaded-PASS
3Find element with id 'actionButton'Button element is located on the page-PASS
4Create action chain: move mouse to button and click, then perform the actionMouse pointer moves over the button and clicks it-PASS
5Get the button text after clickButton text is retrieved from the pageVerify button text equals 'Clicked'PASS
6Test ends and browser closesBrowser window is closed-PASS
Failure Scenario
Failing Condition: Button with id 'actionButton' is not found or click does not change text to 'Clicked'
Execution Trace Quiz - 3 Questions
Test your understanding
What does the perform() method do in the action chain?
AIt executes all the actions in the chain immediately
BIt waits for the element to be visible
CIt finds the element on the page
DIt closes the browser
Key Result
Using action chains with perform() allows simulating real user interactions like mouse moves and clicks, which is essential for testing dynamic UI behavior.