From cb4cccbfbc4851d7cac54e044eb1b6e14a118d5b Mon Sep 17 00:00:00 2001 From: "zhouxiao.shaw" Date: Thu, 22 Aug 2024 15:53:00 +0800 Subject: [PATCH] chore: add ai test --- .github/workflows/ai.yml | 5 ++- .../tests/ai/e2e/ai-auto-todo.spec.ts | 18 +++++++++ .../ai-todo-1-chromium-darwin.txt | 37 +++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 packages/web-integration/tests/ai/e2e/ai-auto-todo.spec.ts-snapshots/ai-todo-1-chromium-darwin.txt diff --git a/.github/workflows/ai.yml b/.github/workflows/ai.yml index 7b41009f..aeddcbf2 100644 --- a/.github/workflows/ai.yml +++ b/.github/workflows/ai.yml @@ -43,4 +43,7 @@ jobs: run: pnpm run build:pkg - name: Run tests - run: pnpm run test + run: pnpm run test:ai + + - name: Run e2e tests + run: pnpm run e2e diff --git a/packages/web-integration/tests/ai/e2e/ai-auto-todo.spec.ts b/packages/web-integration/tests/ai/e2e/ai-auto-todo.spec.ts index 56b097d5..4cf93ba1 100644 --- a/packages/web-integration/tests/ai/e2e/ai-auto-todo.spec.ts +++ b/packages/web-integration/tests/ai/e2e/ai-auto-todo.spec.ts @@ -1,3 +1,4 @@ +import path from 'node:path'; import { expect } from 'playwright/test'; import { test } from './fixture'; @@ -5,6 +6,23 @@ test.beforeEach(async ({ page }) => { await page.goto('https://todomvc.com/examples/react/dist/'); }); +test.afterEach(async ({ page, ai, aiAssert }) => { + await page.goto( + `file://${path.join(__dirname, '../../../midscene_run/report/latest-playwright-report.html')}`, + ); + const actionsList = await ai( + 'Sidebar task list Array<{title: string, actions: Array}>', + { + type: 'query', + }, + ); + const parseList = JSON.stringify(actionsList, null, 4); + expect(parseList).toMatchSnapshot(); + await aiAssert( + 'On the left taskbar, check whether the specific execution content of the right task is normal', + ); +}); + test('ai todo', async ({ ai, aiQuery, aiWaitFor }) => { await ai( 'Enter "Learn JS today" in the task box, then press Enter to create', diff --git a/packages/web-integration/tests/ai/e2e/ai-auto-todo.spec.ts-snapshots/ai-todo-1-chromium-darwin.txt b/packages/web-integration/tests/ai/e2e/ai-auto-todo.spec.ts-snapshots/ai-todo-1-chromium-darwin.txt new file mode 100644 index 00000000..1e327fda --- /dev/null +++ b/packages/web-integration/tests/ai/e2e/ai-auto-todo.spec.ts-snapshots/ai-todo-1-chromium-darwin.txt @@ -0,0 +1,37 @@ +{ + "Sidebar task list": [ + { + "title": "Enter \"Learn JS today\" in the task box, then press Enter to create", + "actions": [ + "Planning", + "Insight / Locate", + "Action / Input", + "Action / KeyboardPress" + ] + }, + { + "title": "waitFor: the input box for task title is empty now", + "actions": [ + "Insight / Assert" + ] + }, + { + "title": "Enter \"Learn Rust tomorrow\" in the task box, then press Enter to create", + "actions": [ + "Planning", + "Insight / Locate", + "Action / Input", + "Action / KeyboardPress" + ] + }, + { + "title": "Enter \"Learning AI the day after tomorrow\" in the task box, then press Enter to create", + "actions": [ + "Planning", + "Insight / Locate", + "Action / Input", + "Action / KeyboardPress" + ] + } + ] +} \ No newline at end of file