How to use driver.startAUT method in Appium Android Driver

Best JavaScript code snippet using appium-android-driver

driver-specs.js

Source:driver-specs.js Github

copy

Full Screen

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

Full Screen

Full Screen

general-specs.js

Source:general-specs.js Github

copy

Full Screen

...332                    waitDuration: 'wdur', optionalIntentArguments: 'opt', stopApp: false};333      driver.opts.dontStopAppOnReset = true;334      params.stopApp = false;335      sandbox.stub(driver.adb, 'startApp');336      await driver.startAUT();337      driver.adb.startApp.calledWithExactly(params).should.be.true;338    });339  });340  describe('setUrl', () => {341    it('should set url', async () => {342      driver.opts = {appPackage: 'pkg'};343      sandbox.stub(driver.adb, 'startUri');344      await driver.setUrl('url');345      driver.adb.startUri.calledWithExactly('url', 'pkg').should.be.true;346    });347  });348  describe('closeApp', () => {349    it('should close app', async () => {350      driver.opts = {appPackage: 'pkg'};...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var chai = require('chai');4var chaiAsPromised = require('chai-as-promised');5chai.use(chaiAsPromised);6chai.should();7var expect = chai.expect;8var driver = wd.promiseChainRemote('localhost', 4723);9var desiredCaps = {10};11driver.init(desiredCaps).then(function () {12    return driver.startAUT();13}).then(function () {14    return driver.quit();15});16var wd = require('wd');17var assert = require('assert');18var chai = require('chai');19var chaiAsPromised = require('chai-as-promised');20chai.use(chaiAsPromised);21chai.should();22var expect = chai.expect;23var driver = wd.promiseChainRemote('localhost', 4723);24var desiredCaps = {25};26driver.init(desiredCaps).then(function () {27return driver.startAUT();28}).then(function () {29return driver.quit();30});31var wd = require('wd');32var assert = require('assert');

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriverio = require('webdriverio');2var options = {3    desiredCapabilities: {4    }5};6var client = webdriverio.remote(options);7    .init()8    .end();9client.startAUT('com.example.android.apis', '.view.Controls1', function(err, res) {10    if (err) throw err;11    console.log(res);12});13    .init()14    .end();15var webdriverio = require('webdriverio');16var options = {17    desiredCapabilities: {18    }19};20var client = webdriverio.remote(options);21    .init()22    .end();23client.startAUT('com.example.android.apis', '.view.Controls1', function(err, res) {24    if (err) throw err;25    console.log(res);26});27    .init()28    .end();29var webdriverio = require('webdriverio');30var options = {31    desiredCapabilities: {32    }33};34var client = webdriverio.remote(options);35    .init()36    .end();37client.startAUT('com.example.android.apis', '.view.Controls1', function(err, res) {38    if (err) throw err;39    console.log(res);40});41    .init()42    .end();43var webdriverio = require('webdriverio');44var options = {45    desiredCapabilities: {

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd'),2    Q = require('q');3driver.init({4}).then(function () {5    return driver.startAUT();6}).then(function () {7    console.log("AUT started");8    return driver.quit();9}).done();

Full Screen

Using AI Code Generation

copy

Full Screen

1driver.startAUT();2driver.stopAUT();3driver.startActivity("com.android.calculator2","Calculator");4driver.currentActivity();5driver.getClipboard();6driver.setClipboard("text");7driver.isKeyboardShown();8driver.hideKeyboard();9driver.openNotifications();10driver.toggleLocationServices();11driver.toggleWiFi();12driver.toggleAirplaneMode();13driver.toggleData();14driver.toggleWiFi();15driver.toggleLocationServices();16driver.toggleData();17driver.toggleAirplaneMode();18driver.toggleWiFi();19driver.toggleLocationServices();20driver.toggleData();21driver.toggleAirplaneMode();22driver.toggleWiFi();23driver.toggleLocationServices();24driver.toggleData();25driver.toggleAirplaneMode();26driver.toggleWiFi();

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var driver = wd.remote();4var desiredCaps = {5};6driver.init(desiredCaps, function() {7  driver.startAUT(function() {8    console.log("AUT started");9  });10});

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2var driver = new webdriver.Builder()3    .forBrowser('chrome')4    .build();5driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');6driver.findElement(webdriver.By.name('btnG')).click();7driver.wait(function() {8    return driver.getTitle().then(function(title) {9        return title === 'webdriver - Google Search';10    });11}, 1000);12driver.quit();

Full Screen

Using AI Code Generation

copy

Full Screen

1driver.startAUT("com.example.android.apis", ".ApiDemos", "android", "8.0");2driver.startAUT("com.example.android.apis", ".ApiDemos", "android", "8.0", "en", "true");3driver.startAUT("com.example.android.apis", ".ApiDemos", "android", "8.0", "en", "true", "true");4driver.startAUT("com.example.android.apis", ".ApiDemos", "android", "8.0", "en", "true", "true", "true");5driver.startAUT("com.example.android.apis", ".ApiDemos", "android", "8.0", "en", "true", "true", "true", "true");6driver.startAUT("com.example.android.apis", ".ApiDemos", "android", "8.0", "en", "true", "true", "true", "true", "true");7driver.startAUT("com.example.android.apis", ".ApiDemos", "android", "8.0", "en", "true", "true", "true", "true", "true", "true");8driver.startAUT("com.example.android.apis", ".ApiDemos", "android", "8.0", "en", "true", "true", "true", "true", "true", "true", "true");9driver.startAUT("com.example.android.apis", ".ApiDemos", "android", "8.0", "en", "true", "true", "true", "true", "true", "true", "true", "true");10driver.startAUT("com.example.android.apis", ".ApiDemos", "android", "8.0", "en", "true", "true", "true", "true", "true", "true", "true", "true", "true");11driver.startAUT("com.example.android.apis", ".ApiDemos", "android", "8.0", "en", "true", "true", "true", "true", "true", "true", "true", "true", "true", "true");12driver.startAUT("com.example.android.apis", ".ApiDemos", "android", "8.0", "en", "true", "true", "true", "true", "true", "true", "true", "true",

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Appium Android Driver automation tests on LambdaTest cloud grid

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful