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
