mirror of
https://github.com/appium/appium.git
synced 2026-10-28 12:21:20 +08:00
Add unit test for starting app
This commit is contained in:
@@ -80,5 +80,73 @@ describe('adb', function () {
|
||||
).nodeify(done);
|
||||
});
|
||||
});
|
||||
|
||||
describe('startApp', function () {
|
||||
var getStartAppMock = function (apiLevel, stdout, startApp) {
|
||||
return {
|
||||
getApiLevel: function (cb) { cb(null, apiLevel); },
|
||||
shell: function (cmd, cb) { cb(null, stdout); },
|
||||
startApp: startApp
|
||||
};
|
||||
};
|
||||
|
||||
it('should fail when there is no permission', function (done) {
|
||||
var stdout =
|
||||
'Stopping: com.android.contacts\n' +
|
||||
'Starting: Intent { cmp=com.android.contacts/.ContactsListActivity }\n' +
|
||||
'java.lang.SecurityException: Permission Denial: ' +
|
||||
'starting Intent { flg=0x10000000 cmp=com.android.contacts/.ContactsListActivity } ' +
|
||||
'from null (pid=13312, uid=2000) not exported from uid 10013\n' +
|
||||
' at android.os.Parcel.readException(Parcel.java:1431)\n' +
|
||||
' ...';
|
||||
|
||||
ADB.prototype.startApp.call(getStartAppMock(19, stdout, null), {pkg: 'com.android.contacts'}, function (err) {
|
||||
err.should.not.be.null;
|
||||
err.message.should.include('Permission to start activity denied');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail when no activity is specified', function (done) {
|
||||
var stdout =
|
||||
'Error: Activity class ... does not exist';
|
||||
|
||||
ADB.prototype.startApp.call(getStartAppMock(19, stdout, null), {pkg: 'com.android.contacts'}, function (err) {
|
||||
err.should.not.be.null;
|
||||
err.message.should.include('Parameter \'appActivity\' is required for launching application');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail when activity does not exist', function (done) {
|
||||
var stdout =
|
||||
'Error: Activity class ... does not exist';
|
||||
|
||||
ADB.prototype.startApp.call(getStartAppMock(19, stdout, null), {
|
||||
pkg: 'com.android.contacts',
|
||||
activity: '.ContactsListActivity'
|
||||
}, function (err) {
|
||||
err.should.not.be.null;
|
||||
err.message.should.include('Activity used to start app doesn\'t exist or cannot be ' +
|
||||
'launched! Make sure it exists and is a launchable activity');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should retry non-existent activity preceded by a `.`', function (done) {
|
||||
var stdout =
|
||||
'Error: Activity class ... does not exist';
|
||||
|
||||
ADB.prototype.startApp.call(getStartAppMock(19, stdout, function (startAppOptions, cb) {
|
||||
startAppOptions.activity.should.equal('.ContactsListActivity');
|
||||
cb();
|
||||
}), {
|
||||
pkg: 'com.android.contacts',
|
||||
activity: 'ContactsListActivity'
|
||||
}, function () {
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user