liveBook · Manning

Question

As explained in BDD in Action, Second Edition

A web question is a Screenplay-compatible query that retrieves information about the state of a system through its web interface.

A question is a Screenplay-compatible query that retrieves information about system state through a user interface. An actor answers it using an ability, then uses the result to determine whether the application behaves as expected. section 12.11 section 12.8

Use questions to express observations at the level your test needs:

  • Read an element’s text, such as a status level or account balance. section 12.8.1
  • Convert a returned value, for example turning a point balance into an integer. section 12.8.1
  • Check state directly, such as whether a balance is visible, a field is enabled, or a button is disabled. section 12.8.1
  • Wrap repeated or business-specific queries in domain-specific Question classes to improve readability. section 12.8.2

Reading a frequent-flyer balance

A predefined question can locate the point-balance element and convert its text: Text.of("[test-dataid='point-balance']").asInteger(). The actor obtains the actual result by answering it, for example with answeredBy(sally). A domain-specific Account.pointBalance() question can hide that selector and conversion while preserving the business meaning. section 12.8.1 section 12.8.2

Table 12.3 Common Screenplay question classes in Serenity BDD (view table figure)

Question

Usage

Example

Attribute

Find a specific HTML attribute value for a given element

Attribute.of(".item-details-link")

.named("href")

Disabled

Check whether a given field is disabled

Disabled.of("#login-button")

Enabled

Check whether a given field is enabled

Enabled.of("#login-button")

SelectedValue

The value of the selected element in a dropdown list

SelectedValue.of("#travel-class")

Text

The text value of an element

Text.of("[test-dataid='name']")

Value

The value of a form field (from the “value” CSS attribute)

Value.of("#firstName")

Visibility

Check whether an element is visible on the page

Visibility.of(".error-message")

Common Serenity BDD question classes cover HTML attributes, form values, selected options, text, visibility, and enabled or disabled state. section 12.8.1

In Serenity/JS, web questions such as Text.of, Value.of, and CssClasses.of provide integration-tool-agnostic access to state through PageElement objects. section 15.2.5

How BDD in Action, Second Edition covers it

How deep it goes
Defines predefined and custom queries, value transformations, actor answering, and common UI question types.
Examples
Uses status text, point-balance conversion, visibility checks, and Serenity BDD UI question classes.
What it assumes
Assumes Screenplay actors and abilities, while introducing questions as the mechanism for querying system state.
What you can do after
Evaluate/understand application behavior by retrieving UI state and using it in assertions.
How it connects
Connects questions with actors, abilities, interactions, tasks, assertions, and PageElement objects.

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.