@wdio/image-comparison-core
Version:
Image comparison core module for @wdio/visual-service - WebdriverIO visual testing framework
26 lines (25 loc) • 855 B
JavaScript
/**
* Scroll to y = variable position in the screen
*/
/* istanbul ignore next */
export default function scrollToPosition(yPosition) {
const htmlNode = document.querySelector('html');
const bodyNode = document.querySelector('body');
if (htmlNode.scrollHeight > htmlNode.clientHeight) {
htmlNode.scrollTop = yPosition;
// Did we scroll to the right position?
if (htmlNode.scrollTop === yPosition) {
return;
}
}
// If not then try the body
if (bodyNode.scrollHeight > bodyNode.clientHeight) {
bodyNode.scrollTop = yPosition;
// Did we scroll to the right position?
if (bodyNode.scrollTop === yPosition) {
return;
}
}
// If not then try the document
(document.scrollingElement || document.documentElement).scrollTop = yPosition;
}