@bloom-perf/yaml-pptr 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,336 @@
1
+ # yaml-pptr
2
+
3
+ [![GitHub last commit](https://img.shields.io/github/last-commit/bloom-perf/yaml-pptr?logo=github)](https://github.com/bloom-perf/yaml-pptr)
4
+ [![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/bloom-perf/yaml-pptr/ci.yml?style=flat&branch=main)](https://github.com/Bloom-Perf/yaml-pptr/actions)
5
+ [![GitHub release](https://img.shields.io/github/v/release/bloom-perf/yaml-pptr?style=flat)](https://github.com/Bloom-Perf/yaml-pptr/releases)
6
+ [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg?style=flat)](https://opensource.org/licenses/Apache-2.0)
7
+
8
+ **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.
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ npm install @bloom-perf/yaml-pptr
14
+ ```
15
+
16
+ ## Quick Start
17
+
18
+ ```typescript
19
+ import { readYamlAndInterpret } from '@bloom-perf/yaml-pptr';
20
+
21
+ const yaml = `
22
+ scenarios:
23
+ - name: Login Test
24
+ location: "https://www.saucedemo.com"
25
+ steps:
26
+ - input:
27
+ selector: "#user-name"
28
+ text: "standard_user"
29
+ - input:
30
+ selector: "#password"
31
+ text: "secret_sauce"
32
+ - click: "#login-button"
33
+ - wait: 2
34
+ `;
35
+
36
+ readYamlAndInterpret(yaml);
37
+ ```
38
+
39
+ ## Examples
40
+
41
+ Ready-to-run examples are available in the [`examples/`](./examples) directory:
42
+
43
+ ```bash
44
+ npm run example:login # Login test with screenshot
45
+ npm run example:load # Load test (3 workers × 2 iterations)
46
+ ```
47
+
48
+ ## Getting Started
49
+
50
+ ### Project Structure
51
+
52
+ ```
53
+ my-automation/
54
+ ├── scenarios/
55
+ │ └── login-test.yaml
56
+ ├── src/
57
+ │ └── runner.ts
58
+ ├── package.json
59
+ └── tsconfig.json
60
+ ```
61
+
62
+ ### 1. Create a YAML scenario
63
+
64
+ **scenarios/login-test.yaml**
65
+
66
+ ```yaml
67
+ scenarios:
68
+ - name: Sauce Demo Login
69
+ location: "https://www.saucedemo.com"
70
+ steps:
71
+ - input:
72
+ selector: "#user-name"
73
+ text: "standard_user"
74
+ - input:
75
+ selector: "#password"
76
+ text: "secret_sauce"
77
+ - click: "#login-button"
78
+ - wait: 2
79
+ actions:
80
+ - type: WAIT_FOR_SELECTOR
81
+ selector: ".inventory_list"
82
+ options:
83
+ visible: true
84
+ - type: SCREENSHOT
85
+ path: "screenshots/result.png"
86
+ options:
87
+ fullPage: true
88
+ ```
89
+
90
+ ### 2. Create a runner script
91
+
92
+ **src/runner.ts**
93
+
94
+ ```typescript
95
+ import { readYamlAndInterpret } from '@bloom-perf/yaml-pptr';
96
+ import * as fs from 'fs';
97
+
98
+ const yaml = fs.readFileSync('./scenarios/login-test.yaml', 'utf-8');
99
+
100
+ fs.mkdirSync('./screenshots', { recursive: true });
101
+
102
+ readYamlAndInterpret(yaml)
103
+ .then(() => console.log('Done!'))
104
+ .catch(console.error);
105
+ ```
106
+
107
+ ### 3. Run it
108
+
109
+ ```bash
110
+ npx ts-node src/runner.ts
111
+ ```
112
+
113
+ ## YAML Reference
114
+
115
+ ### Scenario Configuration
116
+
117
+ | Property | Type | Default | Description |
118
+ | -------- | ---- | ------- | ----------- |
119
+ | `name` | string | `Scenario N` | Scenario name |
120
+ | `browser` | `chrome` \| `firefox` | `chrome` | Browser to use |
121
+ | `run` | `PARALLEL` \| `SEQUENTIAL` | `PARALLEL` | Worker start strategy |
122
+ | `initialDelaySeconds` | number | `0` | Delay before starting |
123
+ | `workers` | number | `1` | Number of parallel workers |
124
+ | `iterations` | number | `1` | Repetitions per worker |
125
+ | `location` | string | - | Starting URL |
126
+ | `steps` | array | - | Simplified syntax |
127
+ | `actions` | array | - | Full syntax with options |
128
+
129
+ ### Steps (Simplified Syntax)
130
+
131
+ #### click
132
+
133
+ ```yaml
134
+ - click: "#submit-button"
135
+ ```
136
+
137
+ #### input
138
+
139
+ ```yaml
140
+ - input:
141
+ selector: "#username"
142
+ text: "myuser"
143
+ ```
144
+
145
+ #### navigate
146
+
147
+ ```yaml
148
+ - navigate: "http://example.com"
149
+ - navigate: "$ENV_VAR"
150
+ ```
151
+
152
+ #### wait
153
+
154
+ ```yaml
155
+ - wait: 3 # seconds
156
+ ```
157
+
158
+ #### waitForever
159
+
160
+ ```yaml
161
+ - waitForever
162
+ ```
163
+
164
+ ### Actions (Full Syntax)
165
+
166
+ Use `actions` instead of `steps` when you need advanced options.
167
+
168
+ #### GOTO
169
+
170
+ ```yaml
171
+ - type: GOTO
172
+ url: "http://example.com"
173
+ options:
174
+ timeout: 30000
175
+ waitUntil: networkidle0 # load | domcontentloaded | networkidle0 | networkidle2
176
+ referer: "http://referrer.com"
177
+ ```
178
+
179
+ #### CLICK
180
+
181
+ ```yaml
182
+ - type: CLICK
183
+ selector: "#button"
184
+ options:
185
+ button: left # left | right | middle
186
+ clickCount: 2 # double-click
187
+ delay: 100 # ms between mousedown/mouseup
188
+ ```
189
+
190
+ #### TYPE
191
+
192
+ ```yaml
193
+ - type: TYPE
194
+ selector: "#input"
195
+ text: "Hello"
196
+ options:
197
+ delay: 50 # ms between keystrokes
198
+ ```
199
+
200
+ #### WAIT
201
+
202
+ ```yaml
203
+ - type: WAIT
204
+ milliseconds: 2000
205
+ ```
206
+
207
+ #### WAIT_FOR_SELECTOR
208
+
209
+ ```yaml
210
+ - type: WAIT_FOR_SELECTOR
211
+ selector: ".loaded"
212
+ options:
213
+ visible: true
214
+ hidden: false
215
+ timeout: 5000
216
+ ```
217
+
218
+ #### WAIT_FOR_TIMEOUT
219
+
220
+ ```yaml
221
+ - type: WAIT_FOR_TIMEOUT
222
+ timeout: 1000
223
+ ```
224
+
225
+ #### SCREENSHOT
226
+
227
+ ```yaml
228
+ - type: SCREENSHOT
229
+ path: "screenshot.png"
230
+ options:
231
+ type: png # png | jpeg
232
+ quality: 80 # jpeg quality (0-100)
233
+ fullPage: true
234
+ omitBackground: false
235
+ encoding: binary # binary | base64
236
+ clip:
237
+ x: 0
238
+ y: 0
239
+ width: 800
240
+ height: 600
241
+ ```
242
+
243
+ #### EVALUATE
244
+
245
+ ```yaml
246
+ - type: EVALUATE
247
+ script: "document.title"
248
+ ```
249
+
250
+ #### SET_VIEWPORT
251
+
252
+ ```yaml
253
+ - type: SET_VIEWPORT
254
+ width: 1920
255
+ height: 1080
256
+ ```
257
+
258
+ #### PAUSE
259
+
260
+ ```yaml
261
+ - type: PAUSE # Press Enter to continue
262
+ ```
263
+
264
+ #### CLOSE
265
+
266
+ ```yaml
267
+ - type: CLOSE
268
+ ```
269
+
270
+ ## Environment Variables
271
+
272
+ Use `$VAR_NAME` syntax in `location` or `navigate`:
273
+
274
+ ```yaml
275
+ location: "$BASE_URL"
276
+ ```
277
+
278
+ ```bash
279
+ BASE_URL=https://example.com npx ts-node runner.ts
280
+ ```
281
+
282
+ ### Indexed Variables
283
+
284
+ Assign different values to each worker using `$VAR[workerIndex]`:
285
+
286
+ ```yaml
287
+ scenarios:
288
+ - name: Multi-URL Test
289
+ workers: 3
290
+ location: "$URLS[workerIndex]"
291
+ steps:
292
+ - wait: 2
293
+ ```
294
+
295
+ ```bash
296
+ URLS="https://site1.com,https://site2.com,https://site3.com" npx ts-node runner.ts
297
+ ```
298
+
299
+ Worker 0 gets `site1.com`, worker 1 gets `site2.com`, etc.
300
+
301
+ ## Load Testing Example
302
+
303
+ ```yaml
304
+ scenarios:
305
+ - name: Load Test
306
+ run: PARALLEL
307
+ workers: 10
308
+ iterations: 5
309
+ location: "https://example.com"
310
+ steps:
311
+ - click: "#action-button"
312
+ - wait: 1
313
+ ```
314
+
315
+ This runs 10 workers in parallel, each executing the scenario 5 times.
316
+
317
+ ## Development
318
+
319
+ ```bash
320
+ # Run tests
321
+ npm test
322
+
323
+ # Run tests with coverage
324
+ npm run test:coverage
325
+
326
+ # Build
327
+ npm run build
328
+ ```
329
+
330
+ ## Contributing
331
+
332
+ Contributions are welcome! Please open an issue or submit a pull request.
333
+
334
+ ## License
335
+
336
+ [Apache 2.0](https://opensource.org/licenses/Apache-2.0)
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";var B=Object.create;var b=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var U=Object.getPrototypeOf,V=Object.prototype.hasOwnProperty;var _=(o,t)=>{for(var i in t)b(o,i,{get:t[i],enumerable:!0})},$=(o,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of j(t))!V.call(o,r)&&r!==i&&b(o,r,{get:()=>t[r],enumerable:!(n=P(t,r))||n.enumerable});return o};var T=(o,t,i)=>(i=o!=null?B(U(o)):{},$(t||!o||!o.__esModule?b(i,"default",{value:o,enumerable:!0}):i,o)),G=o=>$(b({},"__esModule",{value:!0}),o);var bt={};_(bt,{readYamlAndInterpret:()=>wt});module.exports=G(bt);var C=T(require("puppeteer"),1);var x=T(require("js-yaml"),1);var e=T(require("zod"),1),E=e.enum(["load","domcontentloaded","networkidle0","networkidle2"]),I=e.enum(["left","right","middle"]),M=e.enum(["chrome","firefox"]),N=e.object({timeout:e.number().optional(),waitUntil:e.union([E,E.array()]).optional(),referer:e.string().optional()}).optional(),D=e.object({type:e.literal("WAIT"),milliseconds:e.number()}),q=e.object({button:I.optional(),clickCount:e.number().optional(),delay:e.number().optional()}).optional(),H=e.object({delay:e.number().optional()}).optional(),K=e.object({visible:e.boolean().optional(),hidden:e.boolean().optional(),timeout:e.number().optional()}).optional(),J=e.object({type:e.enum(["png","jpeg"]).optional(),quality:e.number().optional(),fullPage:e.boolean().optional(),clip:e.object({x:e.number(),y:e.number(),width:e.number(),height:e.number()}).optional(),omitBackground:e.boolean().optional(),encoding:e.enum(["base64","binary"]).optional()}).optional(),Q=e.object({type:e.literal("GOTO"),url:e.string(),options:N}),Z=e.object({type:e.literal("CLICK"),selector:e.string(),options:q}),X=e.object({type:e.literal("TYPE"),selector:e.string(),text:e.string(),options:H}),Y=e.object({type:e.literal("WAIT_FOR_SELECTOR"),selector:e.string(),options:K}),tt=e.object({type:e.literal("WAIT_FOR_TIMEOUT"),timeout:e.number()}),et=e.object({type:e.literal("PAUSE")}),ot=e.object({type:e.literal("SCREENSHOT"),path:e.string(),options:J}),it=e.object({type:e.literal("EVALUATE"),script:e.union([e.string(),e.function()])}),nt=e.object({type:e.literal("SET_VIEWPORT"),width:e.number(),height:e.number()}),rt=e.object({type:e.literal("CLOSE")}),W=[Q,Z,X,Y,tt,et,ot,it,nt,rt,D];if(W.length===0)throw new Error("Le tableau des sch\xE9mas d'actions est vide.");var st=W,at=e.discriminatedUnion("type",st),ct=e.object({navigate:e.string()}),pt=e.literal("waitForever"),lt=e.object({wait:e.number()}),ut=e.object({click:e.string()}),gt=e.object({input:e.object({selector:e.string(),text:e.string()})}),St=e.union([ct,pt,lt,ut,gt]),dt=e.object({name:e.string().optional(),browser:M.optional(),run:e.enum(["PARALLEL","SEQUENTIAL"]).optional(),initialDelaySeconds:e.number().nonnegative().optional(),workers:e.number().positive().optional(),iterations:e.number().positive().optional(),location:e.string().optional(),steps:e.array(St).optional(),actions:e.array(at).optional()}),k=e.object({scenarios:e.array(dt)});var O=o=>{let t=x.load(o);return k.parse(t)};var S={debug(o){console.log(o)},info(o){console.log(o)},warn(o){console.log(o)},error(o){console.error(o)}};var v=class{envVarResolve;logger;constructor(t,i=S){this.envVarResolve=n=>{let r=n.startsWith("$")?n.substring(1):n;return t(r)},this.logger=i}resolve(t){return{scenarios:t.scenarios.map((i,n)=>this.resolveScenario(i,n+1))}}resolveScenario(t,i){this.logger.debug(`Resolving YAML scenario: ${JSON.stringify(t)}`);let n=[];t.location&&n.push(this.createNavigateAction(t.location)),t.steps&&n.push(...t.steps.map(s=>this.resolveStep(s))),t.actions&&n.push(...t.actions.map(s=>this.resolveAction(s)));let r=t.run==="SEQUENTIAL"?{delaySecondsBetweenWorkerInits:t.initialDelaySeconds||0}:{initialDelaySeconds:t.initialDelaySeconds||0};return{name:t.name||`Scenario ${i}`,browser:t.browser||"chrome",run:r,workers:t.workers||1,iterations:t.iterations||1,actions:n}}resolveStep(t){if(t==="waitForever")return this.logger.debug("Resolving step: waitForever"),{actionType:"WaitForever"};if("wait"in t)return this.logger.debug(`Resolving step: wait ${t.wait} seconds`),{actionType:"Wait",milliseconds:t.wait*1e3};if("navigate"in t)return this.logger.debug("Resolving step: navigate"),this.createNavigateAction(t.navigate);if("click"in t)return this.logger.debug(`Resolving step: click "${t.click}"`),{actionType:"CLICK",selector:t.click};if("input"in t)return this.logger.debug(`Resolving step: input into "${t.input.selector}"`),{actionType:"TYPE",selector:t.input.selector,text:t.input.text};throw new Error(`Unknown step format: ${JSON.stringify(t)}`)}resolveAction(t){switch(this.logger.debug(`Resolving action: ${JSON.stringify(t)}`),t.type){case"GOTO":return{actionType:"GOTO",url:this.resolveStringOrEnv(t.url),options:t.options};case"WAIT":return{actionType:"Wait",milliseconds:t.milliseconds*1e3};case"CLICK":return{actionType:"CLICK",selector:t.selector,options:t.options};case"TYPE":return{actionType:"TYPE",selector:t.selector,text:t.text,options:t.options};case"WAIT_FOR_SELECTOR":return{actionType:"WAIT_FOR_SELECTOR",selector:t.selector,options:t.options};case"WAIT_FOR_TIMEOUT":return{actionType:"WAIT_FOR_TIMEOUT",timeout:t.timeout};case"PAUSE":return{actionType:"PAUSE"};case"SCREENSHOT":return{actionType:"SCREENSHOT",path:this.resolveStringOrEnv(t.path),options:t.options};case"EVALUATE":return{actionType:"EVALUATE",script:t.script};case"SET_VIEWPORT":return{actionType:"SET_VIEWPORT",width:t.width,height:t.height};case"CLOSE":return{actionType:"CLOSE"};default:return t}}createNavigateAction(t){return{actionType:"Navigate",location:this.resolveUrlOrEnv(t)}}resolveUrlOrEnv(t){let i="[workerIndex]";if(t.startsWith("$")){if(t.endsWith(i)){this.logger.debug(`Resolving indexed environment variable: "${t}"`);let n=t.substring(1,t.length-i.length);return{workerIndex:this.envVarResolve(n).split(",").map(c=>c.trim())}}return this.logger.debug(`Resolving environment variable: "${t}"`),{url:this.envVarResolve(t.substring(1))}}return this.logger.debug(`Using direct URL: "${t}"`),{url:t}}resolveStringOrEnv(t){return t.startsWith("$")?(this.logger.debug(`Resolving environment variable: "${t}"`),this.envVarResolve(t.substring(1))):t}};function At(o,t){let i=t||"png";return o.endsWith(".png")||o.endsWith(".jpeg")||o.endsWith(".jpg")||o.endsWith(".webp")?o:`${o}.${i}`}var R=async(o,t,i=S)=>await ht(t.workers,t.name,async n=>{for(let r=0;r<t.iterations;r++){let s=t.run;"delaySecondsBetweenWorkerInits"in s?(i.info(`Scenario "${t.name}" (worker ${n}) > Choosing SEQUENTIAL start with ${s.delaySecondsBetweenWorkerInits} seconds between workers`),await new Promise(p=>setTimeout(p,s.delaySecondsBetweenWorkerInits*n*1e3))):(i.info(`Scenario "${t.name}" (worker ${n}) > Choosing PARALLEL start with ${s.initialDelaySeconds} seconds of initial delay`),await new Promise(p=>setTimeout(p,s.initialDelaySeconds*1e3)));let c=await o.newPage();await yt(t.name,t.actions,c,n,i),await c.close()}},i),ht=async(o,t,i,n=S)=>Promise.all(Array.from({length:o},async(r,s)=>{try{n.info(`Scenario "${t}" (worker ${s}) started.`),await i(s)}catch(c){n.error(`Scenario ${t} (worker ${s}) failed: ${c}`)}})),yt=async(o,t,i,n,r=S)=>{for(let s of t){let{actionType:c}=s;switch(c){case"Navigate":let p=s;"url"in p.location?(r.info(`Scenario "${o}" (worker ${n}) > Navigating to location "${p.location.url}"`),await i.goto(p.location.url)):(r.info(`Scenario "${o}" (worker ${n}) > Navigating to indexed location "${p.location.workerIndex[n]}"`),await i.goto(p.location.workerIndex[n]));break;case"Wait":let y=s;r.info(`Scenario "${o}" (worker ${n}) > Waiting ${y.milliseconds} milliseconds...`),await i.evaluate(h=>new Promise(f=>setTimeout(f,h)),y.milliseconds);break;case"WaitForever":for(r.info(`Scenario "${o}" (worker ${n}) > Waiting forever...`);;)await new Promise(h=>setTimeout(h,3600*1e3));break;case"GOTO":let a=s;r.info(`Scenario "${o}" (worker ${n}) > GOTO "${a.url}"`);let l={timeout:a.options?.timeout,waitUntil:a.options?.waitUntil,referer:a.options?.referer};await i.goto(a.url,l);break;case"CLICK":let u=s;r.info(`Scenario "${o}" (worker ${n}) > CLICK on "${u.selector}"`);let d={button:u.options?.button,clickCount:u.options?.clickCount,delay:u.options?.delay};await i.click(u.selector,d);break;case"TYPE":let m=s;r.info(`Scenario "${o}" (worker ${n}) > TYPE into "${m.selector}"`),await i.type(m.selector,m.text,m.options);break;case"WAIT_FOR_SELECTOR":let A=s;r.info(`Scenario "${o}" (worker ${n}) > WAIT_FOR_SELECTOR "${A.selector}"`),await i.waitForSelector(A.selector,A.options);break;case"WAIT_FOR_TIMEOUT":let z=s;r.info(`Scenario "${o}" (worker ${n}) > WAIT_FOR_TIMEOUT ${z.timeout} milliseconds`),await i.evaluate(h=>new Promise(f=>setTimeout(f,h)),z.timeout);break;case"PAUSE":r.info(`Scenario "${o}" (worker ${n}) > PAUSE, press Enter to continue...`),await new Promise(h=>{process.stdin.resume(),process.stdin.once("data",()=>{process.stdin.pause(),h()})});break;case"SCREENSHOT":let g=s;r.info(`Scenario "${o}" (worker ${n}) > SCREENSHOT "${g.path}"`);let F={path:At(g.path,g.options?.type),type:g.options?.type,quality:g.options?.quality,fullPage:g.options?.fullPage,clip:g.options?.clip,omitBackground:g.options?.omitBackground,encoding:g.options?.encoding};await i.screenshot(F);break;case"EVALUATE":let L=s;r.info(`Scenario "${o}" (worker ${n}) > EVALUATE script`),await i.evaluate(L.script);break;case"SET_VIEWPORT":let w=s;r.info(`Scenario "${o}" (worker ${n}) > SET_VIEWPORT width=${w.width}, height=${w.height}`),await i.setViewport({width:w.width,height:w.height});break;case"CLOSE":r.info(`Scenario "${o}" (worker ${n}) > CLOSE page`),await i.close();break;default:throw new Error(`Unhandled action type "${c}" while evaluating scenario "${o}" on worker ${n}`)}}};var wt=async(o,t={},i=S)=>{let n=O(o),s=new v(a=>{let l=process.env[a];if(i.debug(`Resolving env variable "${a}" with value ***`),l)return l;throw new Error(`Tried to resolve env variable ${a} but was empty.`)},i).resolve(n),c={};for(let a of s.scenarios){let l=a.browser||"chrome";c[l]||(c[l]=[]),c[l]?.push(a)}let p=["chrome","firefox"],y=Object.entries(c).map(async([a,l])=>{if(!l)return;if(!p.includes(a)){console.error(`Navigateur non support\xE9: ${a}. Les navigateurs support\xE9s sont: ${p.join(", ")}`);return}let u=["--no-sandbox","--disable-setuid-sandbox","--disable-dev-shm-usage","--disable-accelerated-2d-canvas","--disable-gpu","--ignore-certificate-errors"];a==="chrome"&&u.push("--start-maximized"),a==="firefox"&&u.push("--private");let d=t[a],m=!1;d||(d=await C.launch({headless:!1,channel:a,acceptInsecureCerts:!0,args:u}),m=!0);try{for(let A of l)await R(d,A,i)}catch(A){console.error(`Erreur lors de l'ex\xE9cution des sc\xE9narios pour ${a}:`,A)}finally{m&&d&&await d.close()}});await Promise.all(y)};0&&(module.exports={readYamlAndInterpret});
@@ -0,0 +1,7 @@
1
+ export type YpLogger = {
2
+ debug(str: string): void;
3
+ info(str: string): void;
4
+ warn(str: string): void;
5
+ error(str: string): void;
6
+ };
7
+ export declare const dumbLogger: YpLogger;
@@ -0,0 +1,130 @@
1
+ export declare enum ActionType {
2
+ Navigate = "Navigate",
3
+ WaitForever = "WaitForever",
4
+ Wait = "Wait",
5
+ Goto = "GOTO",
6
+ Click = "CLICK",
7
+ Type = "TYPE",
8
+ WaitForSelector = "WAIT_FOR_SELECTOR",
9
+ WaitForTimeout = "WAIT_FOR_TIMEOUT",
10
+ Pause = "PAUSE",
11
+ Screenshot = "SCREENSHOT",
12
+ Close = "CLOSE",
13
+ Evaluate = "EVALUATE",
14
+ SetViewport = "SET_VIEWPORT"
15
+ }
16
+ export type UrlOrArray = {
17
+ url: string;
18
+ } | {
19
+ workerIndex: string[];
20
+ };
21
+ export interface BaseAction {
22
+ actionType: ActionType;
23
+ }
24
+ export interface NavigateAction extends BaseAction {
25
+ actionType: ActionType.Navigate;
26
+ location: UrlOrArray;
27
+ }
28
+ export interface WaitForeverAction extends BaseAction {
29
+ actionType: ActionType.WaitForever;
30
+ }
31
+ export interface WaitAction extends BaseAction {
32
+ actionType: ActionType.Wait;
33
+ milliseconds: number;
34
+ }
35
+ export type WaitUntil = 'load' | 'domcontentloaded' | 'networkidle0' | 'networkidle2';
36
+ export type MouseButton = 'left' | 'right' | 'middle';
37
+ export interface GotoOptions {
38
+ timeout?: number;
39
+ waitUntil?: WaitUntil | WaitUntil[];
40
+ referer?: string;
41
+ }
42
+ export interface ClickOptions {
43
+ button?: MouseButton;
44
+ clickCount?: number;
45
+ delay?: number;
46
+ }
47
+ export interface TypeOptions {
48
+ delay?: number;
49
+ }
50
+ export interface WaitForSelectorOptions {
51
+ visible?: boolean;
52
+ hidden?: boolean;
53
+ timeout?: number;
54
+ }
55
+ export interface ScreenshotOptions {
56
+ type?: 'png' | 'jpeg';
57
+ quality?: number;
58
+ fullPage?: boolean;
59
+ clip?: {
60
+ x: number;
61
+ y: number;
62
+ width: number;
63
+ height: number;
64
+ };
65
+ omitBackground?: boolean;
66
+ encoding?: 'base64' | 'binary';
67
+ }
68
+ export interface GotoAction extends BaseAction {
69
+ actionType: ActionType.Goto;
70
+ url: string;
71
+ options?: GotoOptions;
72
+ }
73
+ export interface ClickAction extends BaseAction {
74
+ actionType: ActionType.Click;
75
+ selector: string;
76
+ options?: ClickOptions;
77
+ }
78
+ export interface TypeAction extends BaseAction {
79
+ actionType: ActionType.Type;
80
+ selector: string;
81
+ text: string;
82
+ options?: TypeOptions;
83
+ }
84
+ export interface WaitForSelectorAction extends BaseAction {
85
+ actionType: ActionType.WaitForSelector;
86
+ selector: string;
87
+ options?: WaitForSelectorOptions;
88
+ }
89
+ export interface WaitForTimeoutAction extends BaseAction {
90
+ actionType: ActionType.WaitForTimeout;
91
+ timeout: number;
92
+ }
93
+ export interface PauseAction extends BaseAction {
94
+ actionType: ActionType.Pause;
95
+ }
96
+ export interface ScreenshotAction extends BaseAction {
97
+ actionType: ActionType.Screenshot;
98
+ path: string;
99
+ options?: ScreenshotOptions;
100
+ }
101
+ export interface CloseAction extends BaseAction {
102
+ actionType: ActionType.Close;
103
+ }
104
+ export interface EvaluateAction extends BaseAction {
105
+ actionType: ActionType.Evaluate;
106
+ script: string | ((...args: any[]) => any);
107
+ }
108
+ export interface SetViewportAction extends BaseAction {
109
+ actionType: ActionType.SetViewport;
110
+ width: number;
111
+ height: number;
112
+ }
113
+ export type Action = NavigateAction | WaitForeverAction | WaitAction | GotoAction | ClickAction | TypeAction | WaitForSelectorAction | WaitForTimeoutAction | PauseAction | ScreenshotAction | CloseAction | EvaluateAction | SetViewportAction;
114
+ export type Run = {
115
+ initialDelaySeconds: number;
116
+ } | {
117
+ delaySecondsBetweenWorkerInits: number;
118
+ };
119
+ export type SupportedBrowser = 'chrome' | 'firefox';
120
+ export type Scenario = {
121
+ name: string;
122
+ browser: SupportedBrowser;
123
+ run: Run;
124
+ workers: number;
125
+ iterations: number;
126
+ actions: Action[];
127
+ };
128
+ export type Root = {
129
+ scenarios: Scenario[];
130
+ };