webdriverio 8.16.17 → 8.16.18
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.
|
@@ -38,59 +38,59 @@ export async function scrollIntoView(options = { block: 'start', inline: 'neares
|
|
|
38
38
|
if (browser.isMobile) {
|
|
39
39
|
return scrollIntoViewWeb.call(this, options);
|
|
40
40
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
options
|
|
62
|
-
|
|
63
|
-
if (options === false) {
|
|
64
|
-
options = { block: 'end', inline: 'nearest' };
|
|
65
|
-
}
|
|
66
|
-
if (options && typeof options === 'object') {
|
|
67
|
-
const { block, inline } = options;
|
|
68
|
-
if (block === 'nearest') {
|
|
69
|
-
const nearestYDistance = Math.min(...Object.values(deltaByOption).map(delta => delta.y));
|
|
70
|
-
deltaY = Object.values(deltaByOption).find(delta => delta.y === nearestYDistance).y;
|
|
71
|
-
}
|
|
72
|
-
else if (block) {
|
|
73
|
-
deltaY = deltaByOption[block].y;
|
|
41
|
+
try {
|
|
42
|
+
/**
|
|
43
|
+
* by default the WebDriver action scrolls the element just into the
|
|
44
|
+
* viewport. In order to stay complaint with `Element.scrollIntoView()`
|
|
45
|
+
* we need to adjust the values a bit.
|
|
46
|
+
*/
|
|
47
|
+
const elemRect = await browser.getElementRect(this.elementId);
|
|
48
|
+
const viewport = await browser.getWindowSize();
|
|
49
|
+
let [scrollX, scrollY] = await browser.execute(() => [
|
|
50
|
+
window.scrollX, window.scrollY
|
|
51
|
+
]);
|
|
52
|
+
// handle elements outside of the viewport
|
|
53
|
+
scrollX = elemRect.x <= viewport.width ? elemRect.x : viewport.width / 2;
|
|
54
|
+
scrollY = elemRect.y <= viewport.height ? elemRect.y : viewport.height / 2;
|
|
55
|
+
const deltaByOption = {
|
|
56
|
+
start: { y: elemRect.y - elemRect.height, x: elemRect.x - elemRect.width },
|
|
57
|
+
center: { y: elemRect.y - Math.round((viewport.height - elemRect.height) / 2), x: elemRect.x - Math.round((viewport.width - elemRect.width) / 2) },
|
|
58
|
+
end: { y: elemRect.y - (viewport.height - elemRect.height), x: elemRect.x - (viewport.width - elemRect.width) }
|
|
59
|
+
};
|
|
60
|
+
let [deltaX, deltaY] = [deltaByOption.start.x, deltaByOption.start.y];
|
|
61
|
+
if (options === true) {
|
|
62
|
+
options = { block: 'start', inline: 'nearest' };
|
|
74
63
|
}
|
|
75
|
-
if (
|
|
76
|
-
|
|
77
|
-
deltaX = Object.values(deltaByOption).find(delta => delta.x === nearestXDistance).x;
|
|
64
|
+
if (options === false) {
|
|
65
|
+
options = { block: 'end', inline: 'nearest' };
|
|
78
66
|
}
|
|
79
|
-
|
|
80
|
-
|
|
67
|
+
if (options && typeof options === 'object') {
|
|
68
|
+
const { block, inline } = options;
|
|
69
|
+
if (block === 'nearest') {
|
|
70
|
+
const nearestYDistance = Math.min(...Object.values(deltaByOption).map(delta => delta.y));
|
|
71
|
+
deltaY = Object.values(deltaByOption).find(delta => delta.y === nearestYDistance).y;
|
|
72
|
+
}
|
|
73
|
+
else if (block) {
|
|
74
|
+
deltaY = deltaByOption[block].y;
|
|
75
|
+
}
|
|
76
|
+
if (inline === 'nearest') {
|
|
77
|
+
const nearestXDistance = Math.min(...Object.values(deltaByOption).map(delta => delta.x));
|
|
78
|
+
deltaX = Object.values(deltaByOption).find(delta => delta.x === nearestXDistance).x;
|
|
79
|
+
}
|
|
80
|
+
else if (inline) {
|
|
81
|
+
deltaX = deltaByOption[inline].x;
|
|
82
|
+
}
|
|
81
83
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
try {
|
|
87
|
-
return await browser.action('wheel')
|
|
84
|
+
// take into account the current scroll position
|
|
85
|
+
deltaX = Math.round(deltaX - scrollX);
|
|
86
|
+
deltaY = Math.round(deltaY - scrollY);
|
|
87
|
+
await browser.action('wheel')
|
|
88
88
|
.scroll({ duration: 0, x: deltaX, deltaY, origin: this })
|
|
89
89
|
.perform();
|
|
90
90
|
}
|
|
91
91
|
catch (err) {
|
|
92
92
|
log.warn(`Failed to execute "scrollIntoView" using WebDriver Actions API: ${err.message}!\n` +
|
|
93
93
|
'Re-attempting using `Element.scrollIntoView` via Web API.');
|
|
94
|
-
|
|
94
|
+
await scrollIntoViewWeb.call(this, options);
|
|
95
95
|
}
|
|
96
96
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webdriverio",
|
|
3
3
|
"description": "Next-gen browser and mobile automation test framework for Node.js",
|
|
4
|
-
"version": "8.16.
|
|
4
|
+
"version": "8.16.18",
|
|
5
5
|
"homepage": "https://webdriver.io",
|
|
6
6
|
"author": "Christian Bromann <mail@bromann.dev>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -100,5 +100,5 @@
|
|
|
100
100
|
"optional": true
|
|
101
101
|
}
|
|
102
102
|
},
|
|
103
|
-
"gitHead": "
|
|
103
|
+
"gitHead": "2045bb85cbd7323d130d1458c75aba550f29f544"
|
|
104
104
|
}
|