import {Attribute} from '@serenity-js/webdriverio/lib/screenplay/questions'
public class | source

Attribute

Returns the value of the given HTML attribute of a given WebElement, represented by Answerable<Element>

Extends:

Question → Attribute

Implements:

Examples:

Example widget
 <ul id="shopping-list" data-items-left="2">
   <li data-state="bought">Coffee<li>
   <li data-state="buy">Honey<li>
   <li data-state="buy">Chocolate<li>
 </ul>
Retrieve a HTML attribute of a given WebElement
 import { actorCalled } from '@serenity-js/core';
 import { Ensure, equals } from '@serenity-js/assertions';
 import { Attribute, by, BrowseTheWeb, Target } from '@serenity-js/webdriverio';

 const shoppingList = () =>
     Target.the('shopping list').located(by.id('shopping-list'))

 actorCalled('Lisa')
     .whoCan(BrowseTheWeb.using(browser))
     .attemptsTo(
         Ensure.that(Attribute.called('data-items-left').of(shoppingList()), equals('2')),
     )
Find WebElements with a given attribute
 import { actorCalled } from '@serenity-js/core';
 import { Ensure, includes } from '@serenity-js/assertions';
 import { Attribute, BrowseTheWeb, by, Target } from '@serenity-js/webdriverio';

 class ShoppingList {
     static items = () =>
         Target.all('items')
             .located(by.css('#shopping-list li'))

     static outstandingItems = () =>
         ShoppingList.items
             .where(Attribute.called('data-state'), includes('buy'))
 }

 actorCalled('Lisa')
     .whoCan(BrowseTheWeb.using(browser))
     .attemptsTo(
         Ensure.that(
             Text.ofAll(ShoppingList.outstandingItems()),
             equals([ 'Honey', 'Chocolate' ])
         ),
     )

Static Method Summary

Static Public Methods
public static

called(name: Answerable<string>): Attribute

Constructor Summary

Public Constructor
public

constructor(name: Answerable<string>, element: Answerable<Element<'async'>>)

Method Summary

Public Methods
public

async answeredBy(actor: AnswersQuestions & UsesAbilities): Promise

public

of(parent: Answerable<Element<'async'>>): Question<Promise<string[]>>

Resolves to the value of a HTML attribute of the target element, located in the context of a parent element.

Static Public Methods

public static called(name: Answerable<string>): Attribute source

Params:

NameTypeAttributeDescription
name Answerable<string>

Returns:

Attribute

Public Constructors

public constructor(name: Answerable<string>, element: Answerable<Element<'async'>>) source

Params:

NameTypeAttributeDescription
name Answerable<string>
element Answerable<Element<'async'>>
  • optional

Public Methods

public async answeredBy(actor: AnswersQuestions & UsesAbilities): Promise source

Params:

NameTypeAttributeDescription
actor AnswersQuestions & UsesAbilities

Returns:

Promise

public of(parent: Answerable<Element<'async'>>): Question<Promise<string[]>> source

Resolves to the value of a HTML attribute of the target element, located in the context of a parent element.

Params:

NameTypeAttributeDescription
parent Answerable<Element<'async'>>

Returns:

Question<Promise<string[]>>