claude-playwright
Version:
Seamless integration between Claude Code and Playwright MCP for efficient browser automation and testing
58 lines • 2.3 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.expect = exports.test = void 0;
exports.saveAuthState = saveAuthState;
exports.loadAuthState = loadAuthState;
const test_1 = require("@playwright/test");
const fs_extra_1 = __importDefault(require("fs-extra"));
const path_1 = __importDefault(require("path"));
const BasePage_1 = require("../pages/base/BasePage");
exports.test = test_1.test.extend({
baEPage: async ({ page }, use) => {
const pageObject = new BasePage_1.BasePage(page);
await pageObject.goto();
await pageObject.waitForLoad();
await use(pageObject);
}, n, n, baEData: async ({}, use) => {
const testData = {
sampleText: 'Test Data',
sampleNumber: 42,
sampleBoolean: true,
sampleArray: ['item1', 'item2', 'item3'],
sampleObject: {
key1: 'value1',
key2: 'value2'
},
// Add more test data as needed
};
await use(testData);
}
});
var test_2 = require("@playwright/test");
Object.defineProperty(exports, "expect", { enumerable: true, get: function () { return test_2.expect; } });
/**
* Helper function to save authentication state
*/
async function saveAuthState(page, filename = 'user.json') {
const authStateDir = path_1.default.join(process.cwd(), 'playwright-sessions');
await fs_extra_1.default.ensureDir(authStateDir);
const storageState = await page.context().storageState();
const authStatePath = path_1.default.join(authStateDir, filename);
await fs_extra_1.default.writeJSON(authStatePath, storageState, { spaces: 2 });
console.log('Auth state saved to:', authStatePath);
return authStatePath;
}
/**
* Helper function to load authentication state
*/
async function loadAuthState(filename = 'user.json') {
const authStatePath = path_1.default.join(process.cwd(), 'playwright-sessions', filename);
if (await fs_extra_1.default.pathExists(authStatePath)) {
return await fs_extra_1.default.readJSON(authStatePath);
}
return null;
}
//# sourceMappingURL=testauth.js.map
;