Skip to main content

ComputedStyle <Native_Element_Type>

Uses the actor’s ability to BrowseTheWeb to retrieve the value of the specified computed style property of a given PageElement.

Example widget

<ul id="shopping-list" style="display: block">
<li style="display: block">Coffee<li>
<li style="display: none">Honey<li>
<li style="display: block">Chocolate<li>
</ul>

Retrieve a computed style property of a given PageElement

import { actorCalled } from '@serenity-js/core'
import { Ensure, equals } from '@serenity-js/assertions'
import { ComputedStyle, By, PageElement } from '@serenity-js/web'

const shoppingList = () =>
PageElement.located(By.id('shopping-list'))
.describedAs('shopping list')

await actorCalled('Lisa').attemptsTo(
Ensure.that(
ComputedStyle.called('display').of(shoppingList()),
equals('block')
),
)

Using ComputedStyle as QuestionAdapter

import { actorCalled } from '@serenity-js/core'
import { Ensure, equals } from '@serenity-js/assertions'
import { Attribute, By, PageElement } from '@serenity-js/web'

const shoppingList = () =>
PageElement.located(By.css('#shopping-list'))
.describedAs('shopping list')

await actorCalled('Lisa').attemptsTo(
Ensure.that(
ComputedStyle.called('display').of(shoppingList()).toLocaleUpperCase(),
equals('BLOCK')
),
)

Using as filter in Page Element Query Language

import { actorCalled } from '@serenity-js/core'
import { Ensure, includes } from '@serenity-js/assertions'
import { Attribute, By, PageElements } from '@serenity-js/web'

class ShoppingList {
static items = () =>
PageElements.located(By.css('#shopping-list li'))
.describedAs('items')

static outstandingItems = () =>
ShoppingList.items()
.where(
ComputedStyle.called('display'),
equals('block')
)
}

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

Learn more

Hierarchy

  • Question<Promise<string>>
    • ComputedStyle

Implements

  • MetaQuestion<PageElement<Native_Element_Type>, Question<Promise<string>>>

Index

Methods

staticcalled

as

  • as<O>(mapping: (answer: string) => O | Promise<O>): QuestionAdapter<O>
  • Maps this question to one of a different type.

    Question.about('number returned as string', actor => '42')   // returns: QuestionAdapter<string>
    .as(Number) // returns: QuestionAdapter<number>

    Type parameters

    • O

    Parameters

    • mapping: (answer: string) => O | Promise<O>

    Returns QuestionAdapter<O>

ofPseudoElement

  • ofPseudoElement(pseudoElement: Answerable<string>): MetaQuestionAdapter<PageElement<Native_Element_Type>, string>
  • Instantiates a Question that uses the actor’s ability to BrowseTheWeb to retrieve the value of the specified computed style property of the specified pseudo-element of a given PageElement.


    Parameters

    • pseudoElement: Answerable<string>

      The pseudo-element to retrieve the computed style property from, such as ::before or ::after

    Returns MetaQuestionAdapter<PageElement<Native_Element_Type>, string>

of

  • Resolves to the value of a computed style property of the pageElement.

    Learn more


    Parameters

    Returns MetaQuestionAdapter<PageElement<Native_Element_Type>, string>

answeredBy

  • answeredBy(actor: AnswersQuestions & UsesAbilities): Promise<string>
  • @inheritDoc

    Parameters

    • actor: AnswersQuestions & UsesAbilities

    Returns Promise<string>

describedAs

  • @inheritDoc

    Parameters

    • subject: string

    Returns ComputedStyle<Native_Element_Type>

toString

  • toString(): string
  • @inheritDoc

    Returns string