liveBook · Manning

@serenity-js/web

As explained in BDD in Action, Second Edition

@serenity-js/web is the Serenity/JS module that provides Screenplay-compatible abstractions for interacting with and querying web interfaces.

@serenity-js/web gives Screenplay actors a consistent way to interact with and query web interfaces without coupling tasks to a particular browser integration tool. It turns low-level actions into reusable, domain-friendly automation that can remain portable across Playwright, WebdriverIO, and Selenium WebDriver. section 15.1.3 section 15.2.5

Use the module to express:

  • Interactions such as Navigate.to(url), Click.on(element), Scroll.to(element), and Enter.theValue(value).into(input). section 15.2.5
  • Questions such as Text.of(element), Value.of(input), and CssClasses.of(element) for reading interface state. section 15.2.5
  • PageElement and PageElements queries that identify controls through basic locators or composable conditions. section 15.2.6

Compose a registration task

A registration task can navigate to the home page and click the Register button: `Task.where('#actor locates the registration form', Navigate.to('/'), Click.on(Form.buttonCalled('Register')))`. The task describes intent while the Web interactions perform the browser-level work. section 15.1.3

import { actorCalled, configure, Cast } from '@serenity-js/core'
import { BrowseTheWebWithPlaywright } from '@serenity-js/playwright'
import * as playwright from 'playwright'
 
const browser: playwright.Browser = await playwright.chromium.launch()   #1
    
configure({
  actors: Cast.whereEveryoneCan(                               
    BrowseTheWebWithPlaywright.using(browser)                            #2
  ) 
})
 
actorCalled(‘William’).attemptsTo(
  Click.on(PageElement.located(By.css(‘.selector’)),                     #3
)

Shows how a tool-specific BrowseTheWeb ability supplies the Playwright implementation while the test continues using shared Web APIs. section 15.2.7

How BDD in Action, Second Edition covers it

How deep it goes
Explains interactions, questions, PageElement composition, and selector queries, while deferring tool-specific implementations to companion modules.
Examples
Demonstrates registration-form navigation, button and input queries, text assertions, Angular Material selectors, and Playwright configuration.
What it assumes
Assumes familiarity with Serenity/JS actors, tasks, abilities, PageElements, and assertions while providing the web-facing abstractions.
What you can do after
Apply it via Screenplay tasks, PageElements, interactions, questions, and tool-specific actor abilities to build portable web tests.
How it connects
Connects Screenplay Pattern, Page Elements, web browser drivers, service provider architecture, Playwright, WebdriverIO, and Selenium WebDriver.

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.