liveBook · Manning

QuestionAdapter

As explained in BDD in Action, Second Edition

A QuestionAdapter is a proxy that presents static, dynamic, or asynchronously resolved data through a consistent Screenplay API.

A QuestionAdapter is a proxy that presents static, dynamic, or asynchronously resolved data through one Screenplay API. It lets tasks accept values from an actor’s notepad without knowing whether those values are immediately available or lazy-loaded. section 15.1.6

Use a QuestionAdapter when a task must support both fixed inputs and values resolved during execution:

  • Replace a task parameter such as TravelerDetails with QuestionAdapter<TravelerDetails> when details come from the notepad. section 15.1.6
  • Create partially overridden data with Question.fromObject, merging static fields with dynamic or asynchronous values. section 15.1.6
  • Reference proxied fields and methods like ordinary object members; nested members are wrapped recursively. section 15.1.6
  • Use the same adapter idea in Lean Page Objects to turn low-level widget data, such as CSS classes, into meaningful states. section 15.2.3

Reusable sign-up task

A sign-up task can accept QuestionAdapter<TravelerDetails>, allowing one step to use notes<TravelerNotes>().get('travelerDetails') while another merges those defaults with an email override through Question.fromObject. The registration-form task can then read travelerDetails.email, travelerDetails.password, and other fields without handling resolution explicitly. section 15.1.6

Listing 15.6 Negative scenario: Signing up using duplicate email address
Feature: Sign up
 
  Rule: Duplicate usernames are not allowed
 
    Scenario: Sign up using duplicate email address
 
      Mike Smith is an existing Frequent Flyer member.
      His wife Jenny Smith does not have a Frequent Flyer account.
 
      Given Mike has signed up using the following details:
        | email | smiths@example.org |
       When Jenny tries to sign up using:
        | email | smiths@example.org |
       Then she should be advised of an error: "Email exists"

Explore a duplicate-email scenario that demonstrates how reusable sign-up steps support negative test variations. section 15.1.6

How BDD in Action, Second Edition covers it

How deep it goes
Explains proxy access, recursive wrapping, task signatures, and partial merging, then applies the pattern to Lean Page Objects.
Examples
Uses traveler registration details, duplicate-email overrides, and a toaster status derived from CSS classes.
What it assumes
Assumes Screenplay tasks and actor notepads, while demonstrating how to adapt task signatures for dynamic data.
What you can do after
Apply it via QuestionAdapter and Question.fromObject to build reusable tasks that accept resolved or partially overridden data.
How it connects
Connects QuestionAdapter with Screenplay tasks, actor notepads, Question.fromObject, Lean Page Objects, and CSS-class questions.

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.