Skip to content

Commit

Permalink
iOS. Add --keep-keychains option and desired capability keepKeyChains
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Smolensky committed Mar 3, 2014
1 parent 4163cdb commit f30631d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/caps.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ Appium server capabilities
|`safariAllowPopups`| (Sim-only) Allow javascript to open new windows in Safari. Default keeps current sim setting|`true` or `false`|
|`safariIgnoreFraudWarning`| (Sim-only) Prevent Safari from showing a fraudulent website warning. Default keeps current sim setting.|`true` or `false`|
|`safariOpenLinksInBackground`| (Sim-only) Whether Safari should allow links to open in new windows. Default keeps current sim setting.|`true` or `false`|
|`keepKeyChains`| (Sim-only) Whether to keep keychains (Library/Keychains) when appium session is started/finished|`true` or `false`|
1 change: 1 addition & 0 deletions docs/server-args.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,4 @@ All flags are optional, but some are required in conjunction with certain others
|`--key-alias`|androiddebugkey|(Android-only) Key alias||
|`--key-password`|android|(Android-only) Key password||
|`--show-config`|false|Show info about the appium server configuration and exit||
|`--keep-keychains`|false|(iOS) Whether to keep keychains (Library/Keychains) when appium session is started/finished||
1 change: 1 addition & 0 deletions lib/appium.js
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ Appium.prototype.initDevice = function () {
, flakeyRetries: this.args.backendRetries
, origAppPath: this.origAppPath
, autoAcceptAlerts: this.desiredCapabilities.autoAcceptAlerts
, keepKeyChains: this.args.keepKeyChains || this.desiredCapabilities.keepKeyChains
};
if (this.desiredCapabilities.safari || this.desiredCapabilities.iwebview) {
this.device = new Safari(iosOpts);
Expand Down
13 changes: 10 additions & 3 deletions lib/devices/ios/ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var path = require('path')
, iOSController = require('./ios-controller.js')
, iOSHybrid = require('./ios-hybrid.js')
, settings = require('./settings.js')
, mkdirp = require('mkdirp')
, getSimRoot = settings.getSimRoot
, fruitstrap = path.resolve(__dirname, '../../../build/fruitstrap/fruitstrap')
, UnknownError = errors.UnknownError;
Expand Down Expand Up @@ -62,6 +63,7 @@ IOS.prototype.init = function (args) {
this.xcodeVersion = null;
this.iOSSDKVersion = null;
this.reset = args.reset;
this.keepKeyChains = args.keepKeyChains;
this.fullReset = args.fullReset;
this.automationTraceTemplatePath = args.automationTraceTemplatePath;
this.removeTraceDir = args.removeTraceDir;
Expand Down Expand Up @@ -892,16 +894,21 @@ IOS.prototype.cleanupAppState = function (cb) {
var filesExamined = 0;
var maybeNext = function () {
if (filesExamined === files.length) {
if (this.keepKeyChains) {
// files[0] is always the Applications dir
// we want to keep it around so --keep-keychains logic will work
mkdirp.sync(files[0]);
}
cb();
}
};
}.bind(this);
if (files.length) {
_.each(files, function (file) {
rimraf(file, function () {
logger.info("Deleted " + file);
filesExamined++;
maybeNext();
});
}.bind(this));

var root = path.dirname(file);
var tcc = path.join(root, 'Library/TCC');
Expand All @@ -927,7 +934,7 @@ IOS.prototype.cleanupAppState = function (cb) {
}

var keychain = path.join(root, 'Library/Keychains');
if (fs.existsSync(keychain)) {
if (!this.keepKeyChains && fs.existsSync(keychain)) {
rimraf.sync(keychain);
logger.info("Deleted " + keychain);
}
Expand Down
9 changes: 9 additions & 0 deletions lib/server/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,15 @@ var args = [
, action: 'storeTrue'
, required: false
, help: 'Show info about the appium server configuration and exit'
}],

[['--keep-keychains'], {
defaultValue: false
, dest: 'keepKeyChains'
, action: 'storeTrue'
, required: false
, help: "(iOS) Whether to keep keychains (Library/Keychains) when reset app between sessions"
, nargs: 0
}]
];

Expand Down

0 comments on commit f30631d

Please sign in to comment.