Skip to content

Commit

Permalink
add some negative tests for device extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
jlipps committed Mar 4, 2014
1 parent 0188729 commit 52a6253
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 51 deletions.
2 changes: 1 addition & 1 deletion lib/appium.js
Expand Up @@ -157,7 +157,7 @@ Appium.prototype.getDeviceTypeFromPackage = function (pkg) {
};

Appium.prototype.getDeviceTypeFromArgs = function (args) {
if (args.ipa) {
if (args.ipa && /\.ipa$/.test(args.ipa.toString().toLowerCase())) {
return DT_IOS;
} else if (args.safari) {
return DT_SAFARI;
Expand Down
130 changes: 80 additions & 50 deletions test/unit/configuration-specs.js
Expand Up @@ -10,56 +10,86 @@ describe('Appium', function () {
describe('#getDeviceType', function () {
// test is [args, caps, device]
var appium = getAppium({});
var happyTests = [
[{ipa: '/path/to/my.ipa'}, {}, 'ios']
, [{ipa: '/path/to/MY.IPA'}, {}, 'ios']
, [{forceIphone: true}, {}, 'ios']
, [{forceIpad: true}, {}, 'ios']
, [{safari: true, forceIpad: true}, {}, 'safari']
, [{ipa: '/path/to/my.ipa', safari: true}, {}, 'ios']
, [{safari: true}, {}, 'safari']
, [{safari: true}, {app: '/path/to/my.apk'}, 'safari']
, [{safari: false}, {app: 'safari'}, 'safari']
, [{}, {app: 'settings'}, 'ios']
, [{}, {app: 'Settings'}, 'ios']
, [{}, {app: 'chrome'}, 'chrome']
, [{}, {app: 'chromium'}, 'chrome']
, [{}, {app: 'chromium', device: 'android'}, 'chrome']
, [{}, {app: 'browser'}, 'chrome']
, [{}, {app: 'http://www.site.com/my.app.zip'}, 'ios']
, [{}, {app: 'http://www.site.com/MY.APP.ZIp'}, 'ios']
, [{}, {app: 'http://www.site.com/my.apk.zip'}, 'android']
, [{}, {app: 'http://www.site.com/my.apk'}, 'android']
, [{}, {app: 'HTTP://WWW.Site.COM/MY.APk'}, 'android']
, [{}, {app: '/path/to/my.app'}, 'ios']
, [{}, {app: '/path/to/my.apk'}, 'android']
, [{}, {app: '/path/to/my.apk'}, 'android']
, [{}, {app: '/path/to/my.apk.app'}, 'ios']
, [{}, {app: '/path/to/my.app.apk'}, 'android']
, [{}, {app: '/path/to/my.app', device: 'Android'}, 'android']
, [{app: '/path/to/my.app'}, {device: 'Android'}, 'android']
, [{}, {device: 'iPhone Simulator'}, 'ios']
, [{}, {device: 'iPhone'}, 'ios']
, [{}, {device: 'iphone'}, 'ios']
, [{}, {device: 'ipad'}, 'ios']
, [{}, {device: 'iPad Simulator'}, 'ios']
, [{}, {device: 'Selendroid'}, 'selendroid']
, [{}, {device: 'Android'}, 'android']
, [{}, {device: 'FirefoxOS'}, 'firefoxos']
, [{}, {device: 'firefox'}, 'firefoxos']
, [{}, {device: 'firefox', 'app-package': 'com.android.chrome'}, 'firefoxos']
, [{}, {'app-package': 'com.android.chrome'}, 'chrome']
, [{}, {'app-package': 'Com.Android.Chrome'}, 'chrome']
, [{}, {device: 'iphone', 'app-package': 'lol'}, 'ios']
, [{}, {'app-package': 'lol'}, 'android']
, [{androidPackage: 'com.foo'}, {}, 'android']
, [{androidPackage: 'com.android.browser'}, {}, 'chrome']
];
_.each(happyTests, function (test) {
var spec = 'should turn ' + JSON.stringify(test[0]) + ' args and ' +
JSON.stringify(test[1]) + ' caps into ' + test[2] + ' device';
it(spec, function () {
appium.getDeviceType(test[0], test[1]).should.equal(test[2]);
describe('positive cases', function () {
var happyTests = [
[{ipa: '/path/to/my.ipa'}, {}, 'ios']
, [{ipa: '/path/to/MY.IPA'}, {}, 'ios']
, [{forceIphone: true}, {}, 'ios']
, [{forceIpad: true}, {}, 'ios']
, [{safari: true, forceIpad: true}, {}, 'safari']
, [{ipa: '/path/to/my.ipa', safari: true}, {}, 'ios']
, [{safari: true}, {}, 'safari']
, [{safari: true}, {app: '/path/to/my.apk'}, 'safari']
, [{safari: false}, {app: 'safari'}, 'safari']
, [{}, {app: 'Safari'}, 'safari']
, [{}, {app: 'settings'}, 'ios']
, [{}, {app: 'Settings'}, 'ios']
, [{}, {app: 'chrome'}, 'chrome']
, [{}, {app: 'chromium'}, 'chrome']
, [{}, {app: 'chromium', device: 'android'}, 'chrome']
, [{}, {app: 'browser'}, 'chrome']
, [{}, {app: 'http://www.site.com/my.app.zip'}, 'ios']
, [{}, {app: 'http://www.site.com/MY.APP.ZIp'}, 'ios']
, [{}, {app: 'http://www.site.com/my.apk.zip'}, 'android']
, [{}, {app: 'http://www.site.com/my.apk'}, 'android']
, [{}, {app: 'HTTP://WWW.Site.COM/MY.APk'}, 'android']
, [{}, {app: '/path/to/my.app'}, 'ios']
, [{}, {app: '/path/to/my.apk'}, 'android']
, [{}, {app: '/path/to/my.apk'}, 'android']
, [{}, {app: '/path/to/my.apk.app'}, 'ios']
, [{}, {app: '/path/to/my.app.apk'}, 'android']
, [{}, {app: '/path/to/my.app', device: 'Android'}, 'android']
, [{app: '/path/to/my.app'}, {device: 'Android'}, 'android']
, [{}, {device: 'iPhone Simulator'}, 'ios']
, [{}, {device: 'iPhone Simulator', browserName: 'Safari'}, 'ios']
, [{}, {device: 'iPhone Simulator', browserName: 'safari'}, 'ios']
, [{}, {device: 'iPhone'}, 'ios']
, [{}, {device: 'iphone'}, 'ios']
, [{}, {device: 'ipad'}, 'ios']
, [{}, {device: 'iPad Simulator'}, 'ios']
, [{}, {device: 'Selendroid'}, 'selendroid']
, [{}, {device: 'Android'}, 'android']
, [{}, {device: 'FirefoxOS'}, 'firefoxos']
, [{}, {device: 'firefox'}, 'firefoxos']
, [{}, {device: 'firefox', 'app-package': 'com.android.chrome'}, 'firefoxos']
, [{}, {'app-package': 'com.android.chrome'}, 'chrome']
, [{}, {'app-package': 'Com.Android.Chrome'}, 'chrome']
, [{}, {device: 'iphone', 'app-package': 'lol'}, 'ios']
, [{}, {'app-package': 'lol'}, 'android']
, [{androidPackage: 'com.foo'}, {}, 'android']
, [{androidPackage: 'com.android.browser'}, {}, 'chrome']
];
_.each(happyTests, function (test) {
var spec = 'should turn ' + JSON.stringify(test[0]) + ' args and ' +
JSON.stringify(test[1]) + ' caps into ' + test[2] + ' device';
it(spec, function () {
appium.getDeviceType(test[0], test[1]).should.equal(test[2]);
});
});
});

describe('negative cases', function () {

var unhappyTests = [
[{}, {}]
, [{}, {device: 'rando'}]
, [{}, {app: '/path/to/my.exe'}]
, [{}, {browserName: 'Safari'}]
, [{ipa: '/path/to/my.exe'}, {}]
];
_.each(unhappyTests, function (test) {
var spec = 'should fail with args ' + JSON.stringify(test[0]) + ' and ' +
'caps ' + JSON.stringify(test[1]);
it(spec, function () {
var err;
try {
appium.getDeviceType(test[0], test[1]);
} catch (e) {
err = e;
}
should.exist(err);
err.message.should.contain("Could not determine your device");
});
});
});
});
Expand Down

0 comments on commit 52a6253

Please sign in to comment.