@kogeet/sagent-playwright 0.2.0 → 0.2.2
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/bin/libs/StdLib.js +114 -24
- package/package.json +1 -1
package/bin/libs/StdLib.js
CHANGED
|
@@ -32,12 +32,12 @@ export default class StdLib {
|
|
|
32
32
|
static async elemClick(stepCtx) {
|
|
33
33
|
return await uiWrapper(stepCtx, async (stepCtx, elem) => {
|
|
34
34
|
try {
|
|
35
|
-
await elem
|
|
35
|
+
await complexClick2(elem);
|
|
36
36
|
await core.waitForLoadActivePage();
|
|
37
37
|
return true;
|
|
38
38
|
}
|
|
39
39
|
catch (e) {
|
|
40
|
-
report.warning(`
|
|
40
|
+
report.warning(`Playwright error on 'Click' instruction : ${e.message}`);
|
|
41
41
|
return false;
|
|
42
42
|
}
|
|
43
43
|
});
|
|
@@ -56,7 +56,7 @@ export default class StdLib {
|
|
|
56
56
|
return true;
|
|
57
57
|
}
|
|
58
58
|
catch (e) {
|
|
59
|
-
report.warning(`
|
|
59
|
+
report.warning(`Playwright error on 'InputText' instruction : ${e.message}`);
|
|
60
60
|
return false;
|
|
61
61
|
}
|
|
62
62
|
});
|
|
@@ -75,7 +75,7 @@ export default class StdLib {
|
|
|
75
75
|
return true;
|
|
76
76
|
}
|
|
77
77
|
catch (e) {
|
|
78
|
-
report.warning(`
|
|
78
|
+
report.warning(`Playwright error on 'GetText' instruction : ${e.message}`);
|
|
79
79
|
return false;
|
|
80
80
|
}
|
|
81
81
|
});
|
|
@@ -99,7 +99,7 @@ export default class StdLib {
|
|
|
99
99
|
return !!found;
|
|
100
100
|
}
|
|
101
101
|
catch (e) {
|
|
102
|
-
report.warning(`
|
|
102
|
+
report.warning(`Playwright error on 'HasText' instruction : ${e.message}`);
|
|
103
103
|
return false;
|
|
104
104
|
}
|
|
105
105
|
});
|
|
@@ -125,7 +125,7 @@ export default class StdLib {
|
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
127
|
catch (e) {
|
|
128
|
-
report.warning(`
|
|
128
|
+
report.warning(`Playwright error on 'FindText' instruction : ${e.message}`);
|
|
129
129
|
return false;
|
|
130
130
|
}
|
|
131
131
|
});
|
|
@@ -141,7 +141,7 @@ export default class StdLib {
|
|
|
141
141
|
return elemVisible === stepCtx.getParam('0', true);
|
|
142
142
|
}
|
|
143
143
|
catch (e) {
|
|
144
|
-
report.warning(`
|
|
144
|
+
report.warning(`Playwright error on 'IsVisible' instruction : ${e.message}`);
|
|
145
145
|
return false;
|
|
146
146
|
}
|
|
147
147
|
});
|
|
@@ -157,7 +157,7 @@ export default class StdLib {
|
|
|
157
157
|
return elemEnabled === stepCtx.getParam('0', true);
|
|
158
158
|
}
|
|
159
159
|
catch (e) {
|
|
160
|
-
report.warning(`
|
|
160
|
+
report.warning(`Playwright error on 'IsEnabled' instruction : ${e.message}`);
|
|
161
161
|
return false;
|
|
162
162
|
}
|
|
163
163
|
});
|
|
@@ -175,7 +175,7 @@ export default class StdLib {
|
|
|
175
175
|
return state === stepCtx.getParam('0', true);
|
|
176
176
|
}
|
|
177
177
|
catch (e) {
|
|
178
|
-
report.warning(`
|
|
178
|
+
report.warning(`Playwright error on 'HasState' instruction : ${e.message}`);
|
|
179
179
|
return false;
|
|
180
180
|
}
|
|
181
181
|
});
|
|
@@ -193,7 +193,7 @@ export default class StdLib {
|
|
|
193
193
|
return true;
|
|
194
194
|
}
|
|
195
195
|
catch (e) {
|
|
196
|
-
report.warning(`
|
|
196
|
+
report.warning(`Playwright error on 'GetState' instruction : ${e.message}`);
|
|
197
197
|
return false;
|
|
198
198
|
}
|
|
199
199
|
});
|
|
@@ -216,7 +216,7 @@ export default class StdLib {
|
|
|
216
216
|
return true;
|
|
217
217
|
}
|
|
218
218
|
catch (e) {
|
|
219
|
-
report.warning(`
|
|
219
|
+
report.warning(`Playwright error on 'SetState' instruction : ${e.message}`);
|
|
220
220
|
return false;
|
|
221
221
|
}
|
|
222
222
|
});
|
|
@@ -230,14 +230,14 @@ export default class StdLib {
|
|
|
230
230
|
try {
|
|
231
231
|
const pagePromise = core.pagePromise();
|
|
232
232
|
if (pagePromise) {
|
|
233
|
-
await elem
|
|
233
|
+
await complexClick2(elem);
|
|
234
234
|
await core.switchToNewPage(pagePromise);
|
|
235
235
|
context.setVariable(stepCtx.getStringParam('0'), core.getCurrentPageHandle());
|
|
236
236
|
}
|
|
237
237
|
return true;
|
|
238
238
|
}
|
|
239
239
|
catch (e) {
|
|
240
|
-
report.warning(`
|
|
240
|
+
report.warning(`Playwright error on 'ClickAndOpen' instruction : ${e.message}`);
|
|
241
241
|
return false;
|
|
242
242
|
}
|
|
243
243
|
});
|
|
@@ -271,7 +271,7 @@ export default class StdLib {
|
|
|
271
271
|
return true;
|
|
272
272
|
}
|
|
273
273
|
catch (e) {
|
|
274
|
-
report.warning(`
|
|
274
|
+
report.warning(`Playwright error on 'SelectByText' instruction : ${e.message}`);
|
|
275
275
|
return false;
|
|
276
276
|
}
|
|
277
277
|
});
|
|
@@ -287,7 +287,7 @@ export default class StdLib {
|
|
|
287
287
|
return await options.count() === stepCtx.getParam('0', true);
|
|
288
288
|
}
|
|
289
289
|
catch (e) {
|
|
290
|
-
report.warning(`
|
|
290
|
+
report.warning(`Playwright error on 'SelectByText' instruction : ${e.message}`);
|
|
291
291
|
return false;
|
|
292
292
|
}
|
|
293
293
|
});
|
|
@@ -304,7 +304,7 @@ export default class StdLib {
|
|
|
304
304
|
return true;
|
|
305
305
|
}
|
|
306
306
|
catch (e) {
|
|
307
|
-
report.warning(`
|
|
307
|
+
report.warning(`Playwright error on 'SelectByText' instruction : ${e.message}`);
|
|
308
308
|
return false;
|
|
309
309
|
}
|
|
310
310
|
});
|
|
@@ -321,7 +321,7 @@ export default class StdLib {
|
|
|
321
321
|
return true;
|
|
322
322
|
}
|
|
323
323
|
catch (e) {
|
|
324
|
-
report.warning(`
|
|
324
|
+
report.warning(`Playwright error on 'SelectByText' instruction : ${e.message}`);
|
|
325
325
|
return false;
|
|
326
326
|
}
|
|
327
327
|
});
|
|
@@ -338,7 +338,7 @@ export default class StdLib {
|
|
|
338
338
|
return true;
|
|
339
339
|
}
|
|
340
340
|
catch (e) {
|
|
341
|
-
report.warning(`
|
|
341
|
+
report.warning(`Playwright error on 'SelectByText' instruction : ${e.message}`);
|
|
342
342
|
return false;
|
|
343
343
|
}
|
|
344
344
|
});
|
|
@@ -363,11 +363,11 @@ export default class StdLib {
|
|
|
363
363
|
await elem.selectOption({ index: +data });
|
|
364
364
|
return true;
|
|
365
365
|
}
|
|
366
|
-
report.warning(`
|
|
366
|
+
report.warning(`Playwright error on 'HasOption' instruction : '${by}' is an invalid value for 'By' parameter`);
|
|
367
367
|
return false;
|
|
368
368
|
}
|
|
369
369
|
catch (e) {
|
|
370
|
-
report.warning(`
|
|
370
|
+
report.warning(`Playwright error on 'SelectByText' instruction : ${e.message}`);
|
|
371
371
|
return false;
|
|
372
372
|
}
|
|
373
373
|
});
|
|
@@ -390,12 +390,12 @@ export default class StdLib {
|
|
|
390
390
|
return true;
|
|
391
391
|
}
|
|
392
392
|
else {
|
|
393
|
-
report.warning(`
|
|
393
|
+
report.warning(`Playwright error on 'uploadFile' instruction : No active page`);
|
|
394
394
|
return false;
|
|
395
395
|
}
|
|
396
396
|
}
|
|
397
397
|
catch (e) {
|
|
398
|
-
report.warning(`
|
|
398
|
+
report.warning(`Playwright error on 'uploadFile' instruction : ${e.message}`);
|
|
399
399
|
return false;
|
|
400
400
|
}
|
|
401
401
|
});
|
|
@@ -415,12 +415,12 @@ export default class StdLib {
|
|
|
415
415
|
return true;
|
|
416
416
|
}
|
|
417
417
|
else {
|
|
418
|
-
report.warning(`
|
|
418
|
+
report.warning(`Playwright error on 'uploadFile' instruction : No active page`);
|
|
419
419
|
return false;
|
|
420
420
|
}
|
|
421
421
|
}
|
|
422
422
|
catch (e) {
|
|
423
|
-
report.warning(`
|
|
423
|
+
report.warning(`Playwright error on 'uploadFile' instruction : ${e.message}`);
|
|
424
424
|
return false;
|
|
425
425
|
}
|
|
426
426
|
});
|
|
@@ -433,3 +433,93 @@ function delay(t) {
|
|
|
433
433
|
}, t);
|
|
434
434
|
});
|
|
435
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
|
+
}
|
|
481
|
+
async function complexClick2(elem) {
|
|
482
|
+
const timeout = 1000;
|
|
483
|
+
let retry = false;
|
|
484
|
+
let force = false;
|
|
485
|
+
try {
|
|
486
|
+
await elem.dispatchEvent('click', undefined, { timeout });
|
|
487
|
+
}
|
|
488
|
+
catch (e) {
|
|
489
|
+
const { message } = e;
|
|
490
|
+
console.log('> Failed click action with dispatchEvent :', message);
|
|
491
|
+
if (message.match(/Timeout/)) {
|
|
492
|
+
console.log('> Retry click action with default options');
|
|
493
|
+
retry = true;
|
|
494
|
+
}
|
|
495
|
+
else {
|
|
496
|
+
throw new Error(message);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
if (retry) {
|
|
500
|
+
try {
|
|
501
|
+
await elem.click({ timeout });
|
|
502
|
+
}
|
|
503
|
+
catch (e) {
|
|
504
|
+
const { message } = e;
|
|
505
|
+
console.log('> Failed click action with default options :', message);
|
|
506
|
+
console.log('> Retry click action with standard mode');
|
|
507
|
+
if (message.match(/Timeout/)) {
|
|
508
|
+
console.log('> Retry click action with force option');
|
|
509
|
+
force = true;
|
|
510
|
+
}
|
|
511
|
+
else {
|
|
512
|
+
throw new Error(message);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
if (force) {
|
|
517
|
+
try {
|
|
518
|
+
await elem.click({ timeout, force });
|
|
519
|
+
}
|
|
520
|
+
catch (e) {
|
|
521
|
+
const { message } = e;
|
|
522
|
+
throw new Error(message);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
}
|