Skip to content

Commit 8a9c40a

Browse files
authored
fix(core): update test cases (#804)
1 parent 548a980 commit 8a9c40a

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

packages/web-integration/tests/ai/web/playwright/ai-online-order.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ test('ai online order', async ({ ai, page, aiQuery }) => {
2020
await ai('点击标准甜、点击绿妍(推荐),点击标准口味');
2121
await ai('滚动到最下面');
2222
await ai('点击页面下边的“选好了”按钮');
23+
await sleep(2000);
2324
await ai('点击屏幕右上角购物袋按钮');
2425

2526
const cardDetail = await aiQuery({
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import path from 'node:path';
2+
import { PuppeteerAgent } from '@/puppeteer';
3+
import { sleep } from '@midscene/core/utils';
4+
import { vlLocateMode } from '@midscene/shared/env';
5+
import { afterEach, describe, expect, it, vi } from 'vitest';
6+
import { launchPage } from './utils';
7+
8+
describe(
9+
'puppeteer integration - query',
10+
() => {
11+
let resetFn: () => Promise<void>;
12+
afterEach(async () => {
13+
if (resetFn) {
14+
try {
15+
await resetFn();
16+
} catch (e) {
17+
console.warn('resetFn error');
18+
console.warn(e);
19+
}
20+
}
21+
});
22+
23+
it('query by DOM', async () => {
24+
const { originPage, reset } = await launchPage(
25+
'https://www.saucedemo.com/',
26+
{
27+
viewport: {
28+
width: 1024,
29+
height: 400,
30+
},
31+
},
32+
);
33+
resetFn = reset;
34+
const agent = new PuppeteerAgent(originPage);
35+
36+
await agent.aiAction(
37+
'type "standard_user" in user name input, type "secret_sauce" in password, click login',
38+
);
39+
40+
// find the items
41+
const items = await agent.aiQuery(
42+
'{name: string, price: number, actionBtnName: string, imageUrl: string}[], return item name, price and the action button name on the lower right corner of each item, and the image url of each item (like "Remove")',
43+
{ domIncluded: true, screenshotIncluded: false },
44+
);
45+
46+
expect(items.length).toBeGreaterThan(4); // only 1 items show in the viewport, but we should get more from the DOM
47+
});
48+
},
49+
4 * 60 * 1000,
50+
);

0 commit comments

Comments
 (0)