How to use initAUT method in Appium Android Driver

Best JavaScript code snippet using appium-android-driver

Run Appium Android Driver automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

driver-specs.js

Source: driver-specs.js Github

copy
1import chai from 'chai';
2import chaiAsPromised from 'chai-as-promised';
3import log from '../../lib/logger';
4import sinon from 'sinon';
5import { helpers, SETTINGS_HELPER_PKG_ID } from '../../lib/android-helpers';
6import { withMocks } from 'appium-test-support';
7import AndroidDriver from '../..';
8import ADB from 'appium-adb';
9import { errors } from 'appium-base-driver';
10import { fs } from 'appium-support';
11import { SharedPrefsBuilder } from 'shared-preferences-builder';
12import _ from 'lodash';
13
14let driver;
15let sandbox = sinon.createSandbox();
16let expect = chai.expect;
17chai.should();
18chai.use(chaiAsPromised);
19
20describe('driver', function () {
21  describe('constructor', function () {
22    it('should call BaseDriver constructor with opts', function () {
23      let driver = new AndroidDriver({foo: 'bar'});
24      driver.should.exist;
25      driver.opts.foo.should.equal('bar');
26    });
27    it('should have this.findElOrEls', function () {
28      let driver = new AndroidDriver({foo: 'bar'});
29      driver.findElOrEls.should.exist;
30      driver.findElOrEls.should.be.a('function');
31    });
32  });
33
34  describe('emulator methods', function () {
35    describe('fingerprint', function () {
36      it('should be rejected if isEmulator is false', function () {
37        let driver = new AndroidDriver();
38        sandbox.stub(driver, 'isEmulator').returns(false);
39        driver.fingerprint(1111).should.eventually.be.rejectedWith('fingerprint method is only available for emulators');
40        driver.isEmulator.calledOnce.should.be.true;
41      });
42    });
43    describe('sendSMS', function () {
44      it('sendSMS should be rejected if isEmulator is false', function () {
45        let driver = new AndroidDriver();
46        sandbox.stub(driver, 'isEmulator').returns(false);
47        driver.sendSMS(4509, 'Hello Appium').should.eventually.be.rejectedWith('sendSMS method is only available for emulators');
48        driver.isEmulator.calledOnce.should.be.true;
49      });
50    });
51    describe('sensorSet', function () {
52      it('sensorSet should be rejected if isEmulator is false', function () {
53        let driver = new AndroidDriver();
54        sandbox.stub(driver, 'isEmulator').returns(false);
55        driver.sensorSet({sensorType: 'light', value: 0}).should.eventually.be.rejectedWith('sensorSet method is only available for emulators');
56        driver.isEmulator.calledOnce.should.be.true;
57      });
58    });
59  });
60  describe('sharedPreferences', function () {
61    driver = new AndroidDriver();
62    let adb = new ADB();
63    driver.adb = adb;
64    let builder = new SharedPrefsBuilder();
65    describe('should skip setting sharedPreferences', withMocks({driver}, (mocks) => {
66      it('on undefined name', async function () {
67        driver.opts.sharedPreferences = {};
68        (await driver.setSharedPreferences()).should.be.false;
69        mocks.driver.verify();
70      });
71    }));
72    describe('should set sharedPreferences', withMocks({driver, adb, builder, fs}, (mocks) => {
73      it('on defined sharedPreferences object', async function () {
74        driver.opts.appPackage = 'io.appium.test';
75        driver.opts.sharedPreferences = {
76          name: 'com.appium.prefs',
77          prefs: [{type: 'string', name: 'mystr', value: 'appium rocks!'}]
78        };
79        mocks.driver.expects('getPrefsBuilder').once().returns(builder);
80        mocks.builder.expects('build').once();
81        mocks.builder.expects('toFile').once();
82        mocks.adb.expects('shell').once()
83          .withExactArgs(['mkdir', '-p', '/data/data/io.appium.test/shared_prefs']);
84        mocks.adb.expects('push').once()
85          .withExactArgs('/tmp/com.appium.prefs.xml', '/data/data/io.appium.test/shared_prefs/com.appium.prefs.xml');
86        mocks.fs.expects('exists').once()
87          .withExactArgs('/tmp/com.appium.prefs.xml')
88          .returns(true);
89        mocks.fs.expects('unlink').once()
90          .withExactArgs('/tmp/com.appium.prefs.xml');
91        await driver.setSharedPreferences();
92        mocks.driver.verify();
93        mocks.adb.verify();
94        mocks.builder.verify();
95        mocks.fs.verify();
96      });
97    }));
98  });
99
100  describe('createSession', function () {
101    beforeEach(function () {
102      driver = new AndroidDriver();
103      sandbox.stub(driver, 'checkAppPresent');
104      sandbox.stub(driver, 'checkPackagePresent');
105      sandbox.stub(driver, 'startAndroidSession');
106      sandbox.stub(ADB, 'createADB').callsFake(function (opts) {
107        return {
108          getDevicesWithRetry () {
109            return [
110              {udid: 'emulator-1234'},
111              {udid: 'rotalume-1337'}
112            ];
113          },
114          getPortFromEmulatorString () {
115            return 1234;
116          },
117          setDeviceId: () => {},
118          setEmulatorPort: () => {},
119          adbPort: opts.adbPort,
120          networkSpeed: () => {},
121          getApiLevel: () => 22,
122        };
123      });
124      sandbox.stub(driver.helpers, 'configureApp')
125        .withArgs('/path/to/some', '.apk')
126        .returns('/path/to/some.apk');
127    });
128    afterEach(function () {
129      sandbox.restore();
130    });
131    it('should verify device is an emulator', function () {
132      driver.opts.avd = 'Nexus_5X_Api_23';
133      driver.isEmulator().should.equal(true);
134      driver.opts.avd = undefined;
135      driver.opts.udid = 'emulator-5554';
136      driver.isEmulator().should.equal(true);
137      driver.opts.udid = '01234567889';
138      driver.isEmulator().should.equal(false);
139    });
140    it('should get browser package details if browserName is provided', async function () {
141      sandbox.spy(helpers, 'getChromePkg');
142      await driver.createSession({platformName: 'Android', deviceName: 'device', browserName: 'Chrome'});
143      helpers.getChromePkg.calledOnce.should.be.true;
144    });
145    it('should check an app is present', async function () {
146      await driver.createSession({platformName: 'Android', deviceName: 'device', app: '/path/to/some.apk'});
147      driver.checkAppPresent.calledOnce.should.be.true;
148    });
149    it('should check a package is present', async function () {
150      await driver.createSession({platformName: 'Android', deviceName: 'device', appPackage: 'some.app.package'});
151      driver.checkPackagePresent.calledOnce.should.be.true;
152    });
153    it('should accept a package via the app capability', async function () {
154      await driver.createSession({platformName: 'Android', deviceName: 'device', app: 'some.app.package'});
155      driver.checkPackagePresent.calledOnce.should.be.true;
156    });
157    it('should add server details to caps', async function () {
158      await driver.createSession({platformName: 'Android', deviceName: 'device', appPackage: 'some.app.package'});
159      driver.caps.webStorageEnabled.should.exist;
160    });
161    it('should pass along adbPort capability to ADB', async function () {
162      await driver.createSession({platformName: 'Android', deviceName: 'device', appPackage: 'some.app.package', adbPort: 1111});
163      driver.adb.adbPort.should.equal(1111);
164    });
165    it('should proxy screenshot if nativeWebScreenshot is off', async function () {
166      await driver.createSession({platformName: 'Android', deviceName: 'device', browserName: 'chrome', nativeWebScreenshot: false});
167      driver.getProxyAvoidList()
168        .some((x) => x[1].toString().includes('/screenshot'))
169        .should.be.false;
170    });
171    it('should not proxy screenshot if nativeWebScreenshot is on', async function () {
172      await driver.createSession({platformName: 'Android', deviceName: 'device', browserName: 'chrome', nativeWebScreenshot: true});
173      driver.getProxyAvoidList()
174        .some((x) => x[1].toString().includes('/screenshot'))
175        .should.be.true;
176    });
177  });
178  describe('deleteSession', function () {
179    beforeEach(function () {
180      driver = new AndroidDriver();
181      driver.caps = {};
182      driver.adb = new ADB();
183      driver.bootstrap = new helpers.bootstrap(driver.adb);
184      sandbox.stub(driver, 'stopChromedriverProxies');
185      sandbox.stub(driver.adb, 'setIME');
186      sandbox.stub(driver.adb, 'forceStop');
187      sandbox.stub(driver.adb, 'goToHome');
188      sandbox.stub(driver.adb, 'uninstallApk');
189      sandbox.stub(driver.adb, 'stopLogcat');
190      sandbox.stub(driver.adb, 'setAnimationState');
191      sandbox.stub(driver.adb, 'setDefaultHiddenApiPolicy');
192      sandbox.stub(driver.adb, 'getApiLevel').returns(27);
193      sandbox.stub(driver.bootstrap, 'shutdown');
194      sandbox.spy(log, 'debug');
195    });
196    afterEach(function () {
197      sandbox.restore();
198    });
199    it('should not do anything if Android Driver has already shut down', async function () {
200      driver.bootstrap = null;
201      await driver.deleteSession();
202      driver.stopChromedriverProxies.called.should.be.false;
203      driver.adb.stopLogcat.called.should.be.true;
204    });
205    it('should call stopLogcat even if skipLogcatCapture is true', async function () {
206      driver.opts.skipLogcatCapture = true;
207      await driver.deleteSession();
208      driver.adb.stopLogcat.called.should.be.true;
209    });
210    it('should reset keyboard to default IME', async function () {
211      driver.opts.unicodeKeyboard = true;
212      driver.opts.resetKeyboard = true;
213      driver.defaultIME = 'someDefaultIME';
214      await driver.deleteSession();
215      driver.adb.setIME.calledOnce.should.be.true;
216    });
217    it('should force stop non-Chrome sessions', async function () {
218      await driver.deleteSession();
219      driver.adb.forceStop.calledOnce.should.be.true;
220    });
221    it('should uninstall APK if required', async function () {
222      driver.opts.fullReset = true;
223      await driver.deleteSession();
224      driver.adb.uninstallApk.calledOnce.should.be.true;
225    });
226    it('should call setAnimationState to enable it with API Level 27', async function () {
227      driver._wasWindowAnimationDisabled = true;
228      await driver.deleteSession();
229      driver.adb.setAnimationState.calledOnce.should.be.true;
230      driver.adb.setDefaultHiddenApiPolicy.calledOnce.should.be.false;
231    });
232    it('should call setAnimationState to enable it with API Level 28', async function () {
233      driver._wasWindowAnimationDisabled = true;
234      driver.adb.getApiLevel.restore();
235      sandbox.stub(driver.adb, 'getApiLevel').returns(28);
236      await driver.deleteSession();
237      driver.adb.setAnimationState.calledOnce.should.be.true;
238      driver.adb.setDefaultHiddenApiPolicy.calledOnce.should.be.true;
239    });
240    it('should not call setAnimationState', async function () {
241      driver._wasWindowAnimationDisabled = false;
242      await driver.deleteSession();
243      driver.adb.setAnimationState.calledOnce.should.be.false;
244      driver.adb.setDefaultHiddenApiPolicy.calledOnce.should.be.false;
245    });
246  });
247  describe('dismissChromeWelcome', function () {
248    before(function () {
249      driver = new AndroidDriver();
250    });
251    it('should verify chromeOptions args', function () {
252      driver.opts = {};
253      driver.shouldDismissChromeWelcome().should.be.false;
254      driver.opts = {chromeOptions: {}};
255      driver.shouldDismissChromeWelcome().should.be.false;
256      driver.opts = {chromeOptions: {args: []}};
257      driver.shouldDismissChromeWelcome().should.be.false;
258      driver.opts = {chromeOptions: {args: '--no-first-run'}};
259      driver.shouldDismissChromeWelcome().should.be.false;
260      driver.opts = {chromeOptions: {args: ['--disable-dinosaur-easter-egg']}};
261      driver.shouldDismissChromeWelcome().should.be.false;
262      driver.opts = {chromeOptions: {args: ['--no-first-run']}};
263      driver.shouldDismissChromeWelcome().should.be.true;
264    });
265  });
266  describe('initAUT', withMocks({helpers}, (mocks) => {
267    beforeEach(function () {
268      driver = new AndroidDriver();
269      driver.caps = {};
270    });
271    it('should throw error if run with full reset', async function () {
272      driver.opts = {appPackage: 'app.package', appActivity: 'act', fullReset: true};
273      await driver.initAUT().should.be.rejectedWith(/Full reset requires an app capability/);
274    });
275    it('should reset if run with fast reset', async function () {
276      driver.opts = {appPackage: 'app.package', appActivity: 'act', fullReset: false, fastReset: true};
277      driver.adb = 'mock_adb';
278      mocks.helpers.expects('resetApp').withArgs('mock_adb');
279      await driver.initAUT();
280      mocks.helpers.verify();
281    });
282    it('should keep data if run without reset', async function () {
283      driver.opts = {appPackage: 'app.package', appActivity: 'act', fullReset: false, fastReset: false};
284      mocks.helpers.expects('resetApp').never();
285      await driver.initAUT();
286      mocks.helpers.verify();
287    });
288    it('should install "otherApps" if set in capabilities', async function () {
289      const otherApps = ['http://URL_FOR/fake/app.apk'];
290      const tempApps = ['/path/to/fake/app.apk'];
291      driver.opts = {
292        appPackage: 'app.package',
293        appActivity: 'act',
294        fullReset: false,
295        fastReset: false,
296        otherApps: `["${otherApps[0]}"]`,
297      };
298      sandbox.stub(driver.helpers, 'configureApp')
299        .withArgs(otherApps[0], '.apk')
300        .returns(tempApps[0]);
301      mocks.helpers.expects('installOtherApks').once().withArgs(tempApps, driver.adb, driver.opts);
302      await driver.initAUT();
303      mocks.helpers.verify();
304    });
305    it('should uninstall a package "uninstallOtherPackages" if set in capabilities', async function () {
306      const uninstallOtherPackages = 'app.bundle.id1';
307      driver.opts = {
308        appPackage: 'app.package',
309        appActivity: 'act',
310        fullReset: false,
311        fastReset: false,
312        uninstallOtherPackages,
313      };
314      driver.adb = new ADB();
315      sandbox.stub(driver.adb, 'uninstallApk')
316        .withArgs('app.bundle.id1')
317        .returns(true);
318      mocks.helpers.expects('uninstallOtherPackages').once().withArgs(driver.adb, [uninstallOtherPackages], [SETTINGS_HELPER_PKG_ID]);
319      await driver.initAUT();
320      mocks.helpers.verify();
321    });
322
323    it('should uninstall multiple packages "uninstallOtherPackages" if set in capabilities', async function () {
324      const uninstallOtherPackages = ['app.bundle.id1', 'app.bundle.id2'];
325      driver.opts = {
326        appPackage: 'app.package',
327        appActivity: 'act',
328        fullReset: false,
329        fastReset: false,
330        uninstallOtherPackages: `["${uninstallOtherPackages[0]}", "${uninstallOtherPackages[1]}"]`,
331      };
332      driver.adb = new ADB();
333      sandbox.stub(driver.adb, 'uninstallApk')
334        .returns(true);
335      mocks.helpers.expects('uninstallOtherPackages').once().withArgs(driver.adb, uninstallOtherPackages, [SETTINGS_HELPER_PKG_ID]);
336      await driver.initAUT();
337      mocks.helpers.verify();
338    });
339
340    it('get all 3rd party packages', async function () {
341      driver.adb = new ADB();
342      sandbox.stub(driver.adb, 'shell')
343        .returns('package:app.bundle.id1\npackage:io.appium.settings\npackage:io.appium.uiautomator2.server\npackage:io.appium.uiautomator2.server.test\n');
344      (await helpers.getThirdPartyPackages(driver.adb, [SETTINGS_HELPER_PKG_ID]))
345        .should.eql(['app.bundle.id1', 'io.appium.uiautomator2.server', 'io.appium.uiautomator2.server.test']);
346    });
347
348    it('get all 3rd party packages with multiple package filter', async function () {
349      driver.adb = new ADB();
350      sandbox.stub(driver.adb, 'shell')
351        .returns('package:app.bundle.id1\npackage:io.appium.settings\npackage:io.appium.uiautomator2.server\npackage:io.appium.uiautomator2.server.test\n');
352      (await helpers.getThirdPartyPackages(driver.adb, [SETTINGS_HELPER_PKG_ID, 'io.appium.uiautomator2.server']))
353        .should.eql(['app.bundle.id1', 'io.appium.uiautomator2.server.test']);
354    });
355
356    it('get no 3rd party packages', async function () {
357      driver.adb = new ADB();
358      sandbox.stub(driver.adb, 'shell').throws('');
359      (await helpers.getThirdPartyPackages(driver.adb, [SETTINGS_HELPER_PKG_ID]))
360        .should.eql([]);
361    });
362  }));
363  describe('startAndroidSession', function () {
364    beforeEach(function () {
365      driver = new AndroidDriver();
366      driver.adb = new ADB();
367      driver.bootstrap = new helpers.bootstrap(driver.adb);
368      driver.settings = { update () {} };
369      driver.caps = {};
370
371      // create a fake bootstrap because we can't mock
372      // driver.bootstrap.<whatever> in advance
373      let fakeBootstrap = {
374        start () {},
375        onUnexpectedShutdown: {catch () {}}
376      };
377
378      sandbox.stub(helpers, 'initDevice');
379      sandbox.stub(helpers, 'unlock');
380      sandbox.stub(helpers, 'bootstrap').returns(fakeBootstrap);
381      sandbox.stub(driver, 'initAUT');
382      sandbox.stub(driver, 'startAUT');
383      sandbox.stub(driver, 'defaultWebviewName');
384      sandbox.stub(driver, 'setContext');
385      sandbox.stub(driver, 'startChromeSession');
386      sandbox.stub(driver, 'dismissChromeWelcome');
387      sandbox.stub(driver.settings, 'update');
388      sandbox.stub(driver.adb, 'getPlatformVersion');
389      sandbox.stub(driver.adb, 'getScreenSize');
390      sandbox.stub(driver.adb, 'getModel');
391      sandbox.stub(driver.adb, 'getManufacturer');
392      sandbox.stub(driver.adb, 'getApiLevel').returns(27);
393      sandbox.stub(driver.adb, 'setHiddenApiPolicy');
394      sandbox.stub(driver.adb, 'setAnimationState');
395    });
396    afterEach(function () {
397      sandbox.restore();
398    });
399    it('should set actual platform version', async function () {
400      await driver.startAndroidSession();
401      driver.adb.getPlatformVersion.calledOnce.should.be.true;
402    });
403    it('should auto launch app if it is on the device', async function () {
404      driver.opts.autoLaunch = true;
405      await driver.startAndroidSession();
406      driver.initAUT.calledOnce.should.be.true;
407    });
408    it('should handle chrome sessions', async function () {
409      driver.opts.browserName = 'Chrome';
410      await driver.startAndroidSession();
411      driver.startChromeSession.calledOnce.should.be.true;
412    });
413    it('should unlock the device', async function () {
414      await driver.startAndroidSession();
415      helpers.unlock.calledOnce.should.be.true;
416    });
417    it('should start AUT if auto lauching', async function () {
418      driver.opts.autoLaunch = true;
419      await driver.startAndroidSession();
420      driver.initAUT.calledOnce.should.be.true;
421    });
422    it('should not start AUT if not auto lauching', async function () {
423      driver.opts.autoLaunch = false;
424      await driver.startAndroidSession();
425      driver.initAUT.calledOnce.should.be.false;
426    });
427    it('should set the context if autoWebview is requested', async function () {
428      driver.opts.autoWebview = true;
429      await driver.startAndroidSession();
430      driver.defaultWebviewName.calledOnce.should.be.true;
431      driver.setContext.calledOnce.should.be.true;
432    });
433    it('should set the context if autoWebview is requested using timeout', async function () {
434      driver.setContext.onCall(0).throws(errors.NoSuchContextError);
435      driver.setContext.onCall(1).returns();
436
437      driver.opts.autoWebview = true;
438      driver.opts.autoWebviewTimeout = 5000;
439      await driver.startAndroidSession();
440      driver.defaultWebviewName.calledOnce.should.be.true;
441      driver.setContext.calledTwice.should.be.true;
442    });
443    it('should respect timeout if autoWebview is requested', async function () {
444      this.timeout(10000);
445      driver.setContext.throws(new errors.NoSuchContextError());
446
447      let begin = Date.now();
448
449      driver.opts.autoWebview = true;
450      driver.opts.autoWebviewTimeout = 5000;
451      await driver.startAndroidSession().should.eventually.be.rejected;
452      driver.defaultWebviewName.calledOnce.should.be.true;
453
454      // we have a timeout of 5000ms, retrying on 500ms, so expect 10 times
455      driver.setContext.callCount.should.equal(10);
456
457      let end = Date.now();
458      (end - begin).should.be.above(4500);
459    });
460    it('should not set the context if autoWebview is not requested', async function () {
461      await driver.startAndroidSession();
462      driver.defaultWebviewName.calledOnce.should.be.false;
463      driver.setContext.calledOnce.should.be.false;
464    });
465    it('should set ignoreUnimportantViews cap', async function () {
466      driver.opts.ignoreUnimportantViews = true;
467
468      await driver.startAndroidSession();
469      driver.settings.update.calledOnce.should.be.true;
470      driver.settings.update.firstCall.args[0].ignoreUnimportantViews.should.be.true;
471    });
472    it('should not call dismissChromeWelcome on missing chromeOptions', async function () {
473      driver.opts.browserName = 'Chrome';
474      await driver.startAndroidSession();
475      driver.dismissChromeWelcome.calledOnce.should.be.false;
476    });
477    it('should call setAnimationState with API level 27', async function () {
478      driver.opts.disableWindowAnimation = true;
479      sandbox.stub(driver.adb, 'isAnimationOn').returns(true);
480
481      await driver.startAndroidSession();
482      driver.adb.isAnimationOn.calledOnce.should.be.true;
483      driver.adb.setHiddenApiPolicy.calledOnce.should.be.false;
484      driver.adb.setAnimationState.calledOnce.should.be.true;
485    });
486    it('should call setAnimationState with API level 28', async function () {
487      driver.opts.disableWindowAnimation = true;
488      sandbox.stub(driver.adb, 'isAnimationOn').returns(true);
489      driver.adb.getApiLevel.restore();
490      sandbox.stub(driver.adb, 'getApiLevel').returns(28);
491
492      await driver.startAndroidSession();
493      driver.adb.isAnimationOn.calledOnce.should.be.true;
494      driver.adb.setHiddenApiPolicy.calledOnce.should.be.true;
495      driver.adb.setAnimationState.calledOnce.should.be.true;
496    });
497    it('should not call setAnimationState', async function () {
498      driver.opts.disableWindowAnimation = true;
499      sandbox.stub(driver.adb, 'isAnimationOn').returns(false);
500
501      await driver.startAndroidSession();
502      driver.adb.isAnimationOn.calledOnce.should.be.true;
503      driver.adb.setHiddenApiPolicy.calledOnce.should.be.false;
504      driver.adb.setAnimationState.calledOnce.should.be.false;
505    });
506  });
507  describe('startChromeSession', function () {
508    beforeEach(function () {
509      driver = new AndroidDriver();
510      driver.adb = new ADB();
511      driver.bootstrap = new helpers.bootstrap(driver.adb);
512      driver.settings = { update () { } };
513      driver.caps = {};
514
515      sandbox.stub(driver, 'setupNewChromedriver').returns({
516        on: _.noop,
517        proxyReq: _.noop,
518      });
519      sandbox.stub(driver, 'dismissChromeWelcome');
520    });
521    afterEach(function () {
522      sandbox.restore();
523    });
524    it('should call dismissChromeWelcome', async function () {
525      driver.opts.browserName = 'Chrome';
526      driver.opts.chromeOptions = {
527        'args': ['--no-first-run']
528      };
529      await driver.startChromeSession();
530      driver.dismissChromeWelcome.calledOnce.should.be.true;
531    });
532  });
533  describe('validateDesiredCaps', function () {
534    before(function () {
535      driver = new AndroidDriver();
536    });
537    it('should throw an error if caps do not contain an app, package or valid browser', function () {
538      expect(() => {
539        driver.validateDesiredCaps({platformName: 'Android', deviceName: 'device'});
540      }).to.throw(/must include/);
541      expect(() => {
542        driver.validateDesiredCaps({platformName: 'Android', deviceName: 'device', browserName: 'Netscape Navigator'});
543      }).to.throw(/must include/);
544    });
545    it('should not throw an error if caps contain an app, package or valid browser', function () {
546      expect(() => {
547        driver.validateDesiredCaps({platformName: 'Android', deviceName: 'device', app: '/path/to/some.apk'});
548      }).to.not.throw(Error);
549      expect(() => {
550        driver.validateDesiredCaps({platformName: 'Android', deviceName: 'device', browserName: 'Chrome'});
551      }).to.not.throw(Error);
552      expect(() => {
553        driver.validateDesiredCaps({platformName: 'Android', deviceName: 'device', appPackage: 'some.app.package'});
554      }).to.not.throw(/must include/);
555    });
556    it('should not be sensitive to platform name casing', function () {
557      expect(() => {
558        driver.validateDesiredCaps({platformName: 'AnDrOiD', deviceName: 'device', app: '/path/to/some.apk'});
559      }).to.not.throw(Error);
560    });
561    it('should not throw an error if caps contain both an app and browser, for grid compatibility', function () {
562      expect(() => {
563        driver.validateDesiredCaps({platformName: 'Android', deviceName: 'device', app: '/path/to/some.apk', browserName: 'iPhone'});
564      }).to.not.throw(Error);
565    });
566    it('should not throw an error if caps contain androidScreenshotPath capability', function () {
567      expect(() => {
568        driver.validateDesiredCaps({platformName: 'Android', deviceName: 'device', app: '/path/to/some.apk', androidScreenshotPath: '/path/to/screenshotdir'});
569      }).to.not.throw(Error);
570    });
571  });
572  describe('proxying', function () {
573    before(function () {
574      driver = new AndroidDriver();
575      driver.sessionId = 'abc';
576    });
577    describe('#proxyActive', function () {
578      it('should exist', function () {
579        driver.proxyActive.should.be.an.instanceof(Function);
580      });
581      it('should return false', function () {
582        driver.proxyActive('abc').should.be.false;
583      });
584      it('should throw an error if session id is wrong', function () {
585        (() => { driver.proxyActive('aaa'); }).should.throw;
586      });
587    });
588
589    describe('#getProxyAvoidList', function () {
590      it('should exist', function () {
591        driver.getProxyAvoidList.should.be.an.instanceof(Function);
592      });
593      it('should return jwpProxyAvoid array', function () {
594        let avoidList = driver.getProxyAvoidList('abc');
595        avoidList.should.be.an.instanceof(Array);
596        avoidList.should.eql(driver.jwpProxyAvoid);
597      });
598      it('should throw an error if session id is wrong', function () {
599        (() => { driver.getProxyAvoidList('aaa'); }).should.throw;
600      });
601    });
602
603    describe('#canProxy', function () {
604      it('should exist', function () {
605        driver.canProxy.should.be.an.instanceof(Function);
606      });
607      it('should return false', function () {
608        driver.canProxy('abc').should.be.false;
609      });
610      it('should throw an error if session id is wrong', function () {
611        (() => { driver.canProxy('aaa'); }).should.throw;
612      });
613    });
614  });
615});
616
Full Screen

