@kogeet/sagent-playwright 0.1.0 → 0.2.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.
@@ -25,6 +25,13 @@ export default class StdLib {
25
25
  * @param stepCtx Paramètre du step
26
26
  */
27
27
  static elemHasText(stepCtx: StepContext): Promise<boolean>;
28
+ /**
29
+ * **Recherche d'un texte dans un élément texte statique**
30
+ *
31
+ * En réserve d'implémentation dans une instruction.
32
+ * @param stepCtx Paramètres du step
33
+ */
34
+ static elemMatchText(stepCtx: StepContext): Promise<boolean>;
28
35
  /**
29
36
  * **Implémentation de l'instruction de contrôle IsVisible**
30
37
  * @param stepCtx Paramètre du step
@@ -71,5 +78,37 @@ export default class StdLib {
71
78
  * @param stepCtx Paramètre du step
72
79
  */
73
80
  static calculator(stepCtx: StepContext): Promise<boolean>;
81
+ /**
82
+ * **Sélectionne l'option d'une combobox par son texte affiché**
83
+ * @param stepCtx Paramètres du step
84
+ */
85
+ static selectCountOptions(stepCtx: StepContext): Promise<boolean>;
86
+ /**
87
+ * **Sélectionne l'option d'une combobox par son texte affiché**
88
+ * @param stepCtx Paramètres du step
89
+ */
90
+ static selectHasCountOptions(stepCtx: StepContext): Promise<boolean>;
91
+ /**
92
+ * **Sélectionne l'option d'une combobox par son texte affiché**
93
+ * @param stepCtx Paramètres du step
94
+ */
95
+ static selectByText(stepCtx: StepContext): Promise<boolean>;
96
+ /**
97
+ * **Sélectionne l'option d'une combobox par son texte affiché**
98
+ * @param stepCtx Paramètres du step
99
+ */
100
+ static selectByValue(stepCtx: StepContext): Promise<boolean>;
101
+ /**
102
+ * **Sélectionne l'option d'une combobox par son texte affiché**
103
+ * @param stepCtx Paramètres du step
104
+ */
105
+ static selectByIndex(stepCtx: StepContext): Promise<boolean>;
106
+ /**
107
+ * **Sélectionne l'option d'une combobox par son texte affiché**
108
+ * @param stepCtx Paramètres du step
109
+ */
110
+ static selectHasOption(stepCtx: StepContext): Promise<boolean>;
111
+ static uploadFile(stepCtx: StepContext): Promise<boolean>;
112
+ static downloadFile(stepCtx: StepContext): Promise<boolean>;
74
113
  }
75
114
  //# sourceMappingURL=StdLib.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"StdLib.d.ts","sourceRoot":"","sources":["../../src/libs/StdLib.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,2BAA2B,CAAC;AAM3D,MAAM,CAAC,OAAO,OAAO,MAAM;IAEzB,OAAc,WAAW,uCAavB;IAEF;;;OAGG;WACiB,SAAS,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;IAarE;;;OAGG;WACiB,WAAW,CAAC,OAAO,EAAE,WAAW;IAiBpD;;;;;OAKG;WACiB,WAAW,CAAC,OAAO,EAAE,WAAW;IAapD;;;;;OAKG;WACiB,WAAW,CAAC,OAAO,EAAE,WAAW;IAqBpD;;;OAGG;WACiB,aAAa,CAAC,OAAO,EAAE,WAAW;IAYtD;;;OAGG;WACiB,aAAa,CAAC,OAAO,EAAE,WAAW;IAYtD;;;;;OAKG;WACiB,YAAY,CAAC,OAAO,EAAE,WAAW;IAarD;;;;;OAKG;WACiB,YAAY,CAAC,OAAO,EAAE,WAAW;IAYrD;;;;;OAKG;WACiB,YAAY,CAAC,OAAO,EAAE,WAAW;IAgBrD;;;OAGG;WACiB,cAAc,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;IAiB1E;;;OAGG;WACiB,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;IAMhE;;;OAGG;WACiB,UAAU,CAAC,OAAO,EAAE,WAAW;CAkCpD"}
