UNPKG

@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

48 lines 1.94 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PlaywrightBrowsingSessionWithPage = void 0; const model_1 = require("@serenity-js/core/lib/model"); const PlaywrightBrowsingSession_1 = require("./PlaywrightBrowsingSession"); const PlaywrightPage_1 = require("./PlaywrightPage"); /** * @group Models */ class PlaywrightBrowsingSessionWithPage extends PlaywrightBrowsingSession_1.PlaywrightBrowsingSession { page; playwrightManagedPageId = model_1.CorrelationId.create(); constructor(page, browserContextOptions, selectors) { super(browserContextOptions, selectors); this.page = page; } async registerCurrentPage() { await this.browserContext(); const playwrightPage = new PlaywrightPage_1.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() }; } } exports.PlaywrightBrowsingSessionWithPage = PlaywrightBrowsingSessionWithPage; //# sourceMappingURL=PlaywrightBrowsingSessionWithPage.js.map