liveBook · Manning

Interaction class

As explained in BDD in Action, Second Edition

An interaction class is a reusable test-automation component that represents an actor's interaction with an application through a particular technology.

An interaction class is a reusable test-automation component that represents an actor’s interaction with an application through a particular technology. In the Screenplay Pattern, an actor passes interaction objects to attemptsTo(), while the interaction locates the relevant driver and performs the technology-specific work. section 12.5 section 12.5.2

Interaction classes keep test intent readable and reduce dependence on low-level WebDriver calls. A login flow can combine Open, Click, and Enter interactions in one attemptsTo() call instead of scattering individual method calls. section 12.5.1 section 12.5

Common interaction classes express focused UI actions:

  • Clear a text field, click an element, or enter a value. section 12.5.1
  • Open or navigate to a URL, scroll to an element, or select a dropdown option. section 12.5.1
  • Add a new interaction class when the existing library does not express the required behavior, such as switching to a parent frame or double-clicking. section 12.5.2 section 12.7

A login interaction sequence

tracy.attemptsTo(Open.url("http://localhost:3000/"), Click.on("//button[normalize-space()='Login']"), Enter.theValue("tracy@traveler.com").into("#email"), Enter.theValue("secretPassword").into("#password"), Click.on("#login-button")); section 12.5.1

public class SwitchTo {
    public static Interaction parent() {
        return Interaction.where("{0} switches to the parent frame",
            theActor -> {                                                   #1
                WebDriver driver = BrowseTheWeb.as(theActor).getDriver();   #2
                driver.switchTo().parentFrame();                            #3
            }
        );
    }
}

A custom interaction can wrap WebDriver logic behind an intention-revealing operation such as switching to the parent frame. section 12.7

How BDD in Action, Second Edition covers it

How deep it goes
Explains reusable objects, bundled UI actions, command-pattern behavior, and custom implementations, while deferring broader implementation detail.
Examples
Uses Click, Enter, Open, Navigate, Scroll, Select, DoubleClick, login flows, and parent-frame switching.
What it assumes
Assumes familiarity with actors and abilities while demonstrating low-level WebDriver access through custom interaction implementations.
What you can do after
Build it from scratch by composing supplied interactions and defining custom Interaction.where implementations for missing behavior.
How it connects
Connects interaction classes with the Screenplay Pattern, actors, abilities, questions, the Command Pattern, and WebDriver.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of BDD in Action, Second Edition. The section links point to the parts of the book it draws on.