How to use adb.waitForDevice 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.

reboot.js

Source: reboot.js Github

copy
1module.exports = async function reboot(adb, hard = true) {
2  if (hard) {
3    await adb.reboot();
4    await adb.waitForDevice();
5    return;
6  }
7
8  await adb.shell('stop b2g && start b2g');
9};
10
Full Screen

syscalls-e2e-specs.js

Source: syscalls-e2e-specs.js Github

copy
1import chai from 'chai';
2import chaiAsPromised from 'chai-as-promised';
3import ADB from '../..';
4import { apiLevel, avdName, MOCHA_TIMEOUT, MOCHA_LONG_TIMEOUT } from './setup';
5
6
7chai.use(chaiAsPromised);
8
9describe('System calls', function () {
10  this.timeout(MOCHA_TIMEOUT);
11
12  let adb;
13  before(async () => {
14    adb = await ADB.createADB();
15  });
16  it('getConnectedDevices should get devices', async () => {
17    let devices = await adb.getConnectedDevices();
18    devices.should.have.length.above(0);
19  });
20  it('getDevicesWithRetry should get devices', async () => {
21    let devices = await adb.getDevicesWithRetry();
22    devices.should.have.length.above(0);
23  });
24  it('adbExec should get devices when with devices', async () => {
25    (await adb.adbExec("devices")).should.contain("List of devices attached");
26  });
27  it('isDeviceConnected should be true', async () => {
28    (await adb.isDeviceConnected()).should.be.true;
29  });
30  it('shell should execute command in adb shell ', async () => {
31    (await adb.shell(['getprop', 'ro.build.version.sdk'])).should.equal(`${apiLevel}`);
32  });
33  it('getConnectedEmulators should get all connected emulators', async () => {
34    (await adb.getConnectedEmulators()).length.should.be.above(0);
35  });
36  it('getRunningAVD should get all connected avd', async () => {
37    (await adb.getRunningAVD(avdName)).should.not.be.null;
38  });
39  it('getRunningAVDWithRetry should get all connected avds', async () => {
40    (await adb.getRunningAVDWithRetry(avdName)).should.not.be.null;
41  });
42  // Skipping for now. Will unskip depending on how it behaves on CI
43  it.skip('launchAVD should get all connected avds', async function () {
44    this.timeout(MOCHA_LONG_TIMEOUT);
45    let proc = await adb.launchAVD(avdName);
46    (await adb.getConnectedEmulators()).length.should.be.above(0);
47    proc.stop();
48  });
49  it('waitForDevice should get all connected avds', async function () {
50    await adb.waitForDevice(2);
51  });
52  it('reboot should reboot the device', async function () {
53    this.timeout(MOCHA_LONG_TIMEOUT);
54    await adb.reboot(process.env.TRAVIS ? 200 : undefined);
55    await adb.ping();
56  });
57  it('fileExists should detect when files do and do not exist', async function () {
58    (await adb.fileExists('/foo/bar/baz.zip')).should.be.false;
59    (await adb.fileExists('/system/')).should.be.true;
60  });
61  it('ls should list files', async function () {
62    (await adb.ls('/foo/bar')).should.eql([]);
63    (await adb.ls('/system/')).should.contain('etc');
64  });
65});
66
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)