Skip to main content

LastScriptExecution

Uses the actor’s ability to BrowseTheWeb to retrieve a returns the result of the last script executed via ExecuteScript.

Executing a script and reading the result

import { actorCalled } from '@serenity-js/core'
import { ExecuteScript, LastScriptExecution } from '@serenity-js/web'
import { Ensure, includes } from '@serenity-js/assertions'

await actorCalled('Joseph')
.attemptsTo(
ExecuteScript.sync(() => navigator.userAgent),
Ensure.that(LastScriptExecution.result<string>(), includes('Chrome')),
)

Using LastScriptExecution as QuestionAdapter

import { actorCalled } from '@serenity-js/core'
import { ExecuteScript, LastScriptExecution } from '@serenity-js/web'
import { Ensure, includes } from '@serenity-js/assertions'

await actorCalled('Joseph')
.attemptsTo(
ExecuteScript.sync(() => navigator.userAgent),
Ensure.that(
LastScriptExecution.result<string>().toLocaleLowerCase(),
includes('chrome')
),
)

Learn more

Index

Constructors

Methods

Constructors

constructor

Methods

staticresult

  • result<R>(): QuestionAdapter<R>
  • Enables asserting on the result of a function executed via ExecuteScript.


    Type parameters

    • R

    Returns QuestionAdapter<R>