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
