Merge pull request #3190 from moizjv/fix-3146

Adding check for seledroid for internet permission present in apk
This commit is contained in:
Jonathan Lipps
2014-07-24 16:19:23 -07:00
4 changed files with 50 additions and 3 deletions

View File

@@ -153,6 +153,7 @@ Selendroid.prototype.start = function (cb) {
async.series([
this.ensureServerExists.bind(this),
this.prepareDevice.bind(this),
this.checkInternetPermissionForApp.bind(this),
this.packageAndLaunchActivityFromManifest.bind(this),
checkModServerExists,
conditionalInsertManifest,
@@ -189,6 +190,23 @@ Selendroid.prototype.pushSelendroid = function (cb) {
this.adb.instrument(this.args.appPackage, this.args.appActivity, instrumentWith, cb);
};
Selendroid.prototype.checkInternetPermissionForApp = function (cb) {
var apk = this.args.app;
this.adb.hasInternetPermissionFromManifest(apk, function (err, hasInternetPermission) {
if (err) return cb(err);
if (hasInternetPermission) {
return cb();
}
else {
var errorMessg = "apk does not have INTERNET permissions. Selendroid needs internet " +
"permission to proceed, please check if you have <uses-permission " +
"android:name=\"android.**permission.INTERNET\"/> in your " +
"AndroidManifest.xml";
cb(new Error(errorMessg));
}
});
};
Selendroid.prototype.checkSelendroidCerts = function (cb) {
var alreadyReturned = false
, checks = 0;

View File

@@ -41,7 +41,7 @@
},
"dependencies": {
"adm-zip": "~0.4.4",
"appium-adb": "~1.3.1",
"appium-adb": "~1.3.2",
"appium-atoms": "~0.0.5",
"appium-instruments": "~1.3.0",
"appium-uiauto": "~1.6.0",
@@ -117,7 +117,7 @@
"socks": "~0.0.1",
"underscore-cli": "~0.2.17",
"unorm": "~1.3.3",
"wd": "~0.3.1",
"wd": "~0.3.4",
"wd-bridge": "~0.0.1",
"yiewd": "~0.5.0"
}

View File

@@ -0,0 +1,29 @@
"use strict";
require('../../helpers/setup-chai');
var env = require('../../helpers/env')
, initSession = require('../../helpers/session').initSession
, _ = require('underscore')
, desired = require('./desired');
describe('should not launch app without internet permission', function () {
this.timeout(env.MOCHA_INIT_TIMEOUT);
var session;
var name = this.title;
it('should not launch app', function (done) {
var newDesired = _.defaults({'app': 'sample-code/apps/ContactManager/ContactManager.apk'}, desired);
afterEach(function (done) {
session
.tearDown(this.currentTest.state === 'failed')
.nodeify(done);
});
session = initSession(newDesired, {'no-retry': true, 'expect-error': true});
session
.setUp(name).catch(function (err) {
err.data.should.include("INTERNET");
throw err;
}).should.be.rejectedWith(/The environment you requested was unavailable./)
.nodeify(done);
});
});