/
PlaywrightBrowsingSessionWithBrowser.ts
42 lines (34 loc) · 1.57 KB
/
PlaywrightBrowsingSessionWithBrowser.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import type { BrowserCapabilities } from '@serenity-js/web';
import type * as playwright from 'playwright-core';
import type { PlaywrightOptions } from '../../PlaywrightOptions';
import { SerenitySelectorEngines } from '../../selector-engines';
import { PlaywrightBrowsingSession } from './PlaywrightBrowsingSession';
/**
* @group Models
*/
export class PlaywrightBrowsingSessionWithBrowser extends PlaywrightBrowsingSession {
private readonly serenitySelectorEngines = new SerenitySelectorEngines();
constructor(
protected readonly browser: playwright.Browser,
browserContextOptions: PlaywrightOptions,
private readonly selectors: playwright.Selectors,
) {
super(browserContextOptions);
}
protected override async createBrowserContext(options: PlaywrightOptions): Promise<playwright.BrowserContext> {
await this.serenitySelectorEngines.ensureRegisteredWith(this.selectors);
return this.browser.newContext(this.browserContextOptions);
}
override async closeAllPages(): Promise<void> {
await super.closeAllPages();
const context = await this.browserContext();
await context.close();
}
override async browserCapabilities(): Promise<BrowserCapabilities> {
return {
browserName: (this.browser as any)._initializer.name, // todo: raise a PR to Playwright to expose this information
platformName: process.platform, // todo: get the actual platform from Playwright
browserVersion: this.browser.version()
}
}
}