1
+ {"version":3,"file":"StdLib.d.ts","sourceRoot":"","sources":["../../src/libs/StdLib.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,2BAA2B,CAAC;AAM3D,MAAM,CAAC,OAAO,OAAO,MAA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AGG;WACiB,eAAe,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;WAyBvD,UAAU,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;WA2BlD,YAAY,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;CAyBzE"}
@@ -7,14 +7,23 @@ export default class StdLib {
7
7
  ['elemSetText', StdLib.elemSetText],
8
8
  ['elemGetText', StdLib.elemGetText],
9
9
  ['elemHasText', StdLib.elemHasText],
10
+ ['elemMatchText', StdLib.elemMatchText],
10
11
  ['elemIsVisible', StdLib.elemIsVisible],
11
12
  ['elemIsEnabled', StdLib.elemIsEnabled],
12
13
  ['elemHasState', StdLib.elemHasState],
13
14
  ['elemGetState', StdLib.elemGetState],
14
15
  ['elemSetState', StdLib.elemSetState],
15
16
  ['elemClickToNew', StdLib.elemClickToNew],
17
+ ['selectHasOption', StdLib.selectHasOption],
18
+ ['selectCountOptions', StdLib.selectCountOptions],
19
+ ['selectHasCountOptions', StdLib.selectHasCountOptions],
20
+ ['selectByText', StdLib.selectByText],
21
+ ['selectByValue', StdLib.selectByValue],
22
+ ['selectByIndex', StdLib.selectByIndex],
16
23
  ['wait', StdLib.wait],
17
- ['calculator', StdLib.calculator]
24
+ ['calculator', StdLib.calculator],
25
+ ['uploadFile', StdLib.uploadFile],
26
+ ['downloadFile', StdLib.downloadFile]
18
27
  ]);
19
28
  /**
20
29
  * **Implémentation de l'instruction d'action Click**
@@ -23,12 +32,12 @@ export default class StdLib {
23
32
  static async elemClick(stepCtx) {
24
33
  return await uiWrapper(stepCtx, async (stepCtx, elem) => {
25
34
  try {
26
- await elem.click();
35
+ await complexClick(elem);
27
36
  await core.waitForLoadActivePage();
28
37
  return true;
29
38
  }
30
39
  catch (e) {
31
- report.warning(`Paywright error on 'Click' instruction : ${e.message}`);
40
+ report.warning(`Playwright error on 'Click' instruction : ${e.message}`);
32
41
  return false;
33
42
  }
34
43
  });
@@ -47,7 +56,7 @@ export default class StdLib {
47
56
  return true;
48
57
  }
49
58
  catch (e) {
50
- report.warning(`Paywright error on 'InputText' instruction : ${e.message}`);
59
+ report.warning(`Playwright error on 'InputText' instruction : ${e.message}`);
51
60
  return false;
52
61
  }
53
62
  });
@@ -66,7 +75,7 @@ export default class StdLib {
66
75
  return true;
67
76
  }
68
77
  catch (e) {
69
- report.warning(`Paywright error on 'GetText' instruction : ${e.message}`);
78
+ report.warning(`Playwright error on 'GetText' instruction : ${e.message}`);
70
79
  return false;
71
80
  }
72
81
  });
@@ -90,7 +99,33 @@ export default class StdLib {
90
99
  return !!found;
91
100
  }
92
101
  catch (e) {
93
- report.warning(`Paywright error on 'HasText' instruction : ${e.message}`);
102
+ report.warning(`Playwright error on 'HasText' instruction : ${e.message}`);
103
+ return false;
104
+ }
105
+ });
106
+ }
107
+ /**
108
+ * **Recherche d'un texte dans un élément texte statique**
109
+ *
110
+ * En réserve d'implémentation dans une instruction.
111
+ * @param stepCtx Paramètres du step
112
+ */
113
+ static async elemMatchText(stepCtx) {
114
+ return await uiWrapper(stepCtx, async (stepCtx, elem) => {
115
+ try {
116
+ const text = await elem.innerText();
117
+ const regex = new RegExp(stepCtx.getStringParam('0'), stepCtx.getStringParam('1', ''));
118
+ const found = text ? text.match(regex) : false;
119
+ if (found) {
120
+ context.setVariable(stepCtx.getStringParam('2'), found.length);
121
+ return true;
122
+ }
123
+ else {
124
+ return false;
125
+ }
126
+ }
127
+ catch (e) {
128
+ report.warning(`Playwright error on 'FindText' instruction : ${e.message}`);
94
129
  return false;
95
130
  }
96
131
  });
@@ -106,7 +141,7 @@ export default class StdLib {
106
141
  return elemVisible === stepCtx.getParam('0', true);
107
142
  }
108
143
  catch (e) {
109
- report.warning(`Paywright error on 'IsVisible' instruction : ${e.message}`);
144
+ report.warning(`Playwright error on 'IsVisible' instruction : ${e.message}`);
110
145
  return false;
111
146
  }
112
147
  });
@@ -122,7 +157,7 @@ export default class StdLib {
122
157
  return elemEnabled === stepCtx.getParam('0', true);
123
158
  }
124
159
  catch (e) {
125
- report.warning(`Paywright error on 'IsEnabled' instruction : ${e.message}`);
160
+ report.warning(`Playwright error on 'IsEnabled' instruction : ${e.message}`);
126
161
  return false;
127
162
  }
128
163
  });
@@ -140,7 +175,7 @@ export default class StdLib {
140
175
  return state === stepCtx.getParam('0', true);
141
176
  }
142
177
  catch (e) {
143
- report.warning(`Paywright error on 'HasState' instruction : ${e.message}`);
178
+ report.warning(`Playwright error on 'HasState' instruction : ${e.message}`);
144
179
  return false;
145
180
  }
146
181
  });
@@ -158,7 +193,7 @@ export default class StdLib {
158
193
  return true;
159
194
  }
160
195
  catch (e) {
161
- report.warning(`Paywright error on 'GetState' instruction : ${e.message}`);
196
+ report.warning(`Playwright error on 'GetState' instruction : ${e.message}`);
162
197
  return false;
163
198
  }
164
199
  });
@@ -181,7 +216,7 @@ export default class StdLib {
181
216
  return true;
182
217
  }
183
218
  catch (e) {
184
- report.warning(`Paywright error on 'SetState' instruction : ${e.message}`);
219
+ report.warning(`Playwright error on 'SetState' instruction : ${e.message}`);
185
220
  return false;
186
221
  }
187
222
  });
@@ -195,14 +230,14 @@ export default class StdLib {
195
230
  try {
196
231
  const pagePromise = core.pagePromise();
197
232
  if (pagePromise) {
198
- await elem.click();
233
+ await complexClick(elem);
199
234
  await core.switchToNewPage(pagePromise);
200
235
  context.setVariable(stepCtx.getStringParam('0'), core.getCurrentPageHandle());
201
236
  }
202
237
  return true;
203
238
  }
204
239
  catch (e) {
205
- report.warning(`Paywright error on 'ClickAndOpen' instruction : ${e.message}`);
240
+ report.warning(`Playwright error on 'ClickAndOpen' instruction : ${e.message}`);
206
241
  return false;
207
242
  }
208
243
  });
@@ -224,6 +259,172 @@ export default class StdLib {
224
259
  context.setVariable(stepCtx.getStringParam('1'), stepCtx.getParam('0'));
225
260
  return true;
226
261
  }
