Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
describe('unicode', function () {
let adb;
if (!process.env.TESTOBJECT_E2E_TESTS) {
adb = new ADB();
}
let initialIME;
let driver;
before(async function () {
// save the initial ime so we can make sure it is restored
if (adb) {
initialIME = await adb.defaultIME();
initialIME.should.not.eql('io.appium.settings/.UnicodeIME');
}
driver = await initSession(defaultUnicodeCaps);
});
after(async function () {
await deleteSession();
// make sure the IME has been restored
before(async function () {
// Don't test ADB on test object
if (process.env.TESTOBJECT_E2E_TESTS) {
this.skip();
}
// restarting doesn't work on Android 7+
adb = new ADB();
initialLocale = await getLocale(adb);
});
afterEach(async function () {
beforeEach(function () {
driver = new AndroidDriver();
driver.adb = new ADB();
driver.bootstrap = new helpers.bootstrap(driver.adb);
driver.settings = { update () {} };
driver.caps = {};
// create a fake bootstrap because we can't mock
// driver.bootstrap. in advance
let fakeBootstrap = {
start () {},
onUnexpectedShutdown: {catch () {}}
};
sandbox.stub(helpers, 'initDevice');
sandbox.stub(helpers, 'unlock');
sandbox.stub(helpers, 'bootstrap').returns(fakeBootstrap);
sandbox.stub(driver, 'initAUT');
sandbox.stub(driver, 'startAUT');
before(async function () {
if (process.env.TRAVIS) return this.skip(); // eslint-disable-line curly
let adb = new ADB();
if (!await adb.isAppInstalled('com.android.browser')) {
if (!await adb.isAppInstalled('com.android.chrome')) {
throw new Error('Neither default browser nor chrome available');
}
// `browser` is not available, so use `Chrome`
caps.browserName = 'Chrome';
urlId = 'com.android.chrome:id/url_bar';
}
driver = new AndroidDriver();
await driver.createSession(caps);
});
after(async function () {
describe('sharedPreferences', function () {
driver = new AndroidDriver();
let adb = new ADB();
driver.adb = adb;
let builder = new SharedPrefsBuilder();
describe('should skip setting sharedPreferences', withMocks({driver}, (mocks) => {
it('on undefined name', async function () {
driver.opts.sharedPreferences = {};
(await driver.setSharedPreferences()).should.be.false;
mocks.driver.verify();
});
}));
describe('should set sharedPreferences', withMocks({driver, adb, builder, fs}, (mocks) => {
it('on defined sharedPreferences object', async function () {
driver.opts.appPackage = 'io.appium.test';
driver.opts.sharedPreferences = {
name: 'com.appium.prefs',
prefs: [{type: 'string', name: 'mystr', value: 'appium rocks!'}]
};
describe('UiAutomator2 Driver Helpers', function () {
const adb = new ADB();
describe('ensureInternetPermissionForApp', withMocks({adb}, (mocks) => {
const app = '/path/to/app.apk';
afterEach(function () {
mocks.verify();
});
it('should do nothing if app has internet perms', async function () {
mocks.adb.expects('hasInternetPermissionFromManifest')
.once()
.withExactArgs(app)
.returns(true);
await helpers.ensureInternetPermissionForApp(adb, app);
});
it('should throw an error if app does not have internet perms', async function () {
mocks.adb.expects('hasInternetPermissionFromManifest')
.once()
describe('Webview Helpers', function () {
let adb = new ADB();
afterEach(function () {
sandbox.restore();
});
describe('procFromWebview', function () {
const webview = 'WEBVIEW_123';
const pkg = 'io.appium.android.apis';
it('should get package name when all fields are filled', async function () {
sandbox.stub(adb, 'shell').callsFake(function () {
return 'USER PID PPID VSZ RSS WCHAN ADDR S NAME\n' +
'root 1 0 9948 2344 SyS_epoll_wait 0 S init\n' +
'root 2 0 0 0 kthreadd 0 S [kthreadd]\n' +
'root 3 2 0 0 smpboot_thread_fn 0 S [ksoftirqd/0]\n' +
'root 5 2 0 0 worker_thread 0 S [kworker/0:0H]\n' +
beforeEach(function () {
driver = new AndroidDriver();
driver.adb = new ADB();
driver.bootstrap = new Bootstrap();
sandbox.stub(driver.bootstrap, 'sendAction');
});
afterEach(function () {
beforeEach(function () {
driver = new AndroidDriver();
driver.adb = new ADB();
driver.bootstrap = new helpers.bootstrap(driver.adb);
driver.settings = { update () { } };
driver.caps = {};
sandbox.stub(driver, 'setupNewChromedriver').returns({
on: _.noop,
proxyReq: _.noop,
});
sandbox.stub(driver, 'dismissChromeWelcome');
});
afterEach(function () {
beforeEach(async function () {
driver = new AndroidUiautomator2Driver();
driver.adb = new ADB();
sandbox.stub(driver, 'getNetworkConnection');
sandbox.stub(driver, 'wrapBootstrapDisconnect', async (fn) => {
await fn();
});
sandbox.stub(driver.adb, 'setAirplaneMode');
sandbox.stub(driver.adb, 'broadcastAirplaneMode');
sandbox.stub(driver, 'setWifiState');
sandbox.stub(driver.adb, 'setDataState');
});
afterEach(function () {