mirror of
https://github.com/web-infra-dev/midscene.git
synced 2025-12-08 04:52:00 +00:00
* feat(playwright): add aiTap/aiInput and other AI actions for Playwright integration * chore: update doc --------- Co-authored-by: yutao <yutao.tao@bytedance.com>
41 lines
960 B
TypeScript
41 lines
960 B
TypeScript
import { AiAssert } from '@midscene/core/.';
|
|
import { expect } from 'playwright/test';
|
|
import { test } from './fixture';
|
|
|
|
test.beforeEach(async ({ page }) => {
|
|
await page.goto('https://www.saucedemo.com/');
|
|
await page.setViewportSize({ width: 1920, height: 1080 });
|
|
});
|
|
|
|
const CACHE_TIME_OUT = process.env.MIDSCENE_CACHE;
|
|
|
|
test('ai shop', async ({
|
|
ai,
|
|
aiInput,
|
|
aiAssert,
|
|
aiQuery,
|
|
aiTap,
|
|
generateMidsceneAgent,
|
|
page,
|
|
}) => {
|
|
if (CACHE_TIME_OUT) {
|
|
test.setTimeout(1000 * 1000);
|
|
}
|
|
// login
|
|
const agent = await generateMidsceneAgent(page);
|
|
await aiInput('standard_user', 'in user name input');
|
|
await aiInput('secret_sauce', 'in password input');
|
|
await agent.aiTap('Login Button');
|
|
|
|
// check the login success
|
|
await aiAssert('the page title is "Swag Labs"');
|
|
|
|
// add to cart
|
|
await aiTap('"add to cart" for black t-shirt products');
|
|
|
|
await aiTap({
|
|
prompt: 'click right top cart icon',
|
|
deepThink: true,
|
|
});
|
|
});
|