Files
Agent-Workbench/docs/model-selection-k-evidence/source-bytes/tests/fixtures/browser-project.mjs
T
2026-11-03 15:37:04 +08:00

27 lines
1.9 KiB
JavaScript

import fs from 'node:fs';
import path from 'node:path';
export function createBrowserProject(f, { extra = '', beginTask = true } = {}) {
const source = 'let done = false; document.querySelector("#toggle").addEventListener("click", () => { done = !done; document.querySelector("#state").textContent = done ? "已完成" : "待办"; });';
fs.mkdirSync(path.join(f.projectRoot, 'src'), { recursive: true }); fs.mkdirSync(path.join(f.projectRoot, 'dist'), { recursive: true });
fs.writeFileSync(path.join(f.projectRoot, 'src', 'app.js'), source + extra);
fs.writeFileSync(path.join(f.projectRoot, 'dist', 'app.js'), source + extra);
fs.writeFileSync(path.join(f.projectRoot, 'dist', 'index.html'), '<!doctype html><html lang="zh-CN"><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>工程页面</title>'
+ '<style>body{font:16px sans-serif;max-width:600px;margin:20px}input,select,button{display:block;margin:12px 0}</style>'
+ '<h1>实际浏览器样本</h1><label for="query">搜索任务</label><input id="query" aria-label="搜索任务"><select id="filter" aria-label="状态筛选"><option value="all">全部</option><option value="pending">待办</option></select>'
+ '<button id="toggle">切换状态</button><p id="state">待办</p><script src="/app.js"></script></html>');
if (beginTask) {
const run = f.store.beginRun(f.session, '检查这个工程实际页面', false, f.store.config);
f.session.status = 'paused'; f.store.finishRun(f.session, run, 'browser_ready');
}
return f;
}
export const browserSteps = [
{ action: 'fill', selector: '#query', value: '真实输入' },
{ action: 'select', selector: '#filter', value: 'pending' },
{ action: 'assert_count', selector: 'button', count: 1 },
{ action: 'assert_text', selector: '#state', text: '待办' },
{ action: 'click', selector: '#toggle' },
{ action: 'assert_text', selector: '#state', text: '已完成' },
];