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

51 lines 2.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PlaywrightBrowsingSessionWithPage = void 0; const model_1 = require("@serenity-js/core/model"); const PlaywrightBrowsingSession_js_1 = require("./PlaywrightBrowsingSession.js"); const PlaywrightPage_js_1 = require("./PlaywrightPage.js"); /** * @group Models */ class PlaywrightBrowsingSessionWithPage extends PlaywrightBrowsingSession_js_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_js_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() }; } async discard() { await this.closeAllPages(); } } exports.PlaywrightBrowsingSessionWithPage = PlaywrightBrowsingSessionWithPage; //# sourceMappingURL=PlaywrightBrowsingSessionWithPage.js.map