Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add setting geolocation by set-simulator-location as the first method #249

Merged
merged 9 commits into from
Dec 7, 2019
Prev Previous commit
Make three set location as an array exec
  • Loading branch information
KazuCocoa committed Dec 6, 2019
commit f530c792212748d68658f091d86a467f3f4233ee
36 changes: 15 additions & 21 deletions lib/simulator-xcode-8.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,29 +286,23 @@ class SimulatorXcode8 extends SimulatorXcode7 {
* @throws {Error} If there was an error while setting the location
*/
async setGeolocation (latitude, longitude) {
try {
await setLocationWithLyft(this.udid, latitude, longitude);
return true;
} catch (e) {
log.warn(e.message);
}

try {
await setLocationWithIdb(this.idb, latitude, longitude);
return true;
} catch (e) {
log.warn(e.message);
}
const locationSetters = [
async () => await setLocationWithLyft(this.udid, latitude, longitude),
async () => await setLocationWithIdb(this.idb, latitude, longitude),
async () => await setLocationWithAppleScript(this, latitude, longitude)
];

try {
await setLocationWithAppleScript(this, latitude, longitude);
return true;
} catch (e) {
log.warn(e.message);
let lastError;
for (const setter of locationSetters) {
try {
await setter();
return true;
} catch (e) {
log.info(e.message);
lastError = e;
}
}

log.errorAndThrow('Failed to set geolocation with possible methods. ' +
'Please read the server log what kind of methods Appium tried.');
throw lastError;
}
}

Expand Down