@serenity-js/playwright
Version:
Adapter that integrates @serenity-js/web with Playwright, enabling Serenity/JS reporting and using the Screenplay Pattern to write component and end-to-end test scenarios
47 lines • 1.75 kB
JavaScript
import { CorrelationId } from '@serenity-js/core/model';
import { PlaywrightBrowsingSession } from './PlaywrightBrowsingSession.js';
import { PlaywrightPage } from './PlaywrightPage.js';
/**
* @group Models
*/
export class PlaywrightBrowsingSessionWithPage extends PlaywrightBrowsingSession {
page;
playwrightManagedPageId = CorrelationId.create();
constructor(page, browserContextOptions, selectors) {
super(browserContextOptions, selectors);
this.page = page;
}
async registerCurrentPage() {
await this.browserContext();
const playwrightPage = new PlaywrightPage(this, this.page, this.extraBrowserContextOptions, this.playwrightManagedPageId);
this.register(playwrightPage);
return playwrightPage;
}
async createBrowserContext() {
return this.page.context();
}
/**
* Closes any newly opened pages, leaving only the original one managed by Playwright Test.
*/
async closeAllPages() {
for (const page of this.pages.values()) {
if (!page.id.equals(this.playwrightManagedPageId)) {
await page.close();
}
}
this.pages.clear();
this.currentBrowserPage = undefined;
}
async browserCapabilities() {
const browser = this.page.context().browser();
return {
browserName: browser._initializer.name, // todo: raise a PR to Playwright to expose this information
platformName: process.platform, // todo: get the actual platform from Playwright
browserVersion: browser.version()
};
}
async discard() {
await this.closeAllPages();
}
}
//# sourceMappingURL=PlaywrightBrowsingSessionWithPage.js.map