appium-adb-test
Version:
Android Debug Bridge interface
1,254 lines (1,082 loc) • 125 kB
JavaScript
'use strict';
var _regeneratorRuntime = require('babel-runtime/regenerator')['default'];
var _interopRequireDefault = require('babel-runtime/helpers/interop-require-default')['default'];
var _interopRequireWildcard = require('babel-runtime/helpers/interop-require-wildcard')['default'];
var _this = this;
var _chai = require('chai');
var _chai2 = _interopRequireDefault(_chai);
var _chaiAsPromised = require('chai-as-promised');
var _chaiAsPromised2 = _interopRequireDefault(_chaiAsPromised);
var _ = require('../..');
var _2 = _interopRequireDefault(_);
var _net = require('net');
var _net2 = _interopRequireDefault(_net);
var _events = require('events');
var _events2 = _interopRequireDefault(_events);
var _libLogcatJs = require('../../lib/logcat.js');
var _libLogcatJs2 = _interopRequireDefault(_libLogcatJs);
var _libLoggerJs = require('../../lib/logger.js');
var _libLoggerJs2 = _interopRequireDefault(_libLoggerJs);
var _teen_process = require('teen_process');
var teen_process = _interopRequireWildcard(_teen_process);
var _appiumTestSupport = require('appium-test-support');
_chai2['default'].use(_chaiAsPromised2['default']);
var should = _chai2['default'].should();
var apiLevel = '21',
platformVersion = '4.4.4',
language = 'en',
country = 'US',
locale = 'en-US',
IME = 'com.android.inputmethod.latin/.LatinIME',
imeList = 'com.android.inputmethod.latin/.LatinIME:\n mId=com.android.inputmethod.latin/.LatinIME mSettingsActivityName=com.android\n mIsDefaultResId=0x7f070000\n Service:\n priority=0 preferredOrder=0 match=0x108000 specificIndex=-1 isDefault=false\n ServiceInfo:\n name=com.android.inputmethod.latin.LatinIME\n packageName=com.android.inputmethod.latin\n labelRes=0x7f0a0037 nonLocalizedLabel=null icon=0x0 banner=0x0\n enabled=true exported=true processName=com.android.inputmethod.latin\n permission=android.permission.BIND_INPUT_METHOD\n flags=0x0',
psOutput = 'USER PID PPID VSIZE RSS WCHAN PC NAME\nu0_a101 5078 3129 487404 37044 ffffffff b76ce565 S com.example.android.contactmanager',
contactManagerPackage = 'com.example.android.contactmanager';
describe('adb commands', function () {
var adb = new _2['default']();
var logcat = new _libLogcatJs2['default']({
adb: adb,
debug: false,
debugTrace: false
});
describe('shell', function () {
describe('getApiLevel', (0, _appiumTestSupport.withMocks)({ adb: adb }, function (mocks) {
it('should call shell with correct args', function callee$3$0() {
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
mocks.adb.expects("shell").once().withExactArgs(['getprop', 'ro.build.version.sdk']).returns(apiLevel);
context$4$0.next = 3;
return _regeneratorRuntime.awrap(adb.getApiLevel());
case 3:
context$4$0.t0 = apiLevel;
context$4$0.sent.should.equal(context$4$0.t0);
mocks.adb.verify();
case 6:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
}));
describe('getPlatformVersion', (0, _appiumTestSupport.withMocks)({ adb: adb }, function (mocks) {
it('should call shell with correct args', function callee$3$0() {
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
mocks.adb.expects("shell").once().withExactArgs(['getprop', 'ro.build.version.release']).returns(platformVersion);
context$4$0.next = 3;
return _regeneratorRuntime.awrap(adb.getPlatformVersion());
case 3:
context$4$0.t0 = platformVersion;
context$4$0.sent.should.equal(context$4$0.t0);
mocks.adb.verify();
case 6:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
}));
describe('getDeviceSysLanguage', (0, _appiumTestSupport.withMocks)({ adb: adb }, function (mocks) {
it('should call shell with correct args', function callee$3$0() {
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
mocks.adb.expects("shell").once().withExactArgs(['getprop', 'persist.sys.language']).returns(language);
context$4$0.next = 3;
return _regeneratorRuntime.awrap(adb.getDeviceSysLanguage());
case 3:
context$4$0.t0 = language;
context$4$0.sent.should.equal(context$4$0.t0);
mocks.adb.verify();
case 6:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
}));
describe('setDeviceSysLanguage', (0, _appiumTestSupport.withMocks)({ adb: adb }, function (mocks) {
it('should call shell with correct args', function callee$3$0() {
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
mocks.adb.expects("shell").once().withExactArgs(['setprop', 'persist.sys.language', language]).returns("");
context$4$0.next = 3;
return _regeneratorRuntime.awrap(adb.setDeviceSysLanguage(language));
case 3:
mocks.adb.verify();
case 4:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
}));
describe('getDeviceSysCountry', (0, _appiumTestSupport.withMocks)({ adb: adb }, function (mocks) {
it('should call shell with correct args', function callee$3$0() {
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
mocks.adb.expects("shell").once().withExactArgs(['getprop', 'persist.sys.country']).returns(country);
context$4$0.next = 3;
return _regeneratorRuntime.awrap(adb.getDeviceSysCountry());
case 3:
context$4$0.t0 = country;
context$4$0.sent.should.equal(context$4$0.t0);
mocks.adb.verify();
case 6:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
}));
describe('setDeviceSysCountry', (0, _appiumTestSupport.withMocks)({ adb: adb }, function (mocks) {
it('should call shell with correct args', function callee$3$0() {
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
mocks.adb.expects("shell").once().withExactArgs(['setprop', 'persist.sys.country', country]).returns("");
context$4$0.next = 3;
return _regeneratorRuntime.awrap(adb.setDeviceSysCountry(country));
case 3:
mocks.adb.verify();
case 4:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
}));
describe('getDeviceSysLocale', (0, _appiumTestSupport.withMocks)({ adb: adb }, function (mocks) {
it('should call shell with correct args', function callee$3$0() {
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
mocks.adb.expects("shell").once().withExactArgs(['getprop', 'persist.sys.locale']).returns(locale);
context$4$0.next = 3;
return _regeneratorRuntime.awrap(adb.getDeviceSysLocale());
case 3:
context$4$0.t0 = locale;
context$4$0.sent.should.equal(context$4$0.t0);
mocks.adb.verify();
case 6:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
}));
describe('setDeviceSysLocale', (0, _appiumTestSupport.withMocks)({ adb: adb }, function (mocks) {
it('should call shell with correct args', function callee$3$0() {
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
mocks.adb.expects("shell").once().withExactArgs(['setprop', 'persist.sys.locale', locale]).returns("");
context$4$0.next = 3;
return _regeneratorRuntime.awrap(adb.setDeviceSysLocale(locale));
case 3:
mocks.adb.verify();
case 4:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
}));
describe('getDeviceProductLanguage', (0, _appiumTestSupport.withMocks)({ adb: adb }, function (mocks) {
it('should call shell with correct args', function callee$3$0() {
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
mocks.adb.expects("shell").once().withExactArgs(['getprop', 'ro.product.locale.language']).returns(language);
context$4$0.next = 3;
return _regeneratorRuntime.awrap(adb.getDeviceProductLanguage());
case 3:
context$4$0.t0 = language;
context$4$0.sent.should.equal(context$4$0.t0);
mocks.adb.verify();
case 6:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
}));
describe('getDeviceProductCountry', (0, _appiumTestSupport.withMocks)({ adb: adb }, function (mocks) {
it('should call shell with correct args', function callee$3$0() {
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
mocks.adb.expects("shell").once().withExactArgs(['getprop', 'ro.product.locale.region']).returns(country);
context$4$0.next = 3;
return _regeneratorRuntime.awrap(adb.getDeviceProductCountry());
case 3:
context$4$0.t0 = country;
context$4$0.sent.should.equal(context$4$0.t0);
mocks.adb.verify();
case 6:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
}));
describe('getDeviceProductLocale', (0, _appiumTestSupport.withMocks)({ adb: adb }, function (mocks) {
it('should call shell with correct args', function callee$3$0() {
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
mocks.adb.expects("shell").once().withExactArgs(['getprop', 'ro.product.locale']).returns(locale);
context$4$0.next = 3;
return _regeneratorRuntime.awrap(adb.getDeviceProductLocale());
case 3:
context$4$0.t0 = locale;
context$4$0.sent.should.equal(context$4$0.t0);
mocks.adb.verify();
case 6:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
}));
describe('availableIMEs', (0, _appiumTestSupport.withMocks)({ adb: adb }, function (mocks) {
it('should call shell with correct args', function callee$3$0() {
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
mocks.adb.expects("shell").once().withExactArgs(['ime', 'list', '-a']).returns(imeList);
context$4$0.next = 3;
return _regeneratorRuntime.awrap(adb.availableIMEs());
case 3:
context$4$0.sent.should.have.length.above(0);
mocks.adb.verify();
case 5:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
}));
describe('enabledIMEs', (0, _appiumTestSupport.withMocks)({ adb: adb }, function (mocks) {
it('should call shell with correct args', function callee$3$0() {
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
mocks.adb.expects("shell").once().withExactArgs(['ime', 'list']).returns(imeList);
context$4$0.next = 3;
return _regeneratorRuntime.awrap(adb.enabledIMEs());
case 3:
context$4$0.sent.should.have.length.above(0);
mocks.adb.verify();
case 5:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
}));
describe('defaultIME', (0, _appiumTestSupport.withMocks)({ adb: adb }, function (mocks) {
var defaultIME = 'com.android.inputmethod.latin/.LatinIME';
it('should call shell with correct args', function callee$3$0() {
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
mocks.adb.expects("shell").once().withExactArgs(['settings', 'get', 'secure', 'default_input_method']).returns(defaultIME);
context$4$0.next = 3;
return _regeneratorRuntime.awrap(adb.defaultIME());
case 3:
context$4$0.t0 = defaultIME;
context$4$0.sent.should.equal(context$4$0.t0);
mocks.adb.verify();
case 6:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
}));
describe('disableIME', (0, _appiumTestSupport.withMocks)({ adb: adb }, function (mocks) {
it('should call shell with correct args', function callee$3$0() {
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
mocks.adb.expects("shell").once().withExactArgs(['ime', 'disable', IME]).returns("");
context$4$0.next = 3;
return _regeneratorRuntime.awrap(adb.disableIME(IME));
case 3:
mocks.adb.verify();
case 4:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
}));
describe('enableIME', (0, _appiumTestSupport.withMocks)({ adb: adb }, function (mocks) {
it('should call shell with correct args', function callee$3$0() {
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
mocks.adb.expects("shell").once().withExactArgs(['ime', 'enable', IME]).returns("");
context$4$0.next = 3;
return _regeneratorRuntime.awrap(adb.enableIME(IME));
case 3:
mocks.adb.verify();
case 4:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
}));
describe('keyevent', (0, _appiumTestSupport.withMocks)({ adb: adb }, function (mocks) {
it('should call shell with correct args', function callee$3$0() {
var keycode, code;
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
keycode = '29';
code = parseInt(keycode, 10);
mocks.adb.expects("shell").once().withExactArgs(['input', 'keyevent', code]).returns("");
context$4$0.next = 5;
return _regeneratorRuntime.awrap(adb.keyevent(keycode));
case 5:
mocks.adb.verify();
case 6:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
}));
describe('inputText', (0, _appiumTestSupport.withMocks)({ adb: adb }, function (mocks) {
it('should call shell with correct args', function callee$3$0() {
var text, expectedText;
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
text = 'some text';
expectedText = 'some%stext';
mocks.adb.expects("shell").once().withExactArgs(['input', 'text', expectedText]).returns("");
context$4$0.next = 5;
return _regeneratorRuntime.awrap(adb.inputText(text));
case 5:
mocks.adb.verify();
case 6:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
}));
describe('clearTextField', (0, _appiumTestSupport.withMocks)({ adb: adb }, function (mocks) {
it('should call shell with correct args', function callee$3$0() {
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
mocks.adb.expects("shell").once().withExactArgs(['input', 'keyevent', '67', '112', '67', '112', '67', '112', '67', '112']).returns("");
context$4$0.next = 3;
return _regeneratorRuntime.awrap(adb.clearTextField(4));
case 3:
mocks.adb.verify();
case 4:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
}));
describe('lock', (0, _appiumTestSupport.withMocks)({ adb: adb, log: _libLoggerJs2['default'] }, function (mocks) {
it('should call isScreenLocked, keyevent and errorAndThrow', function callee$3$0() {
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
mocks.adb.expects("isScreenLocked").atLeast(2).returns(false);
mocks.adb.expects("keyevent").once().withExactArgs(26).returns("");
mocks.log.expects("errorAndThrow").once().returns("");
context$4$0.next = 5;
return _regeneratorRuntime.awrap(adb.lock());
case 5:
mocks.adb.verify();
case 6:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
}));
describe('back', (0, _appiumTestSupport.withMocks)({ adb: adb }, function (mocks) {
it('should call keyevent with correct args', function callee$3$0() {
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
mocks.adb.expects("keyevent").once().withExactArgs(4).returns("");
context$4$0.next = 3;
return _regeneratorRuntime.awrap(adb.back());
case 3:
mocks.adb.verify();
case 4:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
}));
describe('goToHome', (0, _appiumTestSupport.withMocks)({ adb: adb }, function (mocks) {
it('should call keyevent with correct args', function callee$3$0() {
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
mocks.adb.expects("keyevent").once().withExactArgs(3).returns("");
context$4$0.next = 3;
return _regeneratorRuntime.awrap(adb.goToHome());
case 3:
mocks.adb.verify();
case 4:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
}));
describe.skip('isScreenLocked', (0, _appiumTestSupport.withMocks)({ adb: adb }, function (mocks) {
it('should call keyevent with correct args', function callee$3$0() {
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
mocks.adb.expects("keyevent").once().withExactArgs(3).returns("");
context$4$0.next = 3;
return _regeneratorRuntime.awrap(adb.goToHome());
case 3:
mocks.adb.verify();
case 4:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
}));
describe('isSoftKeyboardPresent', (0, _appiumTestSupport.withMocks)({ adb: adb }, function (mocks) {
it('should call shell with correct args and should return false', function callee$3$0() {
var _ref, isKeyboardShown, canCloseKeyboard;
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
mocks.adb.expects("shell").once().withExactArgs(['dumpsys', 'input_method']).returns("mInputShown=false");
context$4$0.next = 3;
return _regeneratorRuntime.awrap(adb.isSoftKeyboardPresent());
case 3:
_ref = context$4$0.sent;
isKeyboardShown = _ref.isKeyboardShown;
canCloseKeyboard = _ref.canCloseKeyboard;
canCloseKeyboard.should.be['false'];
isKeyboardShown.should.be['false'];
mocks.adb.verify();
case 9:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
it('should call shell with correct args and should return true', function callee$3$0() {
var _ref2, isKeyboardShown, canCloseKeyboard;
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
mocks.adb.expects("shell").once().withExactArgs(['dumpsys', 'input_method']).returns("mInputShown=true mIsInputViewShown=true");
context$4$0.next = 3;
return _regeneratorRuntime.awrap(adb.isSoftKeyboardPresent());
case 3:
_ref2 = context$4$0.sent;
isKeyboardShown = _ref2.isKeyboardShown;
canCloseKeyboard = _ref2.canCloseKeyboard;
isKeyboardShown.should.be['true'];
canCloseKeyboard.should.be['true'];
mocks.adb.verify();
case 9:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
}));
describe('isAirplaneModeOn', (0, _appiumTestSupport.withMocks)({ adb: adb }, function (mocks) {
it('should call shell with correct args and should be true', function callee$3$0() {
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
mocks.adb.expects("shell").once().withExactArgs(['settings', 'get', 'global', 'airplane_mode_on']).returns("1");
context$4$0.next = 3;
return _regeneratorRuntime.awrap(adb.isAirplaneModeOn());
case 3:
context$4$0.sent.should.be['true'];
mocks.adb.verify();
case 5:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
it('should call shell with correct args and should be false', function callee$3$0() {
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
mocks.adb.expects("shell").once().withExactArgs(['settings', 'get', 'global', 'airplane_mode_on']).returns("0");
context$4$0.next = 3;
return _regeneratorRuntime.awrap(adb.isAirplaneModeOn());
case 3:
context$4$0.sent.should.be['false'];
mocks.adb.verify();
case 5:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
}));
describe('setAirplaneMode', (0, _appiumTestSupport.withMocks)({ adb: adb }, function (mocks) {
it('should call shell with correct args', function callee$3$0() {
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
mocks.adb.expects("shell").once().withExactArgs(['settings', 'put', 'global', 'airplane_mode_on', 1]).returns("");
context$4$0.next = 3;
return _regeneratorRuntime.awrap(adb.setAirplaneMode(1));
case 3:
mocks.adb.verify();
case 4:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
}));
describe('broadcastAirplaneMode', (0, _appiumTestSupport.withMocks)({ adb: adb }, function (mocks) {
it('should call shell with correct args', function callee$3$0() {
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
mocks.adb.expects("shell").once().withExactArgs(['am', 'broadcast', '-a', 'android.intent.action.AIRPLANE_MODE', '--ez', 'state', 'true']).returns("");
context$4$0.next = 3;
return _regeneratorRuntime.awrap(adb.broadcastAirplaneMode(true));
case 3:
mocks.adb.verify();
case 4:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
}));
describe('isWifiOn', (0, _appiumTestSupport.withMocks)({ adb: adb }, function (mocks) {
it('should call shell with correct args and should be true', function callee$3$0() {
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
mocks.adb.expects("shell").once().withExactArgs(['settings', 'get', 'global', 'wifi_on']).returns("1");
context$4$0.next = 3;
return _regeneratorRuntime.awrap(adb.isWifiOn());
case 3:
context$4$0.sent.should.be['true'];
mocks.adb.verify();
case 5:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
it('should call shell with correct args and should be false', function callee$3$0() {
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
mocks.adb.expects("shell").once().withExactArgs(['settings', 'get', 'global', 'wifi_on']).returns("0");
context$4$0.next = 3;
return _regeneratorRuntime.awrap(adb.isWifiOn());
case 3:
context$4$0.sent.should.be['false'];
mocks.adb.verify();
case 5:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
}));
describe('setWifiState', (0, _appiumTestSupport.withMocks)({ adb: adb }, function (mocks) {
it('should call shell with correct args', function callee$3$0() {
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
mocks.adb.expects("shell").once().withExactArgs(['settings', 'put', 'global', 'wifi_on', 1]).returns("");
context$4$0.next = 3;
return _regeneratorRuntime.awrap(adb.setWifiState(true));
case 3:
mocks.adb.verify();
case 4:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
}));
describe('isDataOn', (0, _appiumTestSupport.withMocks)({ adb: adb }, function (mocks) {
it('should call shell with correct args and should be true', function callee$3$0() {
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
mocks.adb.expects("shell").once().withExactArgs(['settings', 'get', 'global', 'mobile_data']).returns("1");
context$4$0.next = 3;
return _regeneratorRuntime.awrap(adb.isDataOn());
case 3:
context$4$0.sent.should.be['true'];
mocks.adb.verify();
case 5:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
it('should call shell with correct args and should be false', function callee$3$0() {
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
mocks.adb.expects("shell").once().withExactArgs(['settings', 'get', 'global', 'mobile_data']).returns("0");
context$4$0.next = 3;
return _regeneratorRuntime.awrap(adb.isDataOn());
case 3:
context$4$0.sent.should.be['false'];
mocks.adb.verify();
case 5:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
}));
describe('setDataState', (0, _appiumTestSupport.withMocks)({ adb: adb }, function (mocks) {
it('should call shell with correct args', function callee$3$0() {
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
mocks.adb.expects("shell").once().withExactArgs(["settings", "put", "global", "mobile_data", 1]).returns("");
context$4$0.next = 3;
return _regeneratorRuntime.awrap(adb.setDataState(true));
case 3:
mocks.adb.verify();
case 4:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
}));
describe('setWifiAndData', (0, _appiumTestSupport.withMocks)({ adb: adb }, function (mocks) {
it('should call shell with correct args when turning only wifi on', function callee$3$0() {
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
mocks.adb.expects("shell").once().withExactArgs(['am', 'start', '-n', 'io.appium.settings/.Settings', '-e', 'wifi', 'on']).returns("");
context$4$0.next = 3;
return _regeneratorRuntime.awrap(adb.setWifiAndData({ wifi: true }));
case 3:
mocks.adb.verify();
case 4:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
it('should call shell with correct args when turning only wifi off', function callee$3$0() {
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
mocks.adb.expects("shell").once().withExactArgs(['am', 'start', '-n', 'io.appium.settings/.Settings', '-e', 'wifi', 'off']).returns("");
context$4$0.next = 3;
return _regeneratorRuntime.awrap(adb.setWifiAndData({ wifi: false }));
case 3:
mocks.adb.verify();
case 4:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
it('should call shell with correct args when turning only data on', function callee$3$0() {
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
mocks.adb.expects("shell").once().withExactArgs(['am', 'start', '-n', 'io.appium.settings/.Settings', '-e', 'data', 'on']).returns("");
context$4$0.next = 3;
return _regeneratorRuntime.awrap(adb.setWifiAndData({ data: true }));
case 3:
mocks.adb.verify();
case 4:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
it('should call shell with correct args when turning only data off', function callee$3$0() {
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
mocks.adb.expects("shell").once().withExactArgs(['am', 'start', '-n', 'io.appium.settings/.Settings', '-e', 'data', 'off']).returns("");
context$4$0.next = 3;
return _regeneratorRuntime.awrap(adb.setWifiAndData({ data: false }));
case 3:
mocks.adb.verify();
case 4:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
it('should call shell with correct args when turning both wifi and data on', function callee$3$0() {
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
mocks.adb.expects("shell").once().withExactArgs(['am', 'start', '-n', 'io.appium.settings/.Settings', '-e', 'wifi', 'on', '-e', 'data', 'on']).returns("");
context$4$0.next = 3;
return _regeneratorRuntime.awrap(adb.setWifiAndData({ wifi: true, data: true }));
case 3:
mocks.adb.verify();
case 4:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
it('should call shell with correct args when turning both wifi and data off', function callee$3$0() {
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
mocks.adb.expects("shell").once().withExactArgs(['am', 'start', '-n', 'io.appium.settings/.Settings', '-e', 'wifi', 'off', '-e', 'data', 'off']).returns("");
context$4$0.next = 3;
return _regeneratorRuntime.awrap(adb.setWifiAndData({ wifi: false, data: false }));
case 3:
mocks.adb.verify();
case 4:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
}));
describe('processExists', (0, _appiumTestSupport.withMocks)({ adb: adb }, function (mocks) {
it('should call shell with correct args and should find process', function callee$3$0() {
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
mocks.adb.expects("shell").once().withExactArgs("ps").returns(psOutput);
context$4$0.next = 3;
return _regeneratorRuntime.awrap(adb.processExists(contactManagerPackage));
case 3:
context$4$0.sent.should.be['true'];
mocks.adb.verify();
case 5:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
it('should call shell with correct args and should not find process', function callee$3$0() {
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
mocks.adb.expects("shell").once().withExactArgs("ps").returns("foo");
context$4$0.next = 3;
return _regeneratorRuntime.awrap(adb.processExists(contactManagerPackage));
case 3:
context$4$0.sent.should.be['false'];
mocks.adb.verify();
case 5:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
}));
describe('forwardPort', (0, _appiumTestSupport.withMocks)({ adb: adb }, function (mocks) {
var sysPort = 12345,
devicePort = 54321;
it('forwardPort should call shell with correct args', function callee$3$0() {
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
mocks.adb.expects("adbExec").once().withExactArgs(['forward', 'tcp:' + sysPort, 'tcp:' + devicePort]).returns("");
context$4$0.next = 3;
return _regeneratorRuntime.awrap(adb.forwardPort(sysPort, devicePort));
case 3:
mocks.adb.verify();
case 4:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
it('forwardAbstractPort should call shell with correct args', function callee$3$0() {
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
mocks.adb.expects("adbExec").once().withExactArgs(['forward', 'tcp:' + sysPort, 'localabstract:' + devicePort]).returns("");
context$4$0.next = 3;
return _regeneratorRuntime.awrap(adb.forwardAbstractPort(sysPort, devicePort));
case 3:
mocks.adb.verify();
case 4:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
it('removePortForward should call shell with correct args', function callee$3$0() {
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
mocks.adb.expects("adbExec").once().withExactArgs(['forward', '--remove', 'tcp:' + sysPort]).returns("");
context$4$0.next = 3;
return _regeneratorRuntime.awrap(adb.removePortForward(sysPort, devicePort));
case 3:
mocks.adb.verify();
case 4:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
}));
describe('ping', (0, _appiumTestSupport.withMocks)({ adb: adb }, function (mocks) {
it('should call shell with correct args and should return true', function callee$3$0() {
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
mocks.adb.expects("shell").once().withExactArgs(["echo", "ping"]).returns("ping");
context$4$0.next = 3;
return _regeneratorRuntime.awrap(adb.ping());
case 3:
context$4$0.sent.should.be['true'];
mocks.adb.verify();
case 5:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
}));
describe('restart', (0, _appiumTestSupport.withMocks)({ adb: adb }, function (mocks) {
it('should call adb in correct order', function callee$3$0() {
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
mocks.adb.expects("stopLogcat").once().returns("");
mocks.adb.expects("restartAdb").once().returns("");
mocks.adb.expects("waitForDevice").once().returns("");
mocks.adb.expects("startLogcat").once().returns("");
context$4$0.next = 6;
return _regeneratorRuntime.awrap(adb.restart());
case 6:
mocks.adb.verify();
case 7:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
}));
describe('stopLogcat', (0, _appiumTestSupport.withMocks)({ logcat: logcat }, function (mocks) {
it('should call stopCapture', function callee$3$0() {
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
adb.logcat = logcat;
mocks.logcat.expects("stopCapture").once().returns("");
context$4$0.next = 4;
return _regeneratorRuntime.awrap(adb.stopLogcat());
case 4:
mocks.logcat.verify();
case 5:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
}));
describe('getLogcatLogs', (0, _appiumTestSupport.withMocks)({ logcat: logcat }, function (mocks) {
it('should call getLogs', function callee$3$0() {
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
adb.logcat = logcat;
mocks.logcat.expects("getLogs").once().returns("");
context$4$0.next = 4;
return _regeneratorRuntime.awrap(adb.getLogcatLogs());
case 4:
mocks.logcat.verify();
case 5:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
}));
describe('getPIDsByName', (0, _appiumTestSupport.withMocks)({ adb: adb }, function (mocks) {
it('should call shell and parse pids correctly', function callee$3$0() {
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
mocks.adb.expects("shell").once().withExactArgs(['ps']).returns(psOutput);
context$4$0.next = 3;
return _regeneratorRuntime.awrap(adb.getPIDsByName(contactManagerPackage));
case 3:
context$4$0.sent[0].should.equal(5078);
mocks.adb.verify();
case 5:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
}));
describe('killProcessesByName', (0, _appiumTestSupport.withMocks)({ adb: adb }, function (mocks) {
it('should call getPIDsByName and kill process correctly', function callee$3$0() {
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
mocks.adb.expects("getPIDsByName").once().withExactArgs(contactManagerPackage).returns([5078]);
mocks.adb.expects("killProcessByPID").once().withExactArgs(5078).returns("");
context$4$0.next = 4;
return _regeneratorRuntime.awrap(adb.killProcessesByName(contactManagerPackage));
case 4:
mocks.adb.verify();
case 5:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
}));
describe('killProcessByPID', (0, _appiumTestSupport.withMocks)({ adb: adb }, function (mocks) {
it('should call kill process correctly', function callee$3$0() {
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
mocks.adb.expects("shell").once().withExactArgs(['kill', 5078]).returns();
context$4$0.next = 3;
return _regeneratorRuntime.awrap(adb.killProcessByPID(5078));
case 3:
mocks.adb.verify();
case 4:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
}));
describe('broadcastProcessEnd', (0, _appiumTestSupport.withMocks)({ adb: adb }, function (mocks) {
it('should broadcast process end', function callee$3$0() {
var intent, processName;
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
intent = 'intent', processName = 'processName';
mocks.adb.expects("shell").once().withExactArgs(['am', 'broadcast', '-a', intent]).returns("");
mocks.adb.expects("processExists").once().withExactArgs(processName).returns(false);
context$4$0.next = 5;
return _regeneratorRuntime.awrap(adb.broadcastProcessEnd(intent, processName));
case 5:
mocks.adb.verify();
case 6:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
}));
describe('broadcast', (0, _appiumTestSupport.withMocks)({ adb: adb }, function (mocks) {
it('should broadcast intent', function callee$3$0() {
var intent;
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
intent = 'intent';
mocks.adb.expects("shell").once().withExactArgs(['am', 'broadcast', '-a', intent]).returns("");
context$4$0.next = 4;
return _regeneratorRuntime.awrap(adb.broadcast(intent));
case 4:
mocks.adb.verify();
case 5:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
}));
describe('instrument', (0, _appiumTestSupport.withMocks)({ adb: adb }, function (mocks) {
it('should call shell with correct arguments', function callee$3$0() {
var intent;
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
intent = 'intent';
mocks.adb.expects("shell").once().withExactArgs(['am', 'broadcast', '-a', intent]).returns("");
context$4$0.next = 4;
return _regeneratorRuntime.awrap(adb.broadcast(intent));
case 4:
mocks.adb.verify();
case 5:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
}));
describe('androidCoverage', (0, _appiumTestSupport.withMocks)({ adb: adb, teen_process: teen_process }, function (mocks) {
it('should call shell with correct arguments', function callee$3$0() {
var conn, instrumentClass, waitPkg, waitActivity, args;
return _regeneratorRuntime.async(function callee$3$0$(context$4$0) {
while (1) switch (context$4$0.prev = context$4$0.next) {
case 0:
adb.executable.defaultArgs = [];
adb.executable.path = "dummy_adb_path";
conn = new _events2['default'].EventEmitter();
conn.start = function () {}; // do nothing
instrumentClass = 'instrumentClass', waitPkg = 'waitPkg', waitActivity = 'waitActivity';
args = adb.executable.defaultArgs.concat(['shell', 'am', 'instrument', '-e', 'coverage', 'true', '-w']).concat([instrumentClass]);
mocks.teen_process.expects("SubProcess").once().withExactArgs('dummy_adb_path', args).returns(conn);
mocks.adb.expects("waitForActivity").once().withExactArgs(waitPkg, waitActivity).returns("");
context$4$0.next = 10;
return _regeneratorRuntime.awrap(adb.androidCoverage(instrumentClass, waitPkg, waitActivity));
case 10:
mocks.teen_process.verify();
mocks.adb.verify();
case 12:
case 'end':
return context$4$0.stop();
}
}, null, _this);
});
}));
});
describe('sendTelnetCommand', (0, _appiumTestSupport.withMocks)({ adb: adb, net: _net2['default'] }, function (mocks) {
it('should call shell with correct args', function callee$2$0() {
var port, conn, commands, p;
return _regeneratorRuntime.async(function callee$2$0$(context$3$0) {
while (1) switch (context$3$0.prev = context$3$0.next) {
case 0:
port = 54321;
conn = new _events2['default'].EventEmitter();
commands = [];
conn.write = function (command) {
commands.push(command);
};
mocks.adb.expects("getEmulatorPort").once().withExactArgs().returns(port);
mocks.net.expects("createConnection").once().withExactArgs(port, 'localhost').returns(conn);
p = adb.sendTelnetCommand('avd name');
setTimeout(function () {
conn.emit('connect');
conn.emit('data', 'OK');
conn.emit('data', 'OK');
conn.emit('close');