abstractPage <Native_Element_Type>
Implements
- Optional
- Switchable
Index
Methods
Constructors
Properties
Methods
staticcurrent
Creates a QuestionAdapter representing the currently active Page.
Returns QuestionAdapter<Page<any>>
staticwhichName
Creates a QuestionAdapter that resolves to a Page which Page.name meets the
expectation
.Switching to a page with the desired name
import { includes } from '@serenity-js/assertions'
import { actorCalled } from '@serenity-js/core'
import { Switch } from '@serenity-js/web'
actorCalled('Bernie').attemptsTo(
Switch.to(Page.whichName(includes(`photo-gallery`))),
)Parameters
expectation: Expectation<string>
Returns QuestionAdapter<Page<any>>
staticwhichTitle
Creates a QuestionAdapter that resolves to a Page which Page.title meets the
expectation
.Switching to a page with the desired title
import { includes } from '@serenity-js/assertions'
import { actorCalled } from '@serenity-js/core'
import { Switch } from '@serenity-js/web'
actorCalled('Bernie').attemptsTo(
Switch.to(Page.whichTitle(includes(`Summer collection`))),
)Parameters
expectation: Expectation<string>
Returns QuestionAdapter<Page<any>>
staticwhichUrl
Creates a QuestionAdapter that resolves to a Page which Page.url meets the
expectation
.Switching to a page with the desired URL
import { endsWith } from '@serenity-js/assertions'
import { actorCalled } from '@serenity-js/core'
import { Switch } from '@serenity-js/web'
actorCalled('Bernie').attemptsTo(
Switch.to(Page.whichUrl(endsWith(`/gallery.html`))),
)Parameters
expectation: Expectation<string>
Returns QuestionAdapter<Page<any>>
abstractlocate
Creates a PageElement, retrieving an element located by Selector.
Parameters
selector: Selector
Returns PageElement<Native_Element_Type>
abstractlocateAll
Creates PageElements, retrieving a collection of elements located by Selector.
Parameters
selector: Selector
Returns PageElements<Native_Element_Type>
abstractnavigateTo
Navigate to a given destination, specified as an absolute URL or a path relative to any base URL configured in your web test integration tool.
Learn more
Parameters
destination: string
Returns Promise<void>
abstractnavigateBack
Causes the browser to traverse one step backward in the joint session history of the current Page (the current top-level browsing context).
This is equivalent to pressing the back button in the browser UI, or calling
window.history.back
.Returns Promise<void>
abstractnavigateForward
Causes the browser to traverse one step forward in the joint session history of the current Page (the current top-level browsing context).
This is equivalent to pressing the back button in the browser UI, or calling
window.history.forward
.Returns Promise<void>
abstractreload
Causes the browser to reload the Page in the current top-level browsing context.
Returns Promise<void>
abstractsendKeys
abstractexecuteScript
Schedules a command to execute JavaScript in the context of the currently selected frame or window.
The script fragment will be executed as the body of an anonymous function. If the script is provided as a function object, that function will be converted to a string for injection into the target window.
Any arguments provided in addition to the script will be included as script arguments and may be referenced using the
arguments
object. Arguments may be aboolean
,number
,string
orWebElement
. Arrays and objects may also be used as script arguments as long as each item adheres to the types previously mentioned.The script may refer to any variables accessible from the current window. Furthermore, the script will execute in the window’s context, thus
document
may be used to refer to the current document. Any local variables will not be available once the script has finished executing, though global variables will persist.If the script has a return value (i.e. if the script contains a
return
statement), then the following steps will be taken for resolving this functions return value:- For a PageElement, the value will resolve to a HTMLElement
null
andundefined
return values will resolve tonull
boolean
,number
, andstring
values will resolve as is- Functions will resolve to their string representation
- For arrays and objects, each member item will be converted according to the rules above
Use injected JavaScript to retrieve information about a HTMLElement
BrowseTheWeb.as(actor).executeAsyncScript(`
return arguments[0].tagName;
`, PageElement.located(By.css('h1')).describedAs('header'))
// returns a Promise that resolves to 'h1'Learn more
Type parameters
- Result
- InnerArguments: any[]
Parameters
script: string | (...parameters: InnerArguments) => Result
rest...args: InnerArguments
Returns Promise<Result>
abstractexecuteAsyncScript
Schedules a command to execute asynchronous JavaScript in the context of the currently selected frame or window.
The script fragment will be executed as the body of an anonymous function. If the script is provided as a function object, that function will be converted to a string for injection into the target window.
Any arguments provided in addition to the script will be included as script arguments and may be referenced using the
arguments
object. Arguments may be aboolean
,number
,string
orWebElement
Arrays and objects may also be used as script arguments as long as each item adheres to the types previously mentioned.Unlike executing synchronous JavaScript with Page.executeScript, scripts executed with this function must explicitly signal they are finished by invoking the provided callback.
This callback will always be injected into the executed function as the last argument, and thus may be referenced with
arguments[arguments.length - 1]
.The following steps will be taken for resolving this functions return value against the first argument to the script’s callback function:
- For a PageElement, the value will resolve to a HTMLElement
null
andundefined
return values will resolve tonull
boolean
,number
, andstring
values will resolve as is- Functions will resolve to their string representation
- For arrays and objects, each member item will be converted according to the rules above
Perform a sleep in the browser under test>
BrowseTheWeb.as(actor).executeAsyncScript(`
var delay = arguments[0];
var callback = arguments[arguments.length - 1];
window.setTimeout(callback, delay);
`, 500)Return a value asynchronously
BrowseTheWeb.as(actor).executeAsyncScript(`
var callback = arguments[arguments.length - 1];
callback('some return value')
`).then(value => doSomethingWithThe(value))Learn more
Type parameters
- Result
- Parameters: any[]
Parameters
script: string | (...args: [...parameters: Parameters[], callback: (result: Result) => void]) => void
rest...args: Parameters
Returns Promise<Result>
abstractlastScriptExecutionResult
Returns the last result of calling Page.executeAsyncScript or Page.executeScript
Type parameters
- R = any
Returns R
abstracttakeScreenshot
Take a screenshot of the top-level browsing context’s viewport.
Returns Promise<string>
A promise that will resolve to a base64-encoded screenshot PNG
abstractcookie
abstractsetCookie
Adds a single cookie with CookieData to the cookie store associated with the active Page‘s address.
Parameters
cookieData: CookieData
Returns Promise<void>
abstractdeleteAllCookies
Removes all the cookies.
Returns Promise<void>
abstracttitle
Retrieves the document title of the current top-level browsing context, equivalent to calling
document.title
.Learn more
Returns Promise<string>
abstracturl
Retrieves the URL of the current top-level browsing context.
Returns Promise<URL>
abstractname
Retrieves the name of the current top-level browsing context.
Returns Promise<string>
abstractisPresent
Checks if a given window / tab / page is open and can be switched to, e.g. it’s not closed.
Returns Promise<boolean>
abstractviewportSize
Returns the actual viewport size available for the given page, excluding any scrollbars.
Returns Promise<{ width: number; height: number }>
abstractsetViewportSize
Sets ths size of the visible viewport to desired dimensions.
Parameters
size: { width: number; height: number }
Returns Promise<void>
switchTo
Switches the current browsing context to the given page and returns an object that allows the caller to switch back to the previous context when needed.
Learn more
Returns Promise<SwitchableOrigin>
abstractclose
Closes this page.
Returns Promise<void>
abstractcloseOthers
Closes any open pages, except for this one.
Returns Promise<void>
modalDialog
Returns the ModalDialogHandler for the current Page.
Returns ModalDialogHandler
toString
Returns a description of this Page and its ID.
Returns string
Constructors
constructor
Type parameters
- Native_Element_Type = any
Parameters
session: BrowsingSession<Page<Native_Element_Type>>
rootLocator: RootLocator<Native_Element_Type>
modalDialogHandler: ModalDialogHandler
id: CorrelationId
Returns Page<Native_Element_Type>
Serenity/JS Screenplay Pattern-style model that enables interactions with a Web page rendered in a Web browser tab.
Referring to the current page
Switching to another open page
Retrieving information about another open page
You can retrieve information about another open page without having to explicitly switch to it:
Performing activities in the context of another page
Learn more