51 lines
1.1 KiB
JavaScript
51 lines
1.1 KiB
JavaScript
//@5
|
|
/*
|
|
Consumes : `action-tests.json`
|
|
Writes to : [console]
|
|
*/
|
|
|
|
// test-executor.js
|
|
console.log("Loading: test-executor.js");
|
|
|
|
import fs from "fs";
|
|
import { chromium } from "playwright";
|
|
|
|
const tests = JSON.parse(fs.readFileSync("./action-tests.json", "utf8")).actionTests;
|
|
|
|
function normalizeValue(value) {
|
|
if (typeof value === "string" && value.startsWith("crawl_")) {
|
|
return value.replace(/^crawl_/, "");
|
|
}
|
|
return value;
|
|
}
|
|
|
|
(async () => {
|
|
const browser = await chromium.launch({ headless: false });
|
|
const page = await browser.newPage();
|
|
|
|
for (const test of tests) {
|
|
try {
|
|
await page.goto(test.url, { waitUntil: "networkidle" });
|
|
|
|
if (test.type === "input") {
|
|
const value = normalizeValue(test.value);
|
|
await page.waitForSelector(test.selector);
|
|
await page.fill(test.selector, value);
|
|
}
|
|
|
|
if (test.type === "click") {
|
|
await page.waitForSelector(test.selector);
|
|
await page.click(test.selector);
|
|
}
|
|
|
|
console.log("✓", test.type.toUpperCase(), test.selector);
|
|
|
|
} catch (err) {
|
|
console.error("✗ Test failed:", test, err);
|
|
}
|
|
}
|
|
|
|
await browser.close();
|
|
})();
|
|
|