@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
107 lines • 4.15 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.SelfLaunchingPlaywrightBrowsingSessionWithElectron = void 0;
const playwright = __importStar(require("playwright-core"));
const PlaywrightBrowsingSessionWithElectron_js_1 = require("./PlaywrightBrowsingSessionWithElectron.js");
/**
* Self-launching implementation of [`PlaywrightBrowsingSession`](https://serenity-js.org/api/playwright/class/PlaywrightBrowsingSession/)
* for Electron applications.
*
* This class launches the Electron application on first use and closes it when discarded.
* Use this for test runners like Mocha or Jasmine that don't manage Electron lifecycle.
*
* ## Example
*
* ```typescript
* import { actorCalled } from '@serenity-js/core';
* import { BrowseTheWebWithPlaywright } from '@serenity-js/playwright';
*
* const actor = actorCalled('Tester').whoCan(
* BrowseTheWebWithPlaywright.launchingElectronApp({
* args: ['path/to/main.js'],
* cwd: 'path/to/app',
* })
* );
*
* // The app is automatically closed when the actor is dismissed
* ```
*
* @group Models
*/
class SelfLaunchingPlaywrightBrowsingSessionWithElectron extends PlaywrightBrowsingSessionWithElectron_js_1.PlaywrightBrowsingSessionWithElectron {
launchOptions;
constructor(launchOptions, extraBrowserContextOptions, selectors) {
// setting electronApp to undefined since it's lazily initialised
super(undefined, extraBrowserContextOptions, selectors);
this.launchOptions = launchOptions;
}
/**
* Launches the Electron application using the configured launch options.
*
* This method is idempotent - calling it multiple times will only launch
* the application once.
*/
async initialise() {
if (this.electronApp) {
return;
}
this.electronApp = await playwright._electron.launch(this.launchOptions);
this.currentBrowserPage = await this.registerCurrentPage();
}
/**
* Returns `true` if the Electron application has been launched.
*/
isInitialised() {
return this.electronApp !== undefined;
}
/**
* Closes the Electron application that was launched by this session.
* Called when the ability is discarded.
*/
async closeElectronApp() {
if (this.electronApp) {
await this.electronApp.close();
this.electronApp = undefined;
}
}
async discard() {
await this.closeElectronApp();
this.pages.clear();
this.currentBrowserPage = undefined;
}
}
exports.SelfLaunchingPlaywrightBrowsingSessionWithElectron = SelfLaunchingPlaywrightBrowsingSessionWithElectron;
//# sourceMappingURL=SelfLaunchingPlaywrightBrowsingSessionWithElectron.js.map