general-specs.js

Source: general-specs.js Github

copy
1import chai from 'chai';
2import chaiAsPromised from 'chai-as-promised';
3import sinon from 'sinon';
4import EspressoDriver from '../../../lib/driver';
5
6chai.should();
7chai.use(chaiAsPromised);
8let sandbox = sinon.createSandbox();
9
10describe('commands', function () {
11  describe('general', function () {
12    let driver;
13    describe('settings', function () {
14      beforeEach(function () {
15        driver = new EspressoDriver({}, false);
16        driver.caps = { appPackage: 'io.appium.package', appActivity: '.MainActivity'};
17        driver.opts = { autoLaunch: false, skipUnlock: true };
18        sandbox.stub(driver, 'initEspressoServer');
19        sandbox.stub(driver, 'initAUT');
20        sandbox.stub(driver, 'startEspressoSession');
21      });
22
23      it('update settings', async function () {
24        await driver.createSession({platformName: 'Android', deviceName: 'device', appPackage: driver.caps.appPackage});
25        await driver.updateSettings().should.be.rejectedWith('Method has not yet been implemented');
26      });
27      it('get settings', async function () {
28        await driver.createSession({platformName: 'Android', deviceName: 'device', appPackage: driver.caps.appPackage});
29        await driver.getSettings().should.be.rejectedWith('Method has not yet been implemented');
30      });
31    });
32  });
33});
34
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Appium Android Driver on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)