externalBrowseTheWebWithPlaywright
Hierarchy
- BrowseTheWeb<playwright.Locator>
- BrowseTheWebWithPlaywright
Implements
Index
Constructors
externalconstructor
Parameters
externalsession: BrowsingSession<Page<Locator>>
Returns BrowseTheWebWithPlaywright
Methods
staticexternalusing
Parameters
externalbrowser: Browser
externaloptionaloptions: PlaywrightOptions
Returns BrowseTheWebWithPlaywright
staticexternalusingPage
Parameters
externalpage: Page
externaloptionaloptions: PlaywrightOptions
Returns BrowseTheWebWithPlaywright
externaltoJSON
Returns a JSON representation of the ability and its current state, if available. The purpose of this method is to enable reporting the state of the ability in a human-readable format, rather than to serialise and deserialise the ability itself.
Returns SerialisedAbility
externalabilityType
Returns the most abstract type of this Ability instance, specifically the first class in the inheritance hierarchy that directly extends the
Ability
class.import { Ability } from '@serenity-js/core';
class MyAbility extends Ability {}
class MySpecialisedAbility extends MyAbility {}
new MyAbility().abilityType(); // returns MyAbility
new MySpecialisedAbility().abilityType(); // returns MyAbilityReturns AbilityType<Ability>
externaldiscard
Automatically closes any open pages when the SceneFinishes
Learn more
Returns Promise<void>
externalcurrentPage
externalallPages
Returns an array of pages representing all the browser tabs available in the current
BrowsingSession
.Returns Promise<Page<Locator>[]>
externalbrowserCapabilities
Returns basic meta-data about the browser associated with this ability.
Returns Promise<BrowserCapabilities>
This implementation of the ability to
BrowseTheWeb
enables theActor
to interact with web front-ends using Playwright.Using Playwright to
BrowseTheWeb
In the example below, we configure the ability to
BrowseTheWebWithPlaywright
with a PlaywrightBrowser
so that Serenity/JS actors can create a newBrowserContext
and instantiate Playwrightpage
s as and when needed.This configuration allows Serenity/JS to control the process of launching and shutting down browser instances and is useful when your test runner, e.g. Cucumber.js, doesn't offer this functionality.
Using
BrowseTheWeb
with an existing Playwrightpage
Test runners like Playwright Test manage Playwright browsers for you and offer a
page
instance you can inject into the ability toBrowseTheWebWithPlaywright
.Note that Serenity/JS Playwright Test module automatically configures all your actors with an ability to
BrowseTheWebWithPlaywright
, so you don't need to do it by hand unless you want to override the default configuration.The example below demonstrates how to use the
BrowseTheWebWithPlaywright.usingPage
API and override the default cast of actors.Configuring Playwright
If you're using Serenity/JS with Playwright Test, Serenity/JS will automatically pick up your configuration from the
playwright.config.ts
file.With other test runners, you can configure Playwright by:
BrowserType.launch
,PlaywrightOptions
when initialising the ability toBrowseTheWebWithPlaywright
.The code snippet below demonstrates how to configure the browser and some popular browser context options, such as
viewport
size,geolocation
, andpermissions
, but you can use it to configure any other option available in Playwright, likeuserAgent
orstorageState
.Note that in addition to all the standard Playwright BrowserContextOptions, you can also provide several others defined in Serenity/JS
PlaywrightOptions
, such as:defaultNavigationTimeout
, which changes the default maximum navigation timeout for the browser context,defaultTimeout
, which changes the default maximum time for all Playwright methods accepting thetimeout
option.Learn more
BrowserContextOptions
BrowseTheWeb
Ability
Actor