Skip to content

Commit

Permalink
feat: Fallback to ios-deploy usage if ios-device lib fails to install…
Browse files Browse the repository at this point in the history
… the app bundle (appium#1098)
  • Loading branch information
mykola-mokhnach authored Oct 28, 2019
1 parent 76bf71d commit 37c891a
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions lib/ios-deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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) {
Expand Down

0 comments on commit 37c891a

Please sign in to comment.