Skip to main content

externalLastScriptExecution

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

externalconstructor

Methods

staticexternalresult