Install appium-adb via npm
masterInstall the appium-adb package using npm to use the ES6-based Android Debugger Bridge (ADB) wrapper.
npm install appium-adbrepository·master·Indexed 43 days ago
https://github.com/appium/appium-adbAn ES6 wrapper for the Android Debug Bridge (ADB) providing an async/await interface. Version 16.0.5. It is primarily used by Appium to interact with Android devices, offering utilities for APK installation and management, manifest extraction, and device control commands such as power management, GSM simulation, and root access.
Install the appium-adb package using npm to use the ES6-based Android Debugger Bridge (ADB) wrapper.
npm install appium-adbFunctional tests (e2e tests) run using an Android Virtual Device (AVD). By default, the tests use an AVD named NEXUS_S_18_X86 with API Level 18.
You can customize the testing environment using the following environment variables:
ANDROID_AVD: The name of the AVD to use.PLATFORM_VERSION: The platform version (if set, API_LEVEL is inferred).API_LEVEL: The specific API level to use.npm run e2e-testTo use the library, import the ADB class and use the static createADB() method to initialize an instance. Once initialized, you can perform various ADB operations using async/await.
import { ADB } from 'appium-adb';
const adb = await ADB.createADB();
console.log(await adb.getPIDsByName('com.android.phone'));Use sendSMS(phoneNumber, message) to send a text message from the device to a specified phone number.
let phoneNumber = 4509;
let message = "Hello Appium"
await adb.sendSMS(phoneNumber, message);Use rotate() to simulate a device rotation.
await adb.rotate();Use gsmVoice(state) to simulate different GSM voice registration states.
Possible values for state:
unregisteredhomeroamingsearchingdeniedoff (alias for unregistered)on (alias for home)let state = 'roaming';
await adb.gsmVoice(state);Use root() to attempt to gain root access on the device, and unroot() to remove root access.
await adb.root();
await adb.unroot();Use powerCapacity(batteryPercent) to simulate a specific battery percentage on the device.
let batteryPercent = 50;
await adb.powerCapacity(batteryPercent);Use powerAC(state) to toggle the AC power state of the device.
Possible values for state:
onofflet state = 'off';
await adb.powerAC(state);Use gsmSignal(signalStrengh) to set the GSM signal strength.
Possible values for signalStrengh:
0 through 4let signalStrengh = 0;
await adb.gsmSignal(signalStrengh);Use gsmCall(phoneNumber, action) to simulate GSM call actions on the device.
Possible values for action:
callacceptholdcancellet action = 'call';
let phoneNumber = 4509;
await adb.gsmCall(phoneNumber, action);Use powerOFF() to trigger a device power-off command.
await adb.powerOFF();