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: Fallback to ios-deploy usage if ios-device lib fails to install the app bundle #1098

Merged
merged 4 commits into from
Oct 28, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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