|
| 1 | +import { |
| 2 | + HarmonyAgent, |
| 3 | + HarmonyDevice, |
| 4 | + getConnectedDevices, |
| 5 | +} from '@midscene/harmony'; |
| 6 | +import { beforeAll, describe, expect, it, vi } from 'vitest'; |
| 7 | +import 'dotenv/config'; |
| 8 | + |
| 9 | +const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms)); |
| 10 | + |
| 11 | +vi.setConfig({ |
| 12 | + testTimeout: 240 * 1000, |
| 13 | + hookTimeout: 240 * 1000, |
| 14 | +}); |
| 15 | + |
| 16 | +const pageUrl = 'https://todomvc.com/examples/react/dist/'; |
| 17 | + |
| 18 | +describe('Test todo list', () => { |
| 19 | + let agent: HarmonyAgent; |
| 20 | + |
| 21 | + beforeAll(async () => { |
| 22 | + const devices = await getConnectedDevices(); |
| 23 | + const device = new HarmonyDevice(devices[0].deviceId); |
| 24 | + agent = new HarmonyAgent(device); |
| 25 | + await device.connect(); |
| 26 | + await agent.aiAct(`open Browser and go to ${pageUrl}`); |
| 27 | + await sleep(3000); |
| 28 | + }); |
| 29 | + |
| 30 | + it( |
| 31 | + 'ai todo', |
| 32 | + async () => { |
| 33 | + await agent.aiAct( |
| 34 | + "type 'Study JS today' in the task box input and press the Enter key", |
| 35 | + ); |
| 36 | + await agent.aiAct( |
| 37 | + "type 'Study Rust tomorrow' in the task box input and press the Enter key", |
| 38 | + ); |
| 39 | + await agent.aiAct( |
| 40 | + "type 'Study AI the day after tomorrow' in the task box input and press the Enter key", |
| 41 | + ); |
| 42 | + await agent.aiAct( |
| 43 | + 'move the mouse to the second item in the task list and click the delete button on the right of the second task', |
| 44 | + ); |
| 45 | + await agent.aiAct( |
| 46 | + 'click the check button on the left of the second task', |
| 47 | + ); |
| 48 | + await agent.aiAct( |
| 49 | + "click the 'completed' status button below the task list", |
| 50 | + ); |
| 51 | + |
| 52 | + const list = await agent.aiQuery('string[], the complete task list'); |
| 53 | + expect(list.length).toEqual(1); |
| 54 | + |
| 55 | + await agent.aiAssert( |
| 56 | + 'Near the bottom of the list, there is a tip shows "1 item left".', |
| 57 | + ); |
| 58 | + |
| 59 | + const name = await agent.aiString( |
| 60 | + 'What is the name of the first todo?', |
| 61 | + ); |
| 62 | + console.log('name', name); |
| 63 | + |
| 64 | + const todoCount = await agent.aiNumber( |
| 65 | + 'How many todos are there in the list?', |
| 66 | + ); |
| 67 | + console.log('todoCount', todoCount); |
| 68 | + |
| 69 | + const isAllCompleted = await agent.aiBoolean( |
| 70 | + 'Is all todos completed?', |
| 71 | + ); |
| 72 | + console.log('isAllCompleted', isAllCompleted); |
| 73 | + |
| 74 | + const location = await agent.aiLocate( |
| 75 | + 'What is the location of the first todo?', |
| 76 | + ); |
| 77 | + console.log('location', location); |
| 78 | + }, |
| 79 | + 720 * 1000, |
| 80 | + ); |
| 81 | +}); |
0 commit comments