export interface BenchmarkCommand { id: string; action: string; [key: string]: unknown; } export interface Scenario { name: string; description: string; /** Commands to run once before measured iterations (e.g. navigate to a page). */ setup?: BenchmarkCommand[]; /** The commands whose total execution time is measured per iteration. */ commands: BenchmarkCommand[]; /** Commands to run once after measured iterations (e.g. cleanup). */ teardown?: BenchmarkCommand[]; } const FORM_HTML = [ "Bench", "

Benchmark Page

", "", "", "", "", "", "", "

Ready

", "Click me", "", "", ].join(""); const INJECT_FORM: BenchmarkCommand = { id: "inject", action: "evaluate", script: `document.open(); document.write(${JSON.stringify(FORM_HTML)}); document.close(); 'ok'`, }; const SETUP_PAGE: BenchmarkCommand[] = [ { id: "setup-nav", action: "navigate", url: "about:blank", waitUntil: "domcontentloaded" }, INJECT_FORM, ]; export const scenarios: Scenario[] = [ { name: "navigate", description: "Page navigation (about:blank round-trip)", commands: [ { id: "nav", action: "navigate", url: "about:blank", waitUntil: "domcontentloaded" }, ], }, { name: "snapshot", description: "DOM snapshot (accessibility tree)", setup: SETUP_PAGE, commands: [ { id: "snap", action: "snapshot" }, ], }, { name: "screenshot", description: "Screenshot capture", setup: SETUP_PAGE, commands: [ { id: "ss", action: "screenshot" }, ], }, { name: "evaluate", description: "JavaScript evaluation", setup: SETUP_PAGE, commands: [ { id: "eval", action: "evaluate", script: "document.title + ' ' + document.querySelectorAll('li').length" }, ], }, { name: "click", description: "Element click interaction", setup: SETUP_PAGE, commands: [ { id: "clk", action: "click", selector: "#link" }, ], }, { name: "fill", description: "Form field fill", setup: SETUP_PAGE, commands: [ { id: "fill", action: "fill", selector: "#name", value: "Benchmark User" }, ], }, { name: "tabs", description: "Tab new + list + switch", commands: [ { id: "tnew", action: "tab_new", url: "about:blank" }, { id: "tlist", action: "tab_list" }, { id: "tswitch", action: "tab_switch", index: 0 }, ], teardown: [ { id: "tclose", action: "tab_close", index: 1 }, ], }, { name: "full-workflow", description: "Realistic agent workflow: navigate, snapshot, click, fill, evaluate, screenshot", commands: [ { id: "w-nav", action: "navigate", url: "about:blank", waitUntil: "domcontentloaded" }, INJECT_FORM, { id: "w-snap", action: "snapshot" }, { id: "w-click", action: "click", selector: "#link" }, { id: "w-fill", action: "fill", selector: "#name", value: "Agent User" }, { id: "w-eval", action: "evaluate", script: "document.getElementById('name').value" }, { id: "w-ss", action: "screenshot" }, ], }, ];