262
+ /**
263
+ * **Sélectionne l'option d'une combobox par son texte affiché**
264
+ * @param stepCtx Paramètres du step
265
+ */
266
+ static async selectCountOptions(stepCtx) {
267
+ return await uiWrapper(stepCtx, async (stepCtx, elem) => {
268
+ try {
269
+ const options = elem.getByRole('option');
270
+ context.setVariable(stepCtx.getStringParam('0'), await options.count());
271
+ return true;
272
+ }
273
+ catch (e) {
274
+ report.warning(`Playwright error on 'SelectByText' instruction : ${e.message}`);
275
+ return false;
276
+ }
277
+ });
278
+ }
279
+ /**
280
+ * **Sélectionne l'option d'une combobox par son texte affiché**
281
+ * @param stepCtx Paramètres du step
282
+ */
283
+ static async selectHasCountOptions(stepCtx) {
284
+ return await uiWrapper(stepCtx, async (stepCtx, elem) => {
285
+ try {
286
+ const options = elem.getByRole('option');
287
+ return await options.count() === stepCtx.getParam('0', true);
288
+ }
289
+ catch (e) {
290
+ report.warning(`Playwright error on 'SelectByText' instruction : ${e.message}`);
291
+ return false;
292
+ }
293
+ });
294
+ }
295
+ /**
296
+ * **Sélectionne l'option d'une combobox par son texte affiché**
297
+ * @param stepCtx Paramètres du step
298
+ */
299
+ static async selectByText(stepCtx) {
300
+ return await uiWrapper(stepCtx, async (stepCtx, elem) => {
301
+ try {
302
+ const label = stepCtx.getStringParam('0');
303
+ await elem.selectOption({ label });
304
+ return true;
305
+ }
306
+ catch (e) {
307
+ report.warning(`Playwright error on 'SelectByText' instruction : ${e.message}`);
308
+ return false;
309
+ }
310
+ });
311
+ }
312
+ /**
313
+ * **Sélectionne l'option d'une combobox par son texte affiché**
314
+ * @param stepCtx Paramètres du step
315
+ */
316
+ static async selectByValue(stepCtx) {
317
+ return await uiWrapper(stepCtx, async (stepCtx, elem) => {
318
+ try {
319
+ const value = stepCtx.getStringParam('0');
320
+ await elem.selectOption({ value });
321
+ return true;
322
+ }
323
+ catch (e) {
324
+ report.warning(`Playwright error on 'SelectByText' instruction : ${e.message}`);
325
+ return false;
326
+ }
327
+ });
328
+ }
329
+ /**
330
+ * **Sélectionne l'option d'une combobox par son texte affiché**
331
+ * @param stepCtx Paramètres du step
332
+ */
333
+ static async selectByIndex(stepCtx) {
334
+ return await uiWrapper(stepCtx, async (stepCtx, elem) => {
335
+ try {
336
+ const index = +stepCtx.getStringParam('0');
337
+ await elem.selectOption({ index });
338
+ return true;
339
+ }
340
+ catch (e) {
341
+ report.warning(`Playwright error on 'SelectByText' instruction : ${e.message}`);
342
+ return false;
343
+ }
344
+ });
345
+ }
346
+ /**
347
+ * **Sélectionne l'option d'une combobox par son texte affiché**
348
+ * @param stepCtx Paramètres du step
349
+ */
350
+ static async selectHasOption(stepCtx) {
351
+ return await uiWrapper(stepCtx, async (stepCtx, elem) => {
352
+ try {
353
+ const by = stepCtx.getStringParam('0');
354
+ const data = stepCtx.getStringParam('1');
355
+ switch (by) {
356
+ case 'name':
357
+ await elem.selectOption({ label: `/${data}/` });
358
+ return true;
359
+ case 'value':
360
+ await elem.selectOption({ value: `/${data}/` });
361
+ return true;
362
+ case 'index':
363
+ await elem.selectOption({ index: +data });
364
+ return true;
365
+ }
366
+ report.warning(`Playwright error on 'HasOption' instruction : '${by}' is an invalid value for 'By' parameter`);
367
+ return false;
368
+ }
369
+ catch (e) {
370
+ report.warning(`Playwright error on 'SelectByText' instruction : ${e.message}`);
371
+ return false;
372
+ }
373
+ });
374
+ }
375
+ static async uploadFile(stepCtx) {
376
+ return await uiWrapper(stepCtx, async (stepCtx, elem) => {
377
+ try {
378
+ const filename = stepCtx.getStringParam('0');
379
+ const page = core.getActivePage();
380
+ if (page) {
381
+ const fileChooserPromise = page.waitForEvent('filechooser');
382
+ await elem.click();
383
+ const fileChooser = await fileChooserPromise;
384
+ if (filename) {
385
+ await fileChooser.setFiles(filename);
386
+ }
387
+ else {
388
+ await fileChooser.setFiles([]);
389
+ }
390
+ return true;
391
+ }
392
+ else {
393
+ report.warning(`Playwright error on 'uploadFile' instruction : No active page`);
394
+ return false;
395
+ }
396
+ }
397
+ catch (e) {
398
+ report.warning(`Playwright error on 'uploadFile' instruction : ${e.message}`);
399
+ return false;
400
+ }
401
+ });
402
+ }
403
+ static async downloadFile(stepCtx) {
404
+ return await uiWrapper(stepCtx, async (stepCtx, elem) => {
405
+ try {
406
+ let path = stepCtx.getStringParam('0', '');
407
+ if (path.length > 0 && path.substring(path.length - 1) !== "\\")
408
+ path = path + "\\";
409
+ const page = core.getActivePage();
410
+ if (page) {
411
+ const downloadPromise = page.waitForEvent('download');
412
+ await elem.click();
413
+ const download = await downloadPromise;
414
+ await download.saveAs(path + download.suggestedFilename());
415
+ return true;
416
+ }
417
+ else {
418
+ report.warning(`Playwright error on 'uploadFile' instruction : No active page`);
419
+ return false;
420
+ }
421
+ }
422
+ catch (e) {
423
+ report.warning(`Playwright error on 'uploadFile' instruction : ${e.message}`);
424
+ return false;
425
+ }
426
+ });
427
+ }
227
428
  }
