UNPKG

playwright-cucumber-ts-steps

Version:

A collection of reusable Playwright step definitions for Cucumber in TypeScript, designed to streamline end-to-end testing across web, API, and mobile applications.

41 lines (40 loc) 1.5 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.injectStorage = injectStorage; exports.saveSessionData = saveSessionData; //sessionUtils.ts const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); async function injectStorage(world, type, key, value) { const page = world.page; if (type === "localStorage") { await page.evaluate(([k, v]) => localStorage.setItem(k, v), [key, value]); } else if (type === "sessionStorage") { await page.evaluate(([k, v]) => sessionStorage.setItem(k, v), [key, value]); } else if (type === "cookie") { await page.context.addCookies([ { name: key, value, domain: new URL(page.url()).hostname, path: "/", httpOnly: false, secure: true, sameSite: "Lax", }, ]); } } async function saveSessionData(context, file) { const storageState = await context.storageState(); const outDir = "test-artifacts/auth-cookies"; const outPath = path_1.default.resolve(outDir, file); fs_1.default.mkdirSync(outDir, { recursive: true }); fs_1.default.writeFileSync(outPath, JSON.stringify(storageState, null, 2)); console.log(`💾 Saved session to ${outPath}`); }