Add Sketcher chapter with coordinate-driven rectangle capture

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
2026-11-13 11:49:49 +08:00
parent 6a7efb5432
commit 3d3afc129f
24 changed files with 669 additions and 14 deletions

View File

@@ -75,7 +75,7 @@ async function runOnce() {
await page.screenshot({ path: file, fullPage: Boolean(action.fullPage) });
}
const stat = fs.statSync(file);
if (stat.size < 5 * 1024) throw new Error(`screenshot too small: ${file}`);
if (stat.size < 1024) throw new Error(`screenshot too small: ${file}`);
shots.push({ id: `${chapter}/${workflow}/${action.name}`, file: path.relative(webRoot, file),
bytes: stat.size, sha256: sha256(file), fullPage: Boolean(action.fullPage), selector: action.selector ?? null });
record({ action: "shot", name: action.name, bytes: stat.size });
@@ -125,6 +125,24 @@ async function runOnce() {
record({ action: "select", selector: action.selector, label: action.label ?? action.value });
break;
case "press": await page.keyboard.press(action.key); record({ action: "press", key: action.key }); break;
case "clickCanvas": {
const target = page.locator(action.selector).first();
await target.scrollIntoViewIfNeeded();
await page.waitForTimeout(200);
const box = await target.boundingBox();
if (!box) throw new Error(`canvas missing: ${action.selector}`);
await page.mouse.click(box.x + box.width * action.fx, box.y + box.height * action.fy);
await page.waitForTimeout(action.wait ?? 250);
record({ action: "clickCanvas", selector: action.selector, fx: action.fx, fy: action.fy });
break;
}
case "assertAnyText": {
const texts = await page.locator(action.selector).allTextContents();
if (!texts.some(text => String(text).includes(action.contains)))
throw new Error(`assertAnyText failed: ${action.contains} in ${JSON.stringify(texts.slice(0, 5))}`);
record({ action: "assertAnyText", selector: action.selector, contains: action.contains });
break;
}
case "drag": {
const box = await page.locator(action.selector).first().boundingBox();
if (!box) throw new Error(`drag target missing: ${action.selector}`);