2025-04-03 10:28:40 +08:00
|
|
|
import { sleep } from '@midscene/core/utils';
|
2025-03-25 22:45:05 +08:00
|
|
|
import { beforeAll, describe, expect, it, vi } from 'vitest';
|
2025-04-03 10:28:40 +08:00
|
|
|
import { AndroidAgent, AndroidDevice, getConnectedDevices } from '../../src';
|
2025-03-25 22:45:05 +08:00
|
|
|
|
|
|
|
vi.setConfig({
|
|
|
|
testTimeout: 240 * 1000,
|
|
|
|
});
|
|
|
|
|
|
|
|
const pageUrl = 'https://todomvc.com/examples/react/dist/';
|
|
|
|
|
|
|
|
describe('Test todo list', () => {
|
|
|
|
let agent: AndroidAgent;
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
2025-04-03 10:28:40 +08:00
|
|
|
const devices = await getConnectedDevices();
|
|
|
|
const page = new AndroidDevice(devices[0].udid);
|
2025-04-17 17:44:11 +08:00
|
|
|
agent = new AndroidAgent(page, {
|
|
|
|
aiActionContext:
|
|
|
|
'If any location, permission, user agreement, etc. popup, click agree. If login page pops up, close it.',
|
|
|
|
});
|
2025-04-03 10:28:40 +08:00
|
|
|
await page.connect();
|
|
|
|
await page.launch(pageUrl);
|
|
|
|
await sleep(3000);
|
2025-03-25 22:45:05 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it(
|
|
|
|
'ai todo',
|
|
|
|
async () => {
|
|
|
|
await agent.aiAction(
|
|
|
|
"type 'Study JS today' in the task box input and press the Enter key",
|
|
|
|
);
|
|
|
|
await agent.aiAction(
|
|
|
|
"type 'Study Rust tomorrow' in the task box input and press the Enter key",
|
|
|
|
);
|
|
|
|
await agent.aiAction(
|
|
|
|
"type 'Study AI the day after tomorrow' in the task box input and press the Enter key",
|
|
|
|
);
|
|
|
|
await agent.aiAction(
|
|
|
|
'move the mouse to the second item in the task list and click the delete button on the right of the second task',
|
|
|
|
);
|
|
|
|
await agent.aiAction(
|
|
|
|
'click the check button on the left of the second task',
|
|
|
|
);
|
|
|
|
await agent.aiAction(
|
|
|
|
"click the 'completed' status button below the task list",
|
|
|
|
);
|
|
|
|
|
|
|
|
const list = await agent.aiQuery('string[], the complete task list');
|
|
|
|
expect(list.length).toEqual(1);
|
|
|
|
|
|
|
|
await agent.aiAssert(
|
|
|
|
'Near the bottom of the list, there is a tip shows "1 item left".',
|
|
|
|
);
|
|
|
|
},
|
|
|
|
720 * 1000,
|
|
|
|
);
|
|
|
|
});
|