webdriverio-automation
Version:
WebdriverIO-Automation android ios project
30 lines (24 loc) • 817 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _default = (_, script, dataProperty, dataFlag, ...args) => {
window.arguments = args;
const result = eval(script);
let tmpResult = result instanceof NodeList ? Array.from(result) : result;
const isResultArray = Array.isArray(tmpResult);
tmpResult = isResultArray ? tmpResult : [tmpResult];
if (tmpResult.find(r => r instanceof HTMLElement)) {
tmpResult = tmpResult.map((r, i) => {
if (r instanceof HTMLElement) {
const dataPropertyValue = `${dataFlag}_${i}`;
r.setAttribute(dataProperty, dataPropertyValue);
return dataPropertyValue;
}
return result;
});
}
return isResultArray ? tmpResult : tmpResult[0];
};
exports.default = _default;