Skip to content

Commit

Permalink
Merge pull request appium#3070 from paymand/ios_app_setup
Browse files Browse the repository at this point in the history
Proper install/uninstall when running on iOS device.
  • Loading branch information
jlipps committed Jul 8, 2014
2 parents cd48e76 + 528b8fa commit 8950a3a
Showing 1 changed file with 65 additions and 19 deletions.
84 changes: 65 additions & 19 deletions lib/devices/ios/ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ IOS.prototype.start = function (cb, onDie) {
this.setPreferences.bind(this),
this.startLogCapture.bind(this),
this.setDeviceAndLaunchSimulator.bind(this),
this.setBundleIdFromApp.bind(this),
this.installToRealDevice.bind(this),
this.startInstruments.bind(this),
this.onInstrumentsLaunch.bind(this),
Expand Down Expand Up @@ -714,32 +715,62 @@ IOS.prototype.detectUdid = function (cb) {
}
};

IOS.prototype.setBundleIdFromApp = function (cb) {
// This method will try to extract the bundleId from the app
if (this.args.app === null) {
// We aleady have a bundle Id
cb();
} else {
this.getBundleIdFromApp(function (err, bundleId) {
if (err) {
logger.error("Could not set the bundleId from app.");
return cb(err);
}
this.args.bundleId = bundleId;
cb();
}.bind(this));
}
};

IOS.prototype.installToRealDevice = function (cb) {
// if user has passed in desiredCaps.autoLaunch = false
// meaning they will manage app install / launching
if (this.args.autoLaunch === false) {
cb();
} else {
if (this.args.udid) {
if (this.args.ipa && this.args.bundleId) {
this.installIpa(cb);
} else if (this.args.ipa) {
var msg = "You specified a UDID and ipa but did not include the bundle " +
"id";
logger.error(msg);
cb(new Error(msg));
} else if (this.args.app) {
try {
this.realDevice = this.getIDeviceObj();
} catch (e) {
return cb(e);
}
this.installApp(this.args.app, cb);
} else {
logger.debug("Real device specified but no ipa or app path, assuming bundle ID is " +
"on device");
cb();
try {
this.realDevice = this.getIDeviceObj();
} catch (e) {
return cb(e);
}
this.isAppInstalled(this.args.bundleId, function (err) {
if (err) {
logger.debug("App is not installed. Will try to install the app.");
} else {
logger.debug("App is installed.");
if (this.args.fullReset) {
logger.debug("fullReset requested. Forcing app install.");
} else {
logger.debug("fullReset not requested. No need to install.");
return cb();
}
}
if (this.args.ipa && this.args.bundleId) {
this.installIpa(cb);
} else if (this.args.ipa) {
var msg = "You specified a UDID and ipa but did not include the bundle " +
"id";
logger.error(msg);
cb(new Error(msg));
} else if (this.args.app) {
this.installApp(this.args.app, cb);
} else {
logger.debug("Real device specified but no ipa or app path, assuming bundle ID is " +
"on device");
cb();
}
}.bind(this));
} else {
logger.debug("No device id or app, not installing to real device.");
cb();
Expand Down Expand Up @@ -883,6 +914,20 @@ IOS.prototype.setDeviceTypeInInfoPlist = function (deviceTypeCode, cb) {
});
};

IOS.prototype.getBundleIdFromApp = function (cb) {
logger.debug("Getting bundle ID from app");
var plist = path.resolve(this.args.app, "Info.plist");
bplistParse.parseFile(plist, function (err, obj) {
if (err) {
logger.error("Could not parse plist file at " + plist);
cb(err, null);
} else {
logger.debug("Parsed app Info.plist");
cb(null, obj[0].CFBundleIdentifier);
}
});
};

IOS.prototype.checkDeviceAvailable = function (cb) {
if (this.iOSSDKVersion >= 7.1) {
logger.debug("Checking whether instruments supports our device string");
Expand Down Expand Up @@ -1107,7 +1152,8 @@ IOS.prototype.cleanupAppState = function (cb) {
}
} else {
logger.debug("No folders found to remove");
if (this.realDevice && this.args.bundleId) {
if (this.realDevice && this.args.bundleId && this.args.fullReset) {
logger.debug("fullReset requested. Will try to uninstall the app.");
var bundleId = this.args.bundleId;
this.realDevice.remove(bundleId, function (err) {
if (err) {
Expand Down

0 comments on commit 8950a3a

Please sign in to comment.