|
1 | 1 | import puppeteer from 'puppeteer'; |
2 | | -import os from 'node:os'; |
3 | 2 | import { PuppeteerAgent } from '@midscene/web/puppeteer'; |
4 | 3 | import 'dotenv/config'; // read environment variables from .env file |
5 | 4 |
|
6 | 5 | const sleep = (ms: number | undefined) => new Promise((r) => setTimeout(r, ms)); |
7 | 6 | Promise.resolve( |
8 | 7 | (async () => { |
9 | 8 | const browser = await puppeteer.launch({ |
10 | | - headless: true, // 'true' means we can't see the browser window |
| 9 | + headless: false, // 'false' means we can see the browser window |
11 | 10 | args: ['--no-sandbox', '--disable-setuid-sandbox'], |
12 | 11 | }); |
13 | 12 |
|
14 | 13 | const page = await browser.newPage(); |
15 | 14 | await page.setViewport({ |
16 | 15 | width: 1280, |
17 | 16 | height: 768, |
18 | | - deviceScaleFactor: os.platform() === 'darwin' ? 2 : 1, // this is used to avoid flashing on UI Mode when doing screenshot on Mac |
| 17 | + deviceScaleFactor: 0 |
19 | 18 | }); |
20 | 19 |
|
21 | | - await page.goto('https://www.bing.com/shop'); |
| 20 | + await page.goto('https://www.bing.com'); |
22 | 21 | await sleep(5000); |
23 | 22 |
|
24 | 23 | // 👀 init Midscene agent |
25 | 24 | const agent = new PuppeteerAgent(page); |
26 | 25 |
|
27 | 26 | // 👀 type keywords, perform a search |
28 | | - await agent.aiAct('type "Headphones" in search box, hit Enter'); |
| 27 | + await agent.aiAct('type "Headphones Price" in search box, hit Enter'); |
29 | 28 |
|
30 | 29 | // 👀 wait for the loading |
31 | 30 | await agent.aiWaitFor('there is at least one headphone item on page'); |
@@ -55,14 +54,6 @@ Promise.resolve( |
55 | 54 | ); |
56 | 55 | console.log('name', name); |
57 | 56 |
|
58 | | - const location = await agent.aiLocate( |
59 | | - 'What is the location of the first headphone?' |
60 | | - ); |
61 | | - console.log('location', location); |
62 | | - |
63 | | - // 👀 assert by AI |
64 | | - await agent.aiAssert('There is a category filter on the left'); |
65 | | - |
66 | 57 | // 👀 click on the first item |
67 | 58 | await agent.aiTap('the first item in the list'); |
68 | 59 |
|
|
0 commit comments