yaml-pptr is a library that allows you to control web browsers using Puppeteer by defining your scenarios in YAML. No more verbose Puppeteer scripts - just simple, human-readable configuration files.
npm install @bloom-perf/yaml-pptrimport { readYamlAndInterpret } from '@bloom-perf/yaml-pptr';
const yaml = `
scenarios:
- name: Login Test
location: "https://www.saucedemo.com"
steps:
- input:
selector: "#user-name"
text: "standard_user"
- input:
selector: "#password"
text: "secret_sauce"
- click: "#login-button"
- wait: 2
`;
readYamlAndInterpret(yaml);Ready-to-run examples are available in the examples/ directory:
npm run example:login # Login test with screenshot
npm run example:load # Load test (3 workers Ă— 2 iterations)my-automation/
├── scenarios/
│ └── login-test.yaml
├── src/
│ └── runner.ts
├── package.json
└── tsconfig.json
scenarios/login-test.yaml
scenarios:
- name: Sauce Demo Login
location: "https://www.saucedemo.com"
steps:
- input:
selector: "#user-name"
text: "standard_user"
- input:
selector: "#password"
text: "secret_sauce"
- click: "#login-button"
- wait: 2
actions:
- type: WAIT_FOR_SELECTOR
selector: ".inventory_list"
options:
visible: true
- type: SCREENSHOT
path: "screenshots/result.png"
options:
fullPage: truesrc/runner.ts
import { readYamlAndInterpret } from '@bloom-perf/yaml-pptr';
import * as fs from 'fs';
const yaml = fs.readFileSync('./scenarios/login-test.yaml', 'utf-8');
fs.mkdirSync('./screenshots', { recursive: true });
readYamlAndInterpret(yaml)
.then(() => console.log('Done!'))
.catch(console.error);npx ts-node src/runner.ts| Property | Type | Default | Description |
|---|---|---|---|
name |
string | Scenario N |
Scenario name |
browser |
chrome | firefox |
chrome |
Browser to use |
run |
PARALLEL | SEQUENTIAL |
PARALLEL |
Worker start strategy |
initialDelaySeconds |
number | 0 |
Delay before starting |
workers |
number | 1 |
Number of parallel workers |
iterations |
number | 1 |
Repetitions per worker |
location |
string | - | Starting URL |
steps |
array | - | Simplified syntax |
actions |
array | - | Full syntax with options |
- click: "#submit-button"- input:
selector: "#username"
text: "myuser"- navigate: "http://example.com"
- navigate: "$ENV_VAR"- wait: 3 # seconds- waitForeverUse actions instead of steps when you need advanced options.
- type: GOTO
url: "http://example.com"
options:
timeout: 30000
waitUntil: networkidle0 # load | domcontentloaded | networkidle0 | networkidle2
referer: "http://referrer.com"- type: CLICK
selector: "#button"
options:
button: left # left | right | middle
clickCount: 2 # double-click
delay: 100 # ms between mousedown/mouseup- type: TYPE
selector: "#input"
text: "Hello"
options:
delay: 50 # ms between keystrokes- type: WAIT
milliseconds: 2000- type: WAIT_FOR_SELECTOR
selector: ".loaded"
options:
visible: true
hidden: false
timeout: 5000- type: WAIT_FOR_TIMEOUT
timeout: 1000- type: SCREENSHOT
path: "screenshot.png"
options:
type: png # png | jpeg
quality: 80 # jpeg quality (0-100)
fullPage: true
omitBackground: false
encoding: binary # binary | base64
clip:
x: 0
y: 0
width: 800
height: 600- type: EVALUATE
script: "document.title"- type: SET_VIEWPORT
width: 1920
height: 1080- type: PAUSE # Press Enter to continue- type: CLOSEUse $VAR_NAME syntax in location or navigate:
location: "$BASE_URL"BASE_URL=https://example.com npx ts-node runner.tsAssign different values to each worker using $VAR[workerIndex]:
scenarios:
- name: Multi-URL Test
workers: 3
location: "$URLS[workerIndex]"
steps:
- wait: 2URLS="https://site1.com,https://site2.com,https://site3.com" npx ts-node runner.tsWorker 0 gets site1.com, worker 1 gets site2.com, etc.
scenarios:
- name: Load Test
run: PARALLEL
workers: 10
iterations: 5
location: "https://example.com"
steps:
- click: "#action-button"
- wait: 1This runs 10 workers in parallel, each executing the scenario 5 times.
# Run tests
npm test
# Run tests with coverage
npm run test:coverage
# Build
npm run buildContributions are welcome! Please open an issue or submit a pull request.