externalabstractPage <Native_Element_Type>
Implements
Index
Constructors
Properties
Methods
- current
- whichName
- whichTitle
- whichUrl
- createPageElement
- locate
- locateAll
- navigateTo
- navigateBack
- navigateForward
- reload
- sendKeys
- executeScript
- executeAsyncScript
- lastScriptExecutionResult
- takeScreenshot
- cookie
- setCookie
- deleteAllCookies
- title
- url
- name
- isPresent
- viewportSize
- setViewportSize
- switchTo
- close
- closeOthers
- modalDialog
- toString
Constructors
externalconstructor
Type parameters
- Native_Element_Type = any
Parameters
externalsession: BrowsingSession<Page<Native_Element_Type>>
externalrootLocator: RootLocator<Native_Element_Type>
externalmodalDialogHandler: ModalDialogHandler
externalid: CorrelationId
Returns Page<Native_Element_Type>
Properties
publicexternalreadonlyid
Methods
staticexternalcurrent
Creates a
QuestionAdapter
representing the currently activePage
.Returns QuestionAdapter<Page<any>>
staticexternalwhichName
Creates a
QuestionAdapter
that resolves to aPage
whichPage.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
externalexpectation: Expectation<string>
Returns QuestionAdapter<Page<any>>
staticexternalwhichTitle
Creates a
QuestionAdapter
that resolves to aPage
whichPage.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
externalexpectation: Expectation<string>
Returns QuestionAdapter<Page<any>>
staticexternalwhichUrl
Creates a
QuestionAdapter
that resolves to aPage
whichPage.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
externalexpectation: Expectation<string>
Returns QuestionAdapter<Page<any>>
externalabstractcreatePageElement
Creates a
PageElement
wrapping a native element.Parameters
externalnativeElement: Native_Element_Type
Returns PageElement<Native_Element_Type>
externalabstractlocate
Creates a
PageElement
, retrieving an element located bySelector
.Parameters
externalselector: Selector
Returns PageElement<Native_Element_Type>
externalabstractlocateAll
Creates
PageElement
, retrieving a collection of elements located bySelector
.Parameters
externalselector: Selector
Returns PageElements<Native_Element_Type>
externalabstractnavigateTo
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
externaldestination: string
Returns Promise<void>
externalabstractnavigateBack
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>
externalabstractnavigateForward
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>
externalabstractreload
Causes the browser to reload the
Page
in the current top-level browsing context.Returns Promise<void>
externalabstractsendKeys
externalabstractexecuteScript
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
externalscript: string | (...parameters: InnerArguments) => Result
externalrest...args: InnerArguments
Returns Promise<Result>
- For a
externalabstractexecuteAsyncScript
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
externalscript: string | (...args: [...parameters: Parameters[], callback: (result: Result) => void]) => void
externalrest...args: Parameters
Returns Promise<Result>
- For a
externalabstractlastScriptExecutionResult
Returns the last result of calling
Page.executeAsyncScript
orPage.executeScript
Type parameters
- R = any
Returns R
externalabstracttakeScreenshot
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
externalabstractcookie
externalabstractsetCookie
Adds a single cookie with
CookieData
to the cookie store associated with the activePage
's address.Parameters
externalcookieData: CookieData
Returns Promise<void>
externalabstractdeleteAllCookies
Removes all the cookies.
Returns Promise<void>
externalabstracttitle
Retrieves the document title of the current top-level browsing context, equivalent to calling
document.title
.Learn more
Returns Promise<string>
externalabstracturl
Retrieves the URL of the current top-level browsing context.
Returns Promise<URL>
externalabstractname
Retrieves the name of the current top-level browsing context.
Returns Promise<string>
externalabstractisPresent
Checks if a given window / tab / page is open and can be switched to, e.g. it's not closed.
Returns Promise<boolean>
externalabstractviewportSize
Returns the actual viewport size available for the given page, excluding any scrollbars.
Returns Promise<{ width: number; height: number }>
externalabstractsetViewportSize
Sets ths size of the visible viewport to desired dimensions.
Parameters
externalsize: { width: number; height: number }
externalwidth: number
externalheight: number
Returns Promise<void>
externalswitchTo
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>
externalabstractclose
Closes this page.
Returns Promise<void>
externalabstractcloseOthers
Closes any open pages, except for this one.
Returns Promise<void>
externalmodalDialog
Returns the
ModalDialogHandler
for the currentPage
.Returns ModalDialogHandler
externaltoString
Returns a description of this Page and its ID.
Returns string
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
BrowseTheWeb
PageElement
Optional
Switchable