UNPKG

e2ed

Version:

E2E testing framework over Playwright

29 lines (28 loc) 1.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getCookies = void 0; const useContext_1 = require("../useContext"); const log_1 = require("../utils/log"); /** * Returns page's cookies with the specified cookies parameters. * If there are no cookies parameters, returns all the cookies. */ const getCookies = async (cookiesParameters = {}) => { const page = (0, useContext_1.getPlaywrightPage)(); const parameters = Object.keys(cookiesParameters); const allCookies = await page.context().cookies(page.url()); if (parameters.length === 0) { (0, log_1.log)('Returns all the cookies from all pages', 5 /* LogEventType.InternalAction */); return allCookies; } (0, log_1.log)('Returns cookies with the specified cookies parameters', { allCookies, cookiesParameters }, 5 /* LogEventType.InternalAction */); return allCookies.filter((cookie) => { for (const parameter of parameters) { if (cookie[parameter] !== cookiesParameters[parameter]) { return false; } } return true; }); }; exports.getCookies = getCookies;