playwright-json-runner
Version:
Extends Playwright to run tests using JSON-based test definitions.
54 lines (53 loc) • 2.42 kB
JavaScript
import { test_exports, executeAction, getConfiguration } from './chunk-HUKYBBJG.mjs';
import './chunk-KTR6D2I2.mjs';
import { readFileSync } from 'fs';
import { globSync } from 'glob';
import path from 'path';
function loadTestFiles() {
const config2 = getConfiguration();
const finalGlobPattern = `**/${config2.jsonTestDir}/${config2.jsonTestMatch}`;
console.log("Glob pattern to find test files: ", finalGlobPattern);
const jsonFiles2 = globSync(finalGlobPattern, { cwd: config2.configDir, absolute: true });
console.log("Found ", jsonFiles2 == null ? void 0 : jsonFiles2.length, " Files.");
return { jsonFiles: jsonFiles2, config: config2 };
}
function resolveSnapshotDir(config2) {
var _a2;
const dir = config2.snapshotDir;
if (path.isAbsolute(dir)) return dir;
return path.join((_a2 = config2.configDir) != null ? _a2 : process.cwd(), dir);
}
var { jsonFiles, config } = loadTestFiles();
var _a;
for (const testFilePath of jsonFiles) {
const testRun = JSON.parse(readFileSync(testFilePath, "utf-8"));
for (const scenario of testRun.scenarios) {
(0, test_exports.test)((_a = scenario.label) != null ? _a : scenario.name, async ({ page }, testInfo) => {
var _a2, _b, _c;
const userSetSnapshotDir = testInfo.project.snapshotDir !== testInfo.project.testDir;
if (!userSetSnapshotDir) {
testInfo.project.snapshotDir = resolveSnapshotDir(config);
testInfo._projectInternal.snapshotPathTemplate = "{snapshotDir}/{arg}{-projectName}{-snapshotSuffix}{ext}";
}
let idx = 0;
await page.goto(testRun.host);
console.log(`\u{1F4CC} Executing scenario: ${(_a2 = scenario.label) != null ? _a2 : scenario.name}`);
for (const step of scenario.steps) {
console.log(` \u{1F6E0} Step: ${(_b = step.label) != null ? _b : step.description}`);
await test_exports.test.step((_c = step.label) != null ? _c : step.description, async () => {
for (const action of step.actions) {
try {
await page.evaluate((id) => console.log(`JSONIDX:${id}:START`), idx);
await executeAction(config, page, action);
await page.evaluate((id) => console.log(`JSONIDX:${id}:END`), idx);
} finally {
idx++;
}
}
});
}
});
}
}
//# sourceMappingURL=runner-playwright.mjs.map
//# sourceMappingURL=runner-playwright.mjs.map