@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
39 lines • 1.58 kB
JavaScript
import { PlaywrightBrowsingSession } from './PlaywrightBrowsingSession.js';
/**
* @group Models
*/
export class PlaywrightBrowsingSessionWithBrowser extends PlaywrightBrowsingSession {
browser;
browserContextOptions;
constructor(browser, browserContextOptions, extraBrowserContextOptions, selectors) {
super(extraBrowserContextOptions, selectors);
this.browser = browser;
this.browserContextOptions = browserContextOptions;
}
async createBrowserContext() {
// todo: move to initialise?
return this.browser.newContext(this.browserContextOptions);
}
async registerCurrentPage() {
const context = await this.browserContext();
await context.newPage();
// calling context.newPage() triggers a callback registered via browserContext(),
// which wraps playwright.Page in PlaywrightPage and adds it to the list of pages
// returned by this.allPages()
const allPages = await this.allPages();
return allPages.at(-1);
}
async browserCapabilities() {
return {
browserName: this.browser._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()
};
}
async discard() {
await this.closeAllPages();
const context = await this.browserContext();
await context.close();
}
}
//# sourceMappingURL=PlaywrightBrowsingSessionWithBrowser.js.map