mirror of
https://github.com/appium/appium.git
synced 2026-05-08 03:49:30 -05:00
Merge pull request #3070 from paymand/ios_app_setup
Proper install/uninstall when running on iOS device.
This commit is contained in:
+65
-19
@@ -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),
|
||||
@@ -714,6 +715,23 @@ 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
|
||||
@@ -721,25 +739,38 @@ IOS.prototype.installToRealDevice = function (cb) {
|
||||
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();
|
||||
@@ -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");
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user