diff --git a/lib/ios-deploy.js b/lib/ios-deploy.js index 6dee9c7ea..b390bdc41 100644 --- a/lib/ios-deploy.js +++ b/lib/ios-deploy.js @@ -5,11 +5,13 @@ import { services, utilities } from 'appium-ios-device'; import B from 'bluebird'; import log from './logger'; import _ from 'lodash'; +import { exec } from 'teen_process'; const APPLICATION_INSTALLED_NOTIFICATION = 'com.apple.mobile.application_installed'; const INSTALLATION_STAGING_DIR = 'PublicStaging'; const ITEM_PUSH_TIMEOUT = 30 * 1000; const APPLICATION_NOTIFICATION_TIMEOUT = 30 * 1000; +const IOS_DEPLOY = 'ios-deploy'; class IOSDeploy { @@ -31,15 +33,30 @@ class IOSDeploy { } async install (app) { - const start = new Date(); + const start = process.hrtime(); try { const bundlePathOnPhone = await this.pushAppBundle(app); await this.installApplication(bundlePathOnPhone); - log.info(`Installation is successful after ${new Date() - start}ms`); } catch (e) { - log.error('Error was thrown during the installation process', e); - throw new Error(`Could not install app: '${e.message}'`); + log.warn('An error was thrown during the installation process. ' + + `Falling back to ${IOS_DEPLOY}`, e); + try { + await fs.which(IOS_DEPLOY); + } catch (e1) { + throw new Error(`Could not install '${app}': ` + + `${IOS_DEPLOY} utility has not been found in PATH. Is it installed?`); + } + try { + await exec(IOS_DEPLOY, [ + '--id', this.udid, + '--bundle', app, + ]); + } catch (e1) { + throw new Error(`Could not install '${app}': ${e1.stderr || e1.stdout || e1.message}`); + } } + const [seconds, nanos] = process.hrtime(start); + log.info(`Installation is successful after ${(seconds + nanos / 1e9).toFixed(3)}s`); } async installApplication (bundlePathOnPhone) {