liveBook · Manning

PageElements

As explained in BDD in Action, Second Edition

PageElements is a Serenity/JS abstraction representing a collection of web elements and exposing queries over that collection.

PageElements represents a collection of web elements and provides queries for selecting members of that collection. It complements PageElement, which models one element, and works with Serenity/JS web APIs. section 15.2.2

Use PageElements to:

  • Locate groups of elements with By.css, By.xpath, By.id, or related selectors. section 15.2.2
  • Filter the collection with Page Element Query Language expectations such as presence and matching text. section 15.2.6
  • Select an individual match with operations such as first(), then scope related PageElements with .of(). section 15.2.2 section 15.2.6

Finding a labelled form field

Define form fields as PageElements.located(By.css('mat-form-field')). Filter them by the presence of a label and matching label text, select the first match, and scope the input to that field: Form.input().of(Form.fieldCalled(name)). section 15.2.6

import { PageElements, By } from '@serenity-js/web'
 
class Form {
    public static fields = () =>
        PageElements.located(By.css('mat-form-field'))
            .describedAs('form fields')
    // ...
}

The listing shows the basic PageElements declaration for a reusable collection of form fields. section 15.2.6

How BDD in Action, Second Edition covers it

How deep it goes
Explains collection declaration, selector choice, filtering, first-match selection, and scoping, while deferring integration internals.
Examples
Demonstrates toaster messages and Angular Material form fields filtered by label text.
What you can do after
Apply it via Serenity/JS to define reusable collections and derive precise element references for automated interactions.
How it connects
Connects PageElements with PageElement, By selectors, Page Element Query Language, Page Objects, and the Screenplay Pattern.

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.