Skip to content

Commit 2a28472

Browse files
authored
feat: use different color for annotations (#366)
1 parent bdff171 commit 2a28472

File tree

187 files changed

+5849
-12643
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

187 files changed

+5849
-12643
lines changed

.github/workflows/ai-evaluation.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: AI unit test
2+
on:
3+
push:
4+
branches:
5+
- main
6+
workflow_dispatch:
7+
inputs:
8+
branch:
9+
description: 'Branch to checkout'
10+
required: false
11+
default: 'main'
12+
type: string
13+
14+
jobs:
15+
main:
16+
runs-on: ubuntu-22.04
17+
strategy:
18+
matrix:
19+
node-version: [18.19.0]
20+
21+
env:
22+
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
23+
OPENAI_BASE_URL: ${{ secrets.OPENAI_BASE_URL }}
24+
MIDSCENE_MODEL_NAME: gpt-4o-2024-11-20
25+
CI: 1
26+
27+
steps:
28+
- uses: actions/checkout@v4
29+
with:
30+
fetch-depth: 0
31+
ref: ${{ github.event.inputs.branch || 'main' }}
32+
33+
- name: Setup pnpm
34+
uses: pnpm/action-setup@v2
35+
with:
36+
version: 9.3.0
37+
38+
- name: Setup Node.js
39+
uses: actions/setup-node@v4
40+
with:
41+
node-version: '18'
42+
cache: 'pnpm'
43+
44+
- name: Install dependencies
45+
run: pnpm install --frozen-lockfile
46+
47+
- name: Build project
48+
run: pnpm run build
49+
50+
- name: Run evaluation
51+
run: |
52+
cd packages/evaluation
53+
pnpm run evaluate:inspect
54+
pnpm run evaluate:assertion

biome.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"**/playwright-report/**",
2222
"**/todo-report.spec.ts-snapshots/**",
2323
"**/visualizer/scripts/fixture/*",
24-
"**/unpacked-extension/*"
24+
"**/unpacked-extension/*",
25+
"**/page-data/**"
2526
]
2627
},
2728
"javascript": {

packages/evaluation/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
# Midscene.js dump files
3+
midscene_run/report
4+
midscene_run/tmp
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import type { PlayWrightAiFixtureType } from '@midscene/web';
2+
import { PlaywrightAiFixture } from '@midscene/web/playwright';
3+
import { test as base } from '@playwright/test';
4+
5+
export const test = base.extend<PlayWrightAiFixtureType>(PlaywrightAiFixture());
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { PlaywrightWebPage } from '@midscene/web/playwright';
2+
import { test } from './fixture';
3+
import { generateExtractData, generateTestDataPath } from './utils';
4+
5+
function sleep(time: number) {
6+
return new Promise((resolve) => {
7+
setTimeout(() => {
8+
resolve(0);
9+
}, time);
10+
});
11+
}
12+
13+
test('taobao', async ({ page, ai }) => {
14+
const playwrightPage = new PlaywrightWebPage(page);
15+
page.setViewportSize({ width: 1280, height: 800 });
16+
17+
await page.goto('https://www.taobao.com/');
18+
19+
// for --ui
20+
await sleep(5000);
21+
22+
await generateExtractData(playwrightPage, generateTestDataPath('taobao'));
23+
});

packages/web-integration/tests/ai/web/playwright/generate-test-data.spec.ts renamed to packages/evaluation/data-generator/generator-headless.spec.ts

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { generateExtractData, generateTestDataPath } from '@/debug';
2-
import { PlaywrightWebPage } from '@/playwright';
1+
import { PlaywrightWebPage } from '@midscene/web/playwright';
32
import { test } from './fixture';
3+
import { generateExtractData, generateTestDataPath } from './utils';
44

55
function sleep(time: number) {
66
return new Promise((resolve) => {
@@ -10,7 +10,7 @@ function sleep(time: number) {
1010
});
1111
}
1212

13-
test('generate todo test data', async ({ page }) => {
13+
test('todo app', async ({ page }) => {
1414
const playwrightPage = new PlaywrightWebPage(page);
1515
await page.goto('https://todomvc.com/examples/react/dist/');
1616
// Add data
@@ -33,7 +33,7 @@ test('generate todo test data', async ({ page }) => {
3333
);
3434
});
3535

36-
test('generate visualstudio test data', async ({ page }) => {
36+
test('visualstudio code', async ({ page }) => {
3737
const playwrightPage = new PlaywrightWebPage(page);
3838

3939
await page.goto('https://code.visualstudio.com/');
@@ -45,7 +45,7 @@ test('generate visualstudio test data', async ({ page }) => {
4545
);
4646
});
4747

48-
test('generate githubstatus test data', async ({ page }) => {
48+
test('github status page', async ({ page }) => {
4949
const playwrightPage = new PlaywrightWebPage(page);
5050

5151
await page.setViewportSize({ width: 1920, height: 1080 });
@@ -95,7 +95,7 @@ test('antd widget - carousel', async ({ page }) => {
9595
);
9696
});
9797

98-
test('generate online order test data', async ({ page, ai }) => {
98+
test('heytea online order', async ({ page, ai }) => {
9999
const playwrightPage = new PlaywrightWebPage(page);
100100

101101
page.setViewportSize({ width: 400, height: 905 });
@@ -109,7 +109,7 @@ test('generate online order test data', async ({ page, ai }) => {
109109
);
110110
});
111111

112-
test('generate online order list test data (zh-cn)', async ({ page, ai }) => {
112+
test('heytea online order list (zh-cn)', async ({ page, ai }) => {
113113
const playwrightPage = new PlaywrightWebPage(page);
114114

115115
page.setViewportSize({ width: 400, height: 905 });
@@ -127,19 +127,7 @@ test('generate online order list test data (zh-cn)', async ({ page, ai }) => {
127127
);
128128
});
129129

130-
test('generate taobao test data', async ({ page, ai }) => {
131-
const playwrightPage = new PlaywrightWebPage(page);
132-
page.setViewportSize({ width: 1280, height: 800 });
133-
134-
await page.goto('https://www.taobao.com/');
135-
136-
// for --ui
137-
await sleep(5000);
138-
139-
await generateExtractData(playwrightPage, generateTestDataPath('taobao'));
140-
});
141-
142-
test('generate douyin test data', async ({ page, ai }) => {
130+
test('douyin', async ({ page, ai }) => {
143131
const playwrightPage = new PlaywrightWebPage(page);
144132

145133
page.setViewportSize({ width: 1280, height: 800 });

packages/web-integration/src/debug/index.ts renamed to packages/evaluation/data-generator/utils.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1+
import assert from 'node:assert';
12
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
3+
import { NodeType } from '@midscene/shared/constants';
4+
25
import path from 'node:path';
3-
import type { WebPage } from '@/common/page';
46
import { descriptionOfTree } from '@midscene/core/tree';
5-
import { NodeType } from '@midscene/shared/constants';
6-
import type { ElementInfo } from '@midscene/shared/extractor';
77
import {
88
processImageElementInfo,
99
resizeImgBase64,
1010
saveBase64Image,
1111
} from '@midscene/shared/img';
12+
import type { WebPage } from '@midscene/web';
13+
14+
import type { ElementInfo } from '@midscene/shared/extractor';
1215

1316
export async function generateExtractData(
1417
page: WebPage,
@@ -109,13 +112,10 @@ export async function generateExtractData(
109112
}
110113

111114
export function generateTestDataPath(testDataName: string) {
112-
// `dist/lib/index.js` Is the default export path
113-
const modulePath = require
114-
.resolve('@midscene/core')
115-
.replace('dist/lib/index.js', '');
115+
assert(testDataName, 'testDataName is required');
116116
const midsceneTestDataPath = path.join(
117-
modulePath,
118-
`tests/ai/evaluate/test-data/${testDataName}`,
117+
__dirname,
118+
`../page-data/${testDataName}`,
119119
);
120120

121121
return midsceneTestDataPath;

packages/evaluation/package.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "evaluation",
3+
"private": true,
4+
"scripts": {
5+
"update-page-data:headless": "playwright test ./data-generator/generator-headless.spec.ts",
6+
"update-page-data:headed": "playwright test ./data-generator/generator-headed.spec.ts --headed",
7+
"evaluate:inspect": "npx vitest --run tests/llm-inspect.test.ts",
8+
"evaluate:inspect:update": "UPDATE_AI_DATA=true npm run evaluate:inspect",
9+
"evaluate:assertion": "npx vitest --run tests/assertion.test.ts",
10+
"evaluate:assertion:update": "UPDATE_AI_DATA=true npm run evaluate:assertion"
11+
},
12+
"dependencies": {
13+
"@midscene/core": "workspace:*",
14+
"@midscene/shared": "workspace:*",
15+
"@midscene/web": "workspace:*"
16+
},
17+
"devDependencies": {
18+
"dotenv": "16.4.5",
19+
"playwright": "1.44.1",
20+
"@playwright/test": "^1.44.1",
21+
"typescript": "~5.0.4",
22+
"vitest": "^1.6.0"
23+
},
24+
"engines": {
25+
"node": ">=18.0.0"
26+
},
27+
"publishConfig": {
28+
"access": "public",
29+
"registry": "https://registry.npmjs.org"
30+
},
31+
"license": "MIT"
32+
}

packages/midscene/tests/ai/evaluate/ai-data/assertion/online_order.json renamed to packages/evaluation/page-cases/assertion/online_order.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"testDataPath": "test-data/online_order",
2+
"testDataPath": "online_order",
33
"testCases": [
44
{
55
"prompt": "there are three tabs in the page, named 'Menu', 'Reviews', 'Merchant'",
@@ -26,4 +26,4 @@
2626
"expected": false
2727
}
2828
]
29-
}
29+
}

packages/midscene/tests/ai/evaluate/ai-data/inspect/aweme_login.json renamed to packages/evaluation/page-cases/inspect/aweme_login.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"testDataPath": "test-data/aweme-login",
2+
"testDataPath": "aweme-login",
33
"testCases": [
44
{
55
"prompt": "密码登录",
@@ -72,4 +72,4 @@
7272
]
7373
}
7474
]
75-
}
75+
}

0 commit comments

Comments
 (0)