// start of string, or preceded by a space // Danger! Recursive // (relatively safe since the DOM tree is only so deep) const getOffsetTop = ( element ) => { const offset = element.offsetTop; return element.offsetParent ? offset + getOffsetTop( element.offsetParent ) : offset; }
// Tactile multi-touch support (#100) this.container.addEventListener("touchstart", e => { e.preventDefault(); for (let i = 0; i < e.changedTouches.length; i++) { let key = e.changedTouches[i].target.offsetParent; if (key.getAttribute("class").startsWith("keyboard_key")) { key.setAttribute("class", key.getAttribute("class")+" active"); key.onmousedown({preventDefault: () => {return true}}); } else { key = e.changedTouches[i].target; if (key.getAttribute("class").startsWith("keyboard_key")) { key.setAttribute("class", key.getAttribute("class")+" active"); key.onmousedown({preventDefault: () => {return true}}); } } } });
let dropKeyTouchHandler = e => { e.preventDefault(); for (let i = 0; i < e.changedTouches.length; i++) { let key = e.changedTouches[i].target.offsetParent; if (key.getAttribute("class").startsWith("keyboard_key")) { key.setAttribute("class", key.getAttribute("class").replace("active", "")); key.onmouseup({preventDefault: () => {return true}}); } else { key = e.changedTouches[i].target; if (key.getAttribute("class").startsWith("keyboard_key")) { key.setAttribute("class", key.getAttribute("class").replace("active", "")); key.onmouseup({preventDefault: () => {return true}}); } } } }
/** * {{> waitNumberOfVisibleElements }} * {{ react }} */ async waitNumberOfVisibleElements(locator, num, sec) { const waitTimeout = sec ? sec * 1000 : this.options.waitForTimeout; locator = new Locator(locator, 'css'); const matcher = await this.context; let waiter; const context = await this._getContext(); if (locator.isCSS()) { const visibleFn = function (locator, num) { const els = document.querySelectorAll(locator); if (!els || els.length === 0) { return false; } return Array.prototype.filter.call(els, el => el.offsetParent !== null).length === num; }; waiter = context.waitForFunction(visibleFn, { timeout: waitTimeout }, locator.value, num); } else { const visibleFn = function (locator, $XPath, num) { eval($XPath); // eslint-disable-line no-eval return $XPath(null, locator).filter(el => el.offsetParent !== null).length === num; }; waiter = context.waitForFunction(visibleFn, { timeout: waitTimeout }, locator.value, $XPath.toString(), num); } return waiter.catch((err) => { throw new Error(`The number of elements (${locator.toString()}) is not ${num} after ${waitTimeout / 1000} sec\n${err.message}`); }); }
offsetParent = elem.offsetParent || doc.documentElement; while ( offsetParent && ( offsetParent === doc.body || offsetParent === doc.documentElement ) && var offsetParent = this.offsetParent; offsetParent = offsetParent.offsetParent;
offsetParent = this.offsetParent(), var offsetParent = this.offsetParent || document.body; while ( offsetParent && (!rroot.test(offsetParent.nodeName) && jQuery.css(offsetParent, "position") === "static") ) { offsetParent = offsetParent.offsetParent;
offsetParent = this.offsetParent(); var offsetParent = this.offsetParent || docElem; offsetParent = offsetParent.offsetParent;
} else { offsetParent = this.offsetParent(); var offsetParent = this.offsetParent || docElem; offsetParent = offsetParent.offsetParent;
offsetParent = this.offsetParent(); var offsetParent = this.offsetParent || docElem; offsetParent = offsetParent.offsetParent;
offsetParent = this.offsetParent(); var offsetParent = this.offsetParent; offsetParent = offsetParent.offsetParent;
} else { offsetParent = this.offsetParent(); var offsetParent = this.offsetParent || document.documentElement; while ( offsetParent && ( !jQuery.nodeName( offsetParent, "html" ) && jQuery.css( offsetParent, "position") === "static" ) ) { offsetParent = offsetParent.offsetParent;
let dropKeyTouchHandler = e => { e.preventDefault(); for (let i = 0; i < e.changedTouches.length; i++) { let key = e.changedTouches[i].target.offsetParent; if (key.getAttribute("class").startsWith("keyboard_key")) { key.setAttribute("class", key.getAttribute("class").replace("active", "")); key.onmouseup({preventDefault: () => {return true}}); } else { key = e.changedTouches[i].target; if (key.getAttribute("class").startsWith("keyboard_key")) { key.setAttribute("class", key.getAttribute("class").replace("active", "")); key.onmouseup({preventDefault: () => {return true}}); } } } }
// Tactile multi-touch support (#100) this.container.addEventListener("touchstart", e => { e.preventDefault(); for (let i = 0; i < e.changedTouches.length; i++) { let key = e.changedTouches[i].target.offsetParent; if (key.getAttribute("class").startsWith("keyboard_key")) { key.setAttribute("class", key.getAttribute("class")+" active"); key.onmousedown({preventDefault: () => {return true}}); } else { key = e.changedTouches[i].target; if (key.getAttribute("class").startsWith("keyboard_key")) { key.setAttribute("class", key.getAttribute("class")+" active"); key.onmousedown({preventDefault: () => {return true}}); } } } });
/** * {{> waitNumberOfVisibleElements }} * */ async waitNumberOfVisibleElements(locator, num, sec) { const waitTimeout = sec ? sec * 1000 : this.options.waitForTimeout; locator = new Locator(locator, 'css'); const matcher = await this.context; let waiter; const context = await this._getContext(); if (locator.isCSS()) { const visibleFn = function ([locator, num]) { const els = document.querySelectorAll(locator); if (!els || els.length === 0) { return false; } return Array.prototype.filter.call(els, el => el.offsetParent !== null).length === num; }; waiter = context.waitForFunction(visibleFn, [locator.value, num], { timeout: waitTimeout }); } else { const visibleFn = function ([locator, $XPath, num]) { eval($XPath); // eslint-disable-line no-eval return $XPath(null, locator).filter(el => el.offsetParent !== null).length === num; }; waiter = context.waitForFunction(visibleFn, [locator.value, $XPath.toString(), num], { timeout: waitTimeout }); } return waiter.catch((err) => { throw new Error(`The number of elements (${locator.toString()}) is not ${num} after ${waitTimeout / 1000} sec\n${err.message}`); }); }
} else { offsetParent = this.offsetParent(); var offsetParent = this.offsetParent || docElem; while ( offsetParent && ( !jQuery.nodeName( offsetParent, "html" ) && jQuery.css( offsetParent, "position") === "static" ) ) { offsetParent = offsetParent.offsetParent;