228
429
  function delay(t) {
229
430
  return new Promise((done) => {
@@ -232,3 +433,48 @@ function delay(t) {
232
433
  }, t);
233
434
  });
234
435
  }
436
+ async function complexClick(elem) {
437
+ const timeout = 1000;
438
+ let force = false;
439
+ let event = false;
440
+ // 1er essai mode standard
441
+ try {
442
+ await elem.click({ timeout });
443
+ }
444
+ catch (e) {
445
+ const { message } = e;
446
+ if (message.match(/Timeout/)) {
447
+ console.log('> Retry click action with force option');
448
+ force = true;
449
+ }
450
+ else {
451
+ throw new Error(message);
452
+ }
453
+ }
454
+ // 2ème essai avec l'option force si le flag force est à true
455
+ if (force) {
456
+ try {
457
+ await elem.click({ timeout, force });
458
+ }
459
+ catch (e) {
460
+ const { message } = e;
461
+ if (message.match(/Timeout/)) {
462
+ console.log('> Retry click action using dispatchEvent');
463
+ event = true;
464
+ }
465
+ else {
466
+ throw new Error(message);
467
+ }
468
+ }
469
+ }
470
+ // 3ème essai avec dispatchEvent si le flag event est à true
471
+ if (event) {
472
+ try {
473
+ await elem.dispatchEvent('click', undefined, { timeout });
474
+ }
475
+ catch (e) {
476
+ const { message } = e;
477
+ throw new Error(message);
478
+ }
479
+ }
480
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kogeet/sagent-playwright",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "description": "Scapin Agent for Playwright",
5
5
  "main": "bin/index.js",
6
6
  "publishConfig": {