testaro 60.10.0 → 60.10.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/package.json +1 -1
- package/procs/identify.js +18 -11
- package/run.js +48 -48
package/package.json
CHANGED
package/procs/identify.js
CHANGED
|
@@ -30,9 +30,7 @@
|
|
|
30
30
|
// IMPORTS
|
|
31
31
|
|
|
32
32
|
// Module to get the XPath of an element.
|
|
33
|
-
const
|
|
34
|
-
xPath: require('playwright-dompath').xPath
|
|
35
|
-
};
|
|
33
|
+
const {xPath} = require('playwright-dompath');
|
|
36
34
|
|
|
37
35
|
// FUNCTIONS
|
|
38
36
|
|
|
@@ -42,7 +40,7 @@ const boxOf = exports.boxOf = async locator => {
|
|
|
42
40
|
const isVisible = await locator.isVisible();
|
|
43
41
|
if (isVisible) {
|
|
44
42
|
const box = await locator.boundingBox({
|
|
45
|
-
timeout:
|
|
43
|
+
timeout: 100
|
|
46
44
|
});
|
|
47
45
|
if (box) {
|
|
48
46
|
Object.keys(box).forEach(dim => {
|
|
@@ -72,22 +70,31 @@ const boxToString = exports.boxToString = box => {
|
|
|
72
70
|
}
|
|
73
71
|
};
|
|
74
72
|
// Adds a box ID and a path ID to an object.
|
|
75
|
-
const addIDs = async (
|
|
73
|
+
const addIDs = async (locator, recipient) => {
|
|
74
|
+
const locatorCount = await locator.count();
|
|
76
75
|
// If there is exactly 1 of them:
|
|
77
|
-
const locatorCount = await locators.count();
|
|
78
76
|
if (locatorCount === 1) {
|
|
79
77
|
// Add the box ID of the element to the result if none exists yet.
|
|
80
78
|
if (! recipient.boxID) {
|
|
81
|
-
const box = await boxOf(
|
|
79
|
+
const box = await boxOf(locator);
|
|
82
80
|
recipient.boxID = boxToString(box);
|
|
83
81
|
}
|
|
84
82
|
// If the element has no path ID yet in the result:
|
|
85
83
|
if (! recipient.pathID) {
|
|
86
|
-
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
84
|
+
let timeout;
|
|
85
|
+
const timer = new Promise(resolve => {
|
|
86
|
+
timeout = setTimeout(() => {
|
|
87
|
+
resolve({timedOut: true})
|
|
88
|
+
}, 500);
|
|
89
|
+
});
|
|
90
|
+
// Use Playwright to get the XPath.
|
|
91
|
+
const pathIDPromise = xPath(locator);
|
|
92
|
+
const pathID = await Promise.race([pathIDPromise, timer]);
|
|
93
|
+
// If the XPath was computed before being timed out:
|
|
90
94
|
if (typeof pathID === 'string') {
|
|
95
|
+
// Prevent the timeout from resolving.
|
|
96
|
+
clearTimeout(timeout);
|
|
97
|
+
// Add the XPath to the result.
|
|
91
98
|
recipient.pathID = pathID;
|
|
92
99
|
}
|
|
93
100
|
}
|
package/run.js
CHANGED
|
@@ -446,8 +446,54 @@ const launch = exports.launch = async (
|
|
|
446
446
|
});
|
|
447
447
|
});
|
|
448
448
|
const isTestaroTest = act.type === 'test' && act.which === 'testaro';
|
|
449
|
-
// If the
|
|
449
|
+
// If the launch is for a testaro test act:
|
|
450
450
|
if (isTestaroTest) {
|
|
451
|
+
// Add a script to the page to add a window method to get the XPath of an element.
|
|
452
|
+
await page.addInitScript(() => {
|
|
453
|
+
window.getXPath = element => {
|
|
454
|
+
if (! element || element.nodeType !== Node.ELEMENT_NODE) {
|
|
455
|
+
return '';
|
|
456
|
+
}
|
|
457
|
+
const segments = [];
|
|
458
|
+
// As long as the current node is an element:
|
|
459
|
+
while (element && element.nodeType === Node.ELEMENT_NODE) {
|
|
460
|
+
const tag = element.tagName.toLowerCase();
|
|
461
|
+
// If it is the html element:
|
|
462
|
+
if (element === document.documentElement) {
|
|
463
|
+
// Prepend it to the segment array
|
|
464
|
+
segments.unshift('html');
|
|
465
|
+
// Stop traversing.
|
|
466
|
+
break;
|
|
467
|
+
}
|
|
468
|
+
// Otherwise, get its parent node.
|
|
469
|
+
const parent = element.parentNode;
|
|
470
|
+
// If (abnormally) the parent node is not an element:
|
|
471
|
+
if (!parent || parent.nodeType !== Node.ELEMENT_NODE) {
|
|
472
|
+
// Prepend it to the segment array.
|
|
473
|
+
segments.unshift(tag);
|
|
474
|
+
// Stop traversing, leaving the segment array partial.
|
|
475
|
+
break;
|
|
476
|
+
}
|
|
477
|
+
let subscript = '';
|
|
478
|
+
// Get the subscript of the element.
|
|
479
|
+
const cohort = Array
|
|
480
|
+
.from(parent.childNodes)
|
|
481
|
+
.filter(
|
|
482
|
+
childNode => childNode.nodeType === Node.ELEMENT_NODE
|
|
483
|
+
&& childNode.tagName === element.tagName
|
|
484
|
+
);
|
|
485
|
+
if (cohort.length > 1) {
|
|
486
|
+
subscript = `[${cohort.indexOf(element) + 1}]`;
|
|
487
|
+
}
|
|
488
|
+
// Prepend the element identifier to the segment array.
|
|
489
|
+
segments.unshift(`${tag}${subscript}`);
|
|
490
|
+
// Continue the traversal with the parent of the current element.
|
|
491
|
+
element = parent;
|
|
492
|
+
}
|
|
493
|
+
// Return the XPath.
|
|
494
|
+
return `/${segments.join('/')}`;
|
|
495
|
+
};
|
|
496
|
+
});
|
|
451
497
|
// Add a script to the page to compute the accessible name of an element.
|
|
452
498
|
await page.addInitScript({path: require.resolve('./dist/nameComputation.js')});
|
|
453
499
|
// Add a script to the page to:
|
|
@@ -515,52 +561,6 @@ const launch = exports.launch = async (
|
|
|
515
561
|
pathID: ''
|
|
516
562
|
};
|
|
517
563
|
};
|
|
518
|
-
// Add a window method to get the XPath of an element.
|
|
519
|
-
window.getXPath = element => {
|
|
520
|
-
if (!element || element.nodeType !== Node.ELEMENT_NODE) {
|
|
521
|
-
return '';
|
|
522
|
-
}
|
|
523
|
-
const segments = [];
|
|
524
|
-
let el = element;
|
|
525
|
-
// As long as the current node is an element:
|
|
526
|
-
while (el && el.nodeType === Node.ELEMENT_NODE) {
|
|
527
|
-
const tag = el.tagName.toLowerCase();
|
|
528
|
-
// If it is the html element:
|
|
529
|
-
if (el === document.documentElement) {
|
|
530
|
-
// Prepend it to the segment array
|
|
531
|
-
segments.unshift('html');
|
|
532
|
-
// Stop traversing.
|
|
533
|
-
break;
|
|
534
|
-
}
|
|
535
|
-
// Otherwise, get its parent node.
|
|
536
|
-
const parent = el.parentNode;
|
|
537
|
-
// If (abnormally) the parent node is not an element:
|
|
538
|
-
if (!parent || parent.nodeType !== Node.ELEMENT_NODE) {
|
|
539
|
-
// Prepend it to the segment array.
|
|
540
|
-
segments.unshift(tag);
|
|
541
|
-
// Stop traversing, leaving the segment array partial.
|
|
542
|
-
break;
|
|
543
|
-
}
|
|
544
|
-
let subscript = '';
|
|
545
|
-
let sameTagCount = 0;
|
|
546
|
-
// Get the subscript of the element.
|
|
547
|
-
const cohort = Array
|
|
548
|
-
.from(parent.childNodes)
|
|
549
|
-
.filter(
|
|
550
|
-
childNode => childNode.nodeType === Node.ELEMENT_NODE
|
|
551
|
-
&& childNode.tagName === el.tagName
|
|
552
|
-
);
|
|
553
|
-
if (cohort.length > 1) {
|
|
554
|
-
subscript = `[${cohort.indexOf(el) + 1}]`;
|
|
555
|
-
}
|
|
556
|
-
// Prepend the element identifier to the segment array.
|
|
557
|
-
segments.unshift(`${tag}${subscript}`);
|
|
558
|
-
// Continue the traversal with the parent of the current element.
|
|
559
|
-
el = parent;
|
|
560
|
-
}
|
|
561
|
-
// Return the XPath.
|
|
562
|
-
return `/${segments.join('/')}`;
|
|
563
|
-
};
|
|
564
564
|
});
|
|
565
565
|
}
|
|
566
566
|
// Navigate to the specified URL.
|
|
@@ -1659,7 +1659,7 @@ const doActs = async (report, opts = {}) => {
|
|
|
1659
1659
|
// Replace the browser and navigate to the URL.
|
|
1660
1660
|
await launch(
|
|
1661
1661
|
report,
|
|
1662
|
-
'',
|
|
1662
|
+
'standardization',
|
|
1663
1663
|
'high',
|
|
1664
1664
|
specs[0],
|
|
1665
1665
|
specs[1]
|