Merge pull request #2718 from jlipps/strict-caps

add --strict-caps mode
This commit is contained in:
Jonathan Lipps
2014-05-30 16:58:37 -07:00
6 changed files with 194 additions and 10 deletions
+14 -3
View File
@@ -12,6 +12,10 @@
|`browserName`|Name of mobile web browser to automate. Should be an empty string if automating an app instead.|'Safari' for iOS and 'Chrome', 'Chromium', or 'Browser' for Android|
|`newCommandTimeout`|How long (in seconds) Appium will wait for a new command from the client before assuming the client quit and ending the session|e.g. `60`|
|`autoLaunch`|Whether to have Appium install and launch the app automatically. Default `true`|`true`, `false`|
|`language`| (Sim/Emu-only) Language to set for the iOS Simulator|e.g. `fr`|
|`locale`| (Sim/Emu-only) Locale to set for the iOS Simulator|e.g. `fr_CA`|
|`udid`| Unique device identifier of the connected physical device|e.g. `1ae203187fc012g`|
|`orientation`| (Sim/Emu-only) start in a certain orientation|`LANDSCAPE` or `PORTRAIT`|
### Android Only
@@ -26,8 +30,16 @@
|`deviceReadyTimeout`| Timeout in seconds while waiting for device to become ready|`5`|
|`androidCoverage`| Fully qualified instrumentation class. Passed to -w in adb shell am instrument -e coverage true -w | `com.my.Pkg/com.my.Pkg.instrumentation.MyInstrumentation`|
|`enablePerformanceLogging`| (Chrome and webview only) Enable Chromedriver's performance logging (default `false`)| `true`, `false`|
|`androidDeviceReadyTimeout`|Timeout in seconds used to wait for a device to become ready after booting|e.g., `30`|
|`avd`| Name of avd to launch|e.g., `api19`|
|`avdLaunchTimeout`| How long to wait in milliseconds for an avd to launch and connect to ADB (default `120000`)| `300000`|
|`avdReadyTimeout`| How long to wait in milliseconds for an avd to finish its boot animations (default `120000`)| `300000`|
|`avdArgs`| Additional emulator arguments used when launching an avd|e.g., `-netfast`|
|`useKeystore`| Use a custom keystore to sign apks, default `false`|`true` or `false`|
|`keystorePath`| Path to custom keystore, default ~/.android/debug.keystore|e.g., `/path/to.keystore`|
|`keystorePassword`| Password for custom keystore|e.g., `foo`|
|`keyAlias`| Alias for key |e.g., `androiddebugkey`|
|`keyPassword`| Password for key |e.g., `foo`|
### iOS Only
@@ -38,9 +50,7 @@
|----|-----------|-------|
|`calendarFormat`| (Sim-only) Calendar format to set for the iOS Simulator|e.g. `gregorian`|
|`bundleId`| Bundle ID of the app under test. Useful for starting an app on a real device or for using other caps which require the bundle ID during test startup|e.g. `io.appium.TestApp`|
|`language`| (Sim-only) Language to set for the iOS Simulator|e.g. `fr`|
|`launchTimeout`| Amount of time in ms to wait for instruments before assuming it hung and failing the session|e.g. `20000`|
|`locale`| (Sim-only) Locale to set for the iOS Simulator|e.g. `fr_CA`|
|`locationServicesEnabled`| (Sim-only) Force location services to be either on or off. Default is to keep current sim setting.|`true` or `false`|
|`locationServicesAuthorized`| (Sim-only) Set location services to be authorized or not authorized for app via plist, so that location services alert doesn't pop up. Default is to keep current sim setting. Note that if you use this setting you MUST also use the `bundleId` capability to send in your app's bundle ID.|`true` or `false`|
|`autoAcceptAlerts`| Accept iOS privacy access permission alerts (e.g., location, contacts, photos) automatically if they pop up. Default is false.|`true` or `false`|
@@ -49,4 +59,5 @@
|`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`|
|`keepKeyChains`| (Sim-only) Whether to keep keychains (Library/Keychains) when appium session is started/finished|`true` or `false`|
|`localizableStringsDir`| Where to look for localizable strings. Default `en.lproj`|`en.lproj`|
+2
View File
@@ -12,6 +12,7 @@ All flags are optional, but some are required in conjunction with certain others
|Flag|Default|Description|Example|
|----|-------|-----------|-------|
|`--shell`|null|Enter REPL mode||
|`--localizable-strings-dir`|en.lproj|IOS only: the relative path of the dir where Localizable.strings file resides |`--localizable-strings-dir en.lproj`|
|`--app`|null|IOS: abs path to simulator-compiled .app file or the bundle_id of the desired target on device; Android: abs path to .apk file|`--app /abs/path/to/my.app`|
|`--ipa`|null|(IOS-only) abs path to compiled .ipa file|`--ipa /abs/path/to/my.ipa`|
|`-q`, `--quiet`|false|Don't use verbose logging output||
@@ -68,4 +69,5 @@ All flags are optional, but some are required in conjunction with certain others
|`--show-config`|false|Show info about the appium server configuration and exit||
|`--command-timeout`|60|The default command timeout for the server to use for all sessions. Will still be overridden by newCommandTimeout cap||
|`--keep-keychains`|false|(iOS) Whether to keep keychains (Library/Keychains) when reset app between sessions||
|`--strict-caps`|false|Cause sessions to fail if desired caps are sent in that Appium does not recognize as valid for the selected device||
|`--tmp`|null|Absolute path to directory Appium can use to manage temporary files, like built-in iOS apps it needs to move around. On *nix/Mac defaults to /tmp, on Windows defaults to C:\Windows\Temp||
+3
View File
@@ -252,6 +252,9 @@ Appium.prototype.configure = function (args, desiredCaps, cb) {
try {
deviceType = this.getDeviceType(args, desiredCaps);
if (args.enforceStrictCaps) {
desiredCaps.checkStrictValidity(deviceType);
}
} catch (e) {
logger.error(e.message);
return cb(e);
+108 -7
View File
@@ -12,19 +12,66 @@ var okObjects = [
'launchTimeout'
];
var requiredCaps = [
'platformName'
, 'platformVersion'
, 'deviceName'
];
var generalCaps = requiredCaps.concat([
'automationName'
, 'app'
, 'browserName'
, 'newCommandTimeout'
, 'autoLaunch'
, 'language'
, 'locale'
, 'udid'
, 'orientation'
]);
var androidCaps = [
'appActivity'
, 'appPackage'
, 'appWaitActivity'
, 'appWaitPackage'
, 'deviceReadyTimeout'
, 'androidCoverage'
, 'enablePerformanceLogging'
, 'avdLaunchTimeout'
, 'avdReadyTimeout'
, 'avd'
, 'avdArgs'
, 'useKeystore'
, 'keystorePath'
, 'keystorePassword'
, 'keyAlias'
, 'keyPassword'
];
var iosCaps = [
'calendarFormat'
, 'bundleId'
, 'launchTimeout'
, 'locationServicesEnabled'
, 'locationServicesAuthorized'
, 'autoAcceptAlerts'
, 'nativeInstrumentsLib'
, 'nativeWebTap'
, 'safariAllowPopups'
, 'safariIgnoreFraudWarning'
, 'safariOpenLinksInBackground'
, 'keepKeyChains'
, 'localizableStringsDir'
];
var Capabilities = function (capabilities) {
this.warnings = {};
this.setDesired(capabilities);
_.each(this.desired, function (value, cap) {
if (_.contains(_.keys(capsConversion), cap)) {
warnDeprecated('capability', cap, capsConversion[cap]);
}
this[cap] = value;
}, this);
};
Capabilities.prototype.setDesired = function (caps) {
caps = _.clone(caps);
_.each(caps, function (value, cap) {
if (!_.contains(okObjects, cap) &&
typeof value === "object" &&
@@ -35,7 +82,61 @@ Capabilities.prototype.setDesired = function (caps) {
caps[cap] = JSON.stringify(value);
}
});
_.each(caps, function (value, cap) {
if (_.contains(_.keys(capsConversion), cap)) {
warnDeprecated('capability', cap, capsConversion[cap]);
caps[capsConversion[cap]] = value;
delete caps[cap];
}
});
this.desired = caps;
_.each(caps, function (value, cap) {
this[cap] = value;
}, this);
};
Capabilities.prototype.checkStrictValidity = function (deviceType) {
if (_.contains(["firefoxos", "selendroid"], deviceType)) {
logger.info("Not checking cap validity because we're proxying all caps " +
"to " + deviceType);
return;
}
logger.info("Checking caps according to strict mode");
var e = function (msg) { throw new Error(msg); };
var allValidCaps = [].concat(generalCaps, androidCaps, iosCaps);
var capsUsed = _.keys(this.desired);
var unknownCaps = _.difference(capsUsed, allValidCaps);
if (unknownCaps.length > 0) {
return e("Appium does not know about these desired capabilities: " +
JSON.stringify(unknownCaps) + ". Please remove unknown caps");
}
var forgottenRequiredCaps = _.difference(requiredCaps, capsUsed);
if (forgottenRequiredCaps.length > 0) {
return e("Appium requires the following caps to be passed in: " +
JSON.stringify(forgottenRequiredCaps));
}
if (_.difference(['app', 'browserName'], capsUsed).length > 1) {
return e("You must pass in either the 'app' or 'browserName' cap");
}
var validDeviceCaps = _.clone(generalCaps);
if (_.contains(["safari", "ios"], deviceType)) {
validDeviceCaps = validDeviceCaps.concat(iosCaps);
} else if (_.contains(["chrome", "android"], deviceType)) {
validDeviceCaps = validDeviceCaps.concat(androidCaps);
}
var unknownDeviceCaps = _.difference(capsUsed, validDeviceCaps);
if (unknownDeviceCaps.length > 0) {
return e("These capabilities are not valid for your device: " +
JSON.stringify(unknownDeviceCaps) + ". Please remove them");
}
};
Capabilities.capabilityConversions = capsConversion;
+10
View File
@@ -488,6 +488,16 @@ var args = [
, nargs: 0
}],
[['--strict-caps'], {
defaultValue: false
, dest: 'enforceStrictCaps'
, action: 'storeTrue'
, required: false
, help: "Cause sessions to fail if desired caps are sent in that Appium " +
"does not recognize as valid for the selected device"
, nargs: 0
}],
[['--tmp'], {
defaultValue: null
, dest: 'tmpDir'
+57
View File
@@ -48,4 +48,61 @@ describe('capabilities', function () {
});
});
});
describe('#checkStrictValidity', function () {
var capsShouldPass = function (dt, caps) {
var c = new Capabilities(caps);
c.checkStrictValidity(dt);
};
var capsShouldFail = function (dt, caps) {
var err = null;
try {
capsShouldPass(dt, caps);
} catch (e) {
err = e;
}
should.exist(err);
};
var iosHappyCaps = {platformName: 'iOS', platformVersion: '7.1',
deviceName: 'iPhone Simulator', app: 'foo'};
var androidHappyCaps = {platformName: 'Android',
platformVersion: '4.2', deviceName: 'Android Emulator',
browserName: 'Chrome'};
it('should not care about selendroid', function () {
var c = new Capabilities({});
(typeof c.checkStrictValidity("selendroid")).should.equal("undefined");
});
it('should not allow unknown caps', function () {
capsShouldFail('ios', _.extend(_.clone(iosHappyCaps), {fooBar: 'lol'}));
capsShouldFail('android', _.extend(_.clone(androidHappyCaps), {fooBar: 'lol'}));
});
it('should enforce required caps', function () {
capsShouldFail('ios', {safariAllowPopups: 'lol'});
capsShouldFail('android', {useKeystore: 'lol'});
capsShouldPass('ios', iosHappyCaps);
capsShouldPass('android', androidHappyCaps);
});
it('should enforce browserName/app', function () {
var badIos = _.clone(iosHappyCaps);
delete badIos.app;
var badAnd = _.clone(androidHappyCaps);
delete badAnd.browserName;
capsShouldFail('ios', badIos);
capsShouldFail('android', badAnd);
});
it('should not allow caps unknown for device type', function () {
capsShouldFail('ios', _.extend(_.clone(iosHappyCaps), {avd: 'foo'}));
capsShouldFail('android', _.extend(_.clone(androidHappyCaps), {bundleId: 'foo'}));
});
});
});