Skip to content

Commit 6ac5110

Browse files
authored
feat: add demo for yaml in agent (#30)
* feat: add demo for yaml in agent * feat: demo file
1 parent 0d19d8d commit 6ac5110

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

.github/workflows/puppeteer-demo.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ jobs:
3333
pnpm install
3434
pnpx puppeteer browsers install chrome
3535
pnpm run test
36+
pnpm run test-yaml
3637
continue-on-error: true
3738

3839
- name: Upload output folder

puppeteer-demo/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ npm install
2020

2121
# run demo.ts
2222
npx tsx demo.ts
23+
24+
# run demo with a `.runYaml` call
25+
npx tsx demo-run-yaml.ts
2326
```
2427

2528
# Reference

puppeteer-demo/demo-run-yaml.ts

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import puppeteer from "puppeteer";
2+
import os from "node:os";
3+
import { PuppeteerAgent } from "@midscene/web/puppeteer";
4+
import "dotenv/config";
5+
6+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
7+
Promise.resolve(
8+
(async () => {
9+
const browser = await puppeteer.launch({
10+
headless: true, // 'true' means we can't see the browser window
11+
args: ["--no-sandbox", "--disable-setuid-sandbox"],
12+
});
13+
14+
const page = await browser.newPage();
15+
await page.setViewport({
16+
width: 1280,
17+
height: 800,
18+
deviceScaleFactor: os.platform() === "darwin" ? 2 : 1, // this is used to avoid flashing on UI Mode when doing screenshot on Mac
19+
});
20+
21+
await page.goto("https://www.ebay.com");
22+
await sleep(5000);
23+
24+
const agent = new PuppeteerAgent(page);
25+
26+
// 👀 run YAML with agent
27+
const { result } = await agent.runYaml(`
28+
tasks:
29+
- name: search
30+
flow:
31+
- ai: input 'Headphones' in search box, click search button
32+
- sleep: 3000
33+
34+
- name: query
35+
flow:
36+
- aiQuery: "{itemTitle: string, price: Number}[], find item in list and corresponding price"
37+
name: headphones
38+
`);
39+
40+
console.log(result);
41+
42+
await browser.close();
43+
})()
44+
);

puppeteer-demo/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"main": "index.js",
77
"type": "module",
88
"scripts": {
9-
"test": "tsx demo.ts"
9+
"test": "tsx demo.ts",
10+
"test-yaml": "tsx demo-run-yaml.ts"
1011
},
1112
"author": "",
1213
"license": "MIT",

0 commit comments

Comments
 (0)