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

45 lines 1.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PlaywrightCookie = void 0; const core_1 = require("@serenity-js/core"); const web_1 = require("@serenity-js/web"); const tiny_types_1 = require("tiny-types"); /** * Playwright-specific implementation of [`Cookie`](https://serenity-js.org/api/web/class/Cookie/). * * @group Models */ class PlaywrightCookie extends web_1.Cookie { context; constructor(context, cookieName) { super(cookieName); this.context = context; (0, tiny_types_1.ensure)('context', context, (0, tiny_types_1.isDefined)()); } async delete() { // see https://github.com/microsoft/playwright/issues/10143 const cookies = await this.context.cookies(); await this.context.clearCookies(); await this.context.addCookies(cookies.filter(cookie => cookie.name !== this.cookieName)); } async read() { const cookies = await this.context.cookies(); const found = cookies.find(cookie => cookie.name === this.cookieName); if (!found) { throw new web_1.CookieMissingError(`Cookie '${this.cookieName}' not set`); } return { name: found.name, value: found.value, domain: found.domain, path: found.path, expiry: typeof found.expires === 'number' && found.expires >= 0 ? core_1.Timestamp.fromTimestampInSeconds(Math.round(found.expires)) : undefined, httpOnly: found.httpOnly, secure: found.secure, }; } } exports.PlaywrightCookie = PlaywrightCookie; //# sourceMappingURL=PlaywrightCookie.js.map