Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
commands.setWindow = async function setWindow (name, skipReadyCheck) {
try {
await this.setContext(name, _.noop, skipReadyCheck);
} catch (err) {
// translate the error in terms of windows
throw isErrorType(err, errors.NoSuchContextError)
? new errors.NoSuchWindowError()
: err;
}
};
let 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 (isErrorType(err, 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-base-driver
if (isErrorType(err, 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 !_.isEmpty(element);
};
let 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 (isErrorType(err, 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-base-driver
if (isErrorType(err, 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 !_.isEmpty(element);
};
commands.performGesture = async function (gesture) {
try {
return await this.doTouchAction(gesture.action, gesture.options || {});
} catch (e) {
// sometime the element is not available when releasing, retry without it
if (isErrorType(e, errors.NoSuchElementError) && gesture.action === 'release' &&
gesture.options.element) {
delete gesture.options.element;
log.debug(`retrying release without element opts: ${gesture.options}.`);
return await this.doTouchAction(gesture.action, gesture.options || {});
}
throw e;
}
};
helpers.performGesture = async function performGesture (gesture) {
try {
return await this.doTouchAction(gesture.action, gesture.options || {});
} catch (e) {
// sometime the element is not available when releasing, retry without it
if (isErrorType(e, errors.NoSuchElementError) && gesture.action === 'release' &&
gesture.options.element) {
delete gesture.options.element;
log.debug(`retrying release without element opts: ${gesture.options}.`);
return await this.doTouchAction(gesture.action, gesture.options || {});
}
throw e;
}
};
alert.setText = async (value) => {
try {
let textView = await this.findNativeElementOrElements('class name', 'XCUIElementTypeTextField', false, util.unwrapElement(alert));
await this.proxyCommand(`/element/${util.unwrapElement(textView)}/value `, 'POST', {value});
} catch (err) {
if (isErrorType(err, errors.NoSuchElementError)) {
throw new Error('Tried to set text of an alert that was not a prompt');
}
throw err;
}
};
let doFind = async () => {
try {
element = await this.doFindElementOrEls(params);
} catch (err) {
if (isErrorType(err, errors.NoSuchElementError)) {
return false;
}
throw err;
}
return !_.isEmpty(element);
};