liveBook · Manning

Synchronization statement

As explained in BDD in Action, Second Edition

A synchronization statement coordinates test execution with an asynchronous system condition or elapsed duration.

A synchronization statement coordinates test execution with an asynchronous interface condition or elapsed duration. Used inside higher-level verification tasks, it keeps business-facing checks clear while handling low-level timing concerns. section 15.1.7

Prefer synchronization statements that express the condition the test must observe:

  • Replace a low-level sequence such as “wait, check, click, wait” with a business-specific verification task. section 15.1.7
  • Wait for a notification to appear, verify its message, dismiss it, and wait for it to disappear. section 15.1.7

Duplicate email notification

A failed registration check can wait until the toaster message is present, confirm that it includes “Email exists,” click the message, and wait until it is no longer present. Encapsulating these steps as VerifySubmission.failedWith keeps the Cucumber step readable and reusable. section 15.1.7

import { Actor, Wait } from '@serenity-js/core'
import { Click } from '@serenity-js/web'
import { Ensure, includes, isPresent, not } from '@serenity-js/assertions'
 
Then('{pronoun} should be advised of an error: {string}',
  (actor: Actor, expectedMessage: string) =>
    actor.attemptsTo(
      // wait for the message to appear
      Wait.until(ToasterMessage(), isPresent()),
 
      // verify the message
      Ensure.that(Text.of(ToasterMessage()), includes(expectedMessage)),
 
      // dismiss the message
      Click.on(ToasterMessage()),
 
      // wait for the message to disappear
      Wait.until(ToasterMessage(), not(isPresent())),
  )
)

Inspect the Serenity/JS step showing appearance and disappearance synchronization around a temporary error message. section 15.1.7

How BDD in Action, Second Edition covers it

How deep it goes
Descends to Wait.until conditions, assertions, dismissal, and reusable task composition.
Examples
Uses a duplicate-email toaster notification and successful or failed registration-submission checks.
What you can do after
Apply it via Serenity/JS to synchronize transient interface checks inside reusable business-domain tasks.
How it connects
Connects test automation with verification tasks, assertions, Cucumber steps, actors, and acceptance criteria.

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.