diff --git a/src/playwright/actions.ts b/src/playwright/actions.ts new file mode 100644 index 0000000..38613f7 --- /dev/null +++ b/src/playwright/actions.ts @@ -0,0 +1,32 @@ +import { Page } from 'playwright'; + +export interface Action { + type: string; + payload: Record; +} + +export class PlaywrightExecutor { + constructor(private page: Page) { } + + async execute(action: Action): Promise { + switch (action.type) { + case 'goto': + await this.page.goto(action.payload.url); + break; + case 'type': + await this.page.fill(action.payload.selector, action.payload.text); + break; + case 'click': + await this.page.click(action.payload.selector); + break; + case 'waitForLoad': + await this.page.waitForLoadState('networkidle'); + break; + case 'screenshot': + await this.page.screenshot({ path: action.payload.path }); + break; + default: + throw new Error(`未知动作: ${action.type}`); + } + } +} \ No newline at end of file