externalBrowseTheWebWithPlaywright
Hierarchy
- BrowseTheWeb<playwright.Locator>
- BrowseTheWebWithPlaywright
Implements
Index
Constructors
externalconstructor
Parameters
externalsession: BrowsingSession<Page<Locator>>
Returns BrowseTheWebWithPlaywright
Methods
staticexternalusing
Parameters
externalbrowser: Browser
externaloptionalbrowserContextOptions: BrowserContextOptions
externaloptionalextraBrowserContextOptions: ExtraBrowserContextOptions
Returns BrowseTheWebWithPlaywright
staticexternalusingPage
Parameters
externalpage: Page
externaloptionalextraBrowserContextOptions: ExtraBrowserContextOptions
Returns BrowseTheWebWithPlaywright
staticexternalusingElectronApp
Creates an ability to browse the web using an already-launched Electron application.
Use this method when the Electron application lifecycle is managed externally, such as in Playwright Test where the app is launched per-worker.
Example
import { _electron as electron } from 'playwright';
import { actorCalled } from '@serenity-js/core';
import { BrowseTheWebWithPlaywright } from '@serenity-js/playwright';
const electronApp = await electron.launch({ args: ['main.js'] });
const actor = actorCalled('Tester').whoCan(
BrowseTheWebWithPlaywright.usingElectronApp(electronApp)
);
// After tests, close the app manually
await electronApp.close();Parameters
externalelectronApp: ElectronApplication
An already-launched Playwright ElectronApplication instance
externaloptionalextraBrowserContextOptions: ExtraBrowserContextOptions
Optional configuration for timeouts and navigation
Returns BrowseTheWebWithPlaywright
staticexternallaunchingElectronApp
Creates an ability to browse the web by launching and managing an Electron application.
Use this method when you want Serenity/JS to manage the Electron application lifecycle. The app is launched on first use and closed when the ability is discarded.
Example
import { actorCalled } from '@serenity-js/core';
import { BrowseTheWebWithPlaywright } from '@serenity-js/playwright';
const actor = actorCalled('Tester').whoCan(
BrowseTheWebWithPlaywright.launchingElectronApp({
args: ['path/to/main.js'],
cwd: 'path/to/app',
})
);
// The app is automatically closed when the actor is dismissedParameters
externallaunchOptions: { acceptDownloads?: boolean; args?: string[]; artifactsDir?: string; bypassCSP?: boolean; chromiumSandbox?: boolean; colorScheme?: light | dark | no-preference; cwd?: string; env?: {}; executablePath?: string; extraHTTPHeaders?: {}; geolocation?: { latitude: number; longitude: number; accuracy?: number }; httpCredentials?: { username: string; password: string; origin?: string; send?: unauthorized | always }; ignoreHTTPSErrors?: boolean; locale?: string; offline?: boolean; recordHar?: { omitContent?: boolean; content?: omit | embed | attach; path: string; mode?: full | minimal; urlFilter?: string | RegExp }; recordVideo?: { dir?: string; size?: { width: number; height: number }; showActions?: { duration?: number; position?: top-left | top | top-right | bottom-left | bottom | bottom-right; fontSize?: number } }; timeout?: number; timezoneId?: string; tracesDir?: string }
Options for launching the Electron application
externaloptionalacceptDownloads: boolean
Whether to automatically download all the attachments. Defaults to
truewhere all the downloads are accepted.externaloptionalargs: string[]
Additional arguments to pass to the application when launching. You typically pass the main script name here.
externaloptionalartifactsDir: string
If specified, artifacts (traces, videos, downloads, HAR files, etc.) are saved into this directory. The directory is not cleaned up when the browser closes. If not specified, a temporary directory is used and cleaned up when the browser closes.
externaloptionalbypassCSP: boolean
Toggles bypassing page's Content-Security-Policy. Defaults to
false.externaloptionalchromiumSandbox: boolean
Enable Chromium sandboxing. Defaults to
false.externaloptionalcolorScheme: light | dark | no-preference
Emulates prefers-colors-scheme media feature, supported values are
'light'and'dark'. See page.emulateMedia([options]) for more details. Passingnullresets emulation to system defaults. Defaults to'light'.externaloptionalcwd: string
Current working directory to launch application from.
externaloptionalenv: {}
Specifies environment variables that will be visible to Electron. Defaults to
process.env.externaloptionalexecutablePath: string
Launches given Electron application. If not specified, launches the default Electron executable installed in this package, located at
node_modules/.bin/electron.externaloptionalextraHTTPHeaders: {}
An object containing additional HTTP headers to be sent with every request. Defaults to none.
externaloptionalgeolocation: { latitude: number; longitude: number; accuracy?: number }
externaloptionalhttpCredentials: { username: string; password: string; origin?: string; send?: unauthorized | always }
Credentials for HTTP authentication. If no origin is specified, the username and password are sent to any servers upon unauthorized responses.
externaloptionalignoreHTTPSErrors: boolean
Whether to ignore HTTPS errors when sending network requests. Defaults to
false.externaloptionallocale: string
Specify user locale, for example
en-GB,de-DE, etc. Locale will affectnavigator.languagevalue,Accept-Languagerequest header value as well as number and date formatting rules. Defaults to the system default locale. Learn more about emulation in our emulation guide.externaloptionaloffline: boolean
Whether to emulate network being offline. Defaults to
false. Learn more about network emulation.externaloptionalrecordHar: { omitContent?: boolean; content?: omit | embed | attach; path: string; mode?: full | minimal; urlFilter?: string | RegExp }
Enables HAR recording for all pages into
recordHar.pathfile. If not specified, the HAR is not recorded. Make sure to await browserContext.close([options]) for the HAR to be saved.externaloptionalrecordVideo: { dir?: string; size?: { width: number; height: number }; showActions?: { duration?: number; position?: top-left | top | top-right | bottom-left | bottom | bottom-right; fontSize?: number } }
Enables video recording for all pages into
recordVideo.dirdirectory. If not specified videos are not recorded. Make sure to await browserContext.close([options]) for videos to be saved.externaloptionaltimeout: number
Maximum time in milliseconds to wait for the application to start. Defaults to
30000(30 seconds). Pass0to disable timeout.externaloptionaltimezoneId: string
Changes the timezone of the context. See ICU's metaZones.txt for a list of supported timezone IDs. Defaults to the system timezone.
externaloptionaltracesDir: string
If specified, traces are saved into this directory.
externaloptionalextraBrowserContextOptions: ExtraBrowserContextOptions
Optional configuration for timeouts and navigation
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
Abilityclass.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>
externalinitialise
Returns Promise<void>
externalisInitialised
Returns boolean
externaldiscard
Automatically closes any open pages when the SceneFinishes
For self-launching Electron sessions, also closes the Electron application.
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
BrowseTheWebenables theActorto interact with web front-ends using Playwright.Using Playwright to
BrowseTheWebIn the example below, we configure the ability to
BrowseTheWebWithPlaywrightwith a PlaywrightBrowserso that Serenity/JS actors can create a newBrowserContextand instantiate Playwrightpages 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
BrowseTheWebwith an existing PlaywrightpageTest runners like Playwright Test manage Playwright browsers for you and offer a
pageinstance 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.usingPageAPI 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.tsfile.With other test runners, you can configure Playwright by:
BrowserType.launch,ExtraBrowserContextOptionswhen initialising the ability toBrowseTheWebWithPlaywright.The code snippet below demonstrates how to configure the browser and some popular browser context options, such as
viewportsize,geolocation, andpermissions, but you can use it to configure any other option available in Playwright, likeuserAgentorstorageState.Note that in addition to all the standard Playwright BrowserContextOptions, you can also provide several others defined in Serenity/JS
ExtraBrowserContextOptions, 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 thetimeoutoption.Learn more
BrowserContextOptionsBrowseTheWebAbilityActor