Skip to content

Commit 1d9162b

Browse files
authored
feat: add demo for yaml style automation (#13)
* feat: add demo for yaml scripts * feat: add demo for yaml scripts * feat: update yaml demo * feat: add github actions
1 parent fe8f35a commit 1d9162b

19 files changed

+160
-126
lines changed

.github/workflows/command-line-demo.yaml .github/workflows/yaml-scripts-demo.yaml

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Command Line Demo
1+
name: Yaml Scripts Demo
22

33
on:
44
workflow_dispatch:
@@ -10,7 +10,7 @@ on:
1010
output_folder:
1111
description: 'Midscene report directory'
1212
required: true
13-
default: 'command-line/midscene_run/report/'
13+
default: 'yaml-scripts/midscene_run/report/'
1414
push:
1515
branches:
1616
- main
@@ -29,13 +29,8 @@ jobs:
2929
MIDSCENE_DEBUG_AI_PROFILE: 1
3030
run: |
3131
npm i -g @midscene/cli@${{ github.event.inputs.tag }}
32-
cd command-line
33-
echo "Run sauce-demo.sh"
34-
./sauce-demo.sh
35-
echo "Run extract-github-status.sh"
36-
./extract-github-status.sh
37-
echo "Run local-static-server.sh"
38-
./local-static-server.sh
32+
cd yaml-scripts
33+
midscene ./midscene-scripts/
3934
4035
- name: List directory contents
4136
run: ls -R ${{ github.workspace }}

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ Examples for [Midscene](https://github.com/web-infra-dev/midscene).
66

77
Here are some examples you can refer to:
88

9-
- [Playwright-demo](./playwright-demo/): Integrate Midscene with Playwright, including ai action, query ,cache, and report.
10-
- [Puppeteer-demo](./puppeteer-demo/): Integrate Midscene with Puppeteer, including ai action, query, cache, and report.
11-
- [Command Line](./command-line/): Using Midscene as a command line tool.
9+
- [Automate with Scripts in YAML](./yaml-scripts-demo/): Automate with scripts in YAML. This is the easiest way to integrate Midscene with your existing project.
10+
- [Integrate with Playwright](./playwright-demo/): Integrate Midscene with Playwright, including ai action, query ,cache, and report.
11+
- [Integrate with Puppeteer](./puppeteer-demo/): Integrate Midscene with Puppeteer, including ai action, query, cache, and report.

command-line/README.md

-46
This file was deleted.

command-line/extract-github-status.sh

-10
This file was deleted.

command-line/local-static-server.sh

-11
This file was deleted.

command-line/sauce-demo-expect-fail.sh

-15
This file was deleted.

command-line/sauce-demo.sh

-15
This file was deleted.

command-line/search-headphone-on-ebay.sh

-13
This file was deleted.

playwright-demo/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
"devDependencies": {
1414
"@midscene/web": "0.8.4",
1515
"@playwright/test": "1.48.0",
16-
"@types/jest": "~29.5.13",
17-
"@types/node": "~22.7.5",
16+
"@types/jest": "~29.5.14",
17+
"@types/node": "~22.7.9",
1818
"dotenv": "16.4.5",
1919
"eslint-plugin-prettier": "~5.2.1",
2020
"rimraf": "~6.0.1",

puppeteer-demo/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
package-lock.json
12

23
# Midscene.js dump files
34
midscene_run/midscene-report

puppeteer-demo/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"test": "tsx demo.ts"
1010
},
1111
"author": "",
12-
"license": "ISC",
12+
"license": "MIT",
1313
"devDependencies": {
1414
"@midscene/web": "latest",
1515
"puppeteer": "^23.4.0",
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
*.json
1+
output/
2+
package-lock.json
23

34
# Midscene.js dump files
45
midscene_run/report
56
midscene_run/dump
7+
midscene_run/tmp

yaml-scripts-demo/README.md

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Yaml Scripts
2+
3+
## Preparation
4+
5+
Ensure that Node.js is installed. Install the `@midscene/cli` globally
6+
7+
```shell
8+
npm i -g @midscene/cli
9+
```
10+
11+
Config the API key
12+
13+
```shell
14+
# replace by your own
15+
export OPENAI_API_KEY="sk-abcdefghijklmnopqrstuvwxyz"
16+
```
17+
18+
## Run
19+
20+
Run all scripts
21+
22+
```shell
23+
midscene ./midscene-scripts/
24+
```
25+
26+
Extract status info from github status page
27+
28+
```shell
29+
midscene ./midscene-scripts/extract-github-status.yaml
30+
```
31+
32+
Perform a testing case on sauce demo
33+
34+
```shell
35+
midscene ./midscene-scripts/sauce-demo.yaml
36+
```
37+
38+
Perform a search on ebay.com
39+
40+
```shell
41+
midscene ./midscene-scripts/search-headphone-on-ebay.yaml
42+
```
43+
44+
Serve the `server_root` folder as a static server and test the `index.html` file
45+
46+
```shell
47+
midscene ./midscene-scripts/local-static-server.yml
48+
```
49+
50+
## Debug
51+
52+
Run a script with headed mode (i.e. you can see the browser window when running)
53+
54+
```shell
55+
midscene --headed ./midscene-scripts/sauce-demo.yaml
56+
```
57+
58+
Keep the browser window open after the script finishes
59+
60+
```shell
61+
midscene --keep-open ./midscene-scripts/sauce-demo.yaml
62+
```
63+
64+
# Reference
65+
66+
https://midscenejs.com/automate-with-scripts-in-yaml.html
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
target:
2+
url: https://www.githubstatus.com/
3+
output: ./output/github-status.json
4+
5+
tasks:
6+
- name: extract github status
7+
flow:
8+
- aiQuery: >
9+
{name: string, status: string}[], service status of github page
10+
name: status
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# serve a local static server and assert the button text
2+
3+
target:
4+
serve: ./public
5+
url: index.html
6+
7+
tasks:
8+
- name: assert button text
9+
flow:
10+
- aiAssert: The button text is 'Start'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# login to sauce demo, extract the items info into a json file, and assert the price of 'Sauce Labs Fleece Jacket'
2+
3+
target:
4+
url: https://www.saucedemo.com/
5+
output: ./output/sauce-demo-items.json
6+
7+
tasks:
8+
- name: login
9+
flow:
10+
- aiAction: type 'standard_user' in user name input, type 'secret_sauce' in password, click 'Login'
11+
12+
- name: extract items info
13+
flow:
14+
- aiQuery: >
15+
{name: string, price: number, actionBtnName: string}[], return item name, price and the action button name on the lower right corner of each item (like 'Remove')
16+
name: items
17+
- aiAssert: The price of 'Sauce Labs Fleece Jacket' is 49.99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# search headphone on ebay, extract the items info into a json file, and assert the shopping cart icon
2+
3+
target:
4+
url: https://www.ebay.com
5+
# emulate a mobile device
6+
viewportWidth: 400
7+
viewportHeight: 1200
8+
deviceScaleFactor: 2
9+
userAgent: "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Mobile Safari/537.36"
10+
output: ./output/ebay-headphones.json
11+
12+
tasks:
13+
- name: search headphones
14+
flow:
15+
- aiAction: type 'Headphones' in search box, hit Enter
16+
- aiWaitFor: there is at least one headphone item on page
17+
timeout: 10000
18+
19+
- name: extract headphones info
20+
flow:
21+
- aiQuery: >
22+
{name: string, price: number, actionBtnName: string}[], return item name, price and the action button name on the lower right corner of each item (like 'Remove')
23+
name: headphones
24+
25+
- name: assert shopping cart icon
26+
flow:
27+
- aiAssert: There is a shopping cart icon on the top right

yaml-scripts-demo/package.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "yaml-scripts-demo",
3+
"private": true,
4+
"version": "1.0.0",
5+
"description": "> quick start",
6+
"main": "index.js",
7+
"type": "module",
8+
"scripts": {
9+
"test": "midscene ./midscene-scripts"
10+
},
11+
"author": "",
12+
"license": "MIT",
13+
"devDependencies": {
14+
"@midscene/cli": "beta"
15+
}
16+
}
File renamed without changes.

0 commit comments

Comments
 (0)