appium-android-driver
Version:
Android UiAutomator and Chrome support for Appium
72 lines • 2.48 kB
JavaScript
/* eslint-disable @typescript-eslint/no-unused-vars */
/**
* @module
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.findElOrEls = findElOrEls;
exports.doFindElementOrEls = doFindElementOrEls;
const lodash_1 = __importDefault(require("lodash"));
const driver_1 = require("appium/driver");
async function findElOrEls(strategy, selector, mult, context = '') {
if (!selector) {
throw new Error('Must provide a selector when finding elements');
}
const params = {
strategy,
selector,
context,
multiple: mult,
};
let element;
const doFind = async () => {
try {
element = await this.doFindElementOrEls(params);
}
catch (err) {
// if the error that comes back is from a proxied request, we need to
// unwrap it to its actual protocol error first
if ((0, driver_1.isErrorType)(err, driver_1.errors.ProxyRequestError)) {
err = err.getActualError(); // eslint-disable-line no-ex-assign
}
// now we have to inspect the error to determine if it is a no such
// element error, based on the shape of the error object from
// appium/driver
if ((0, driver_1.isErrorType)(err, driver_1.errors.NoSuchElementError)) {
// we are fine with this, just indicate a retry
return false;
}
throw err;
}
// we want to return false if we want to potentially try again
return !lodash_1.default.isEmpty(element);
};
try {
await this.implicitWaitForCondition(doFind);
}
catch (e) {
const err = e;
if (err.message && err.message.match(/Condition unmet/)) {
// only get here if we are looking for multiple elements
// condition was not met setting res to empty array
element = [];
}
else {
throw err;
}
}
if (mult) {
return element;
}
if (lodash_1.default.isEmpty(element)) {
throw new driver_1.errors.NoSuchElementError();
}
return element;
}
async function doFindElementOrEls(params) {
throw new driver_1.errors.NotImplementedError('Not implemented');
}
//# sourceMappingURL=find.js.map
;