@serenity-js/webdriverio
Version:
Adapter that integrates @serenity-js/web with the latest stable version of WebdriverIO, enabling Serenity/JS reporting and using the Screenplay Pattern to write web and mobile test scenarios
46 lines • 1.78 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.WebdriverIOCookie = void 0;
require("webdriverio");
const core_1 = require("@serenity-js/core");
const web_1 = require("@serenity-js/web");
const tiny_types_1 = require("tiny-types");
/**
* WebdriverIO-specific implementation of [`Cookie`](https://serenity-js.org/api/web/class/Cookie/).
*
* @group Models
*/
class WebdriverIOCookie extends web_1.Cookie {
browser;
constructor(browser, cookieName) {
super(cookieName);
this.browser = browser;
(0, tiny_types_1.ensure)('browser', browser, (0, tiny_types_1.isDefined)());
}
async delete() {
await this.browser.deleteCookies(this.cookieName);
}
async read() {
const [cookie] = await this.browser.getCookies(this.cookieName);
if (!cookie) {
throw new web_1.CookieMissingError(`Cookie '${this.cookieName}' not set`);
}
// There _might_ be a bug in WDIO where the expiry date is set on "expires" rather than the "expiry" key
// and possibly another one around deserialising the timestamp, since WDIO seems to add several hundred milliseconds
// to the original expiry date
const expiry = cookie.expiry || cookie.expires;
return {
name: cookie.name,
value: cookie.value,
domain: cookie.domain,
path: cookie.path,
expiry: typeof expiry === 'number' && expiry >= 0
? core_1.Timestamp.fromTimestampInSeconds(Math.round(expiry))
: undefined,
httpOnly: cookie.httpOnly,
secure: cookie.secure,
};
}
}
exports.WebdriverIOCookie = WebdriverIOCookie;
//# sourceMappingURL=WebdriverIOCookie.js.map