Friday, 17 August 2018

Android ADB Use full commands for Testing/Automation

1. Get list of connected android device. 

Command: adb devices -l
Out put: Prints all the connected devices ID's along with the state of it. State can be Offline/Online/Unauthorized.

If Offline try to unplug the device and plug it. Or restart the adb server to get the device back to online.
Unauthorized: Might the an alert presents on the device to accept the trust prompt.

2. Restart Adb server.

Command: adb kill-server
Command: adb start-server

Note: Restart adb server will resolve most of the issues

3. What is adb ? How it works? 

adb is tool/utility provided by google to interact with the connected android devices. By using adb we can connect the devices in shell mode and we can pass some commands and gets response from the devices. 

adbd  - is a process which runs on the devices and whatever the commands that we send from our system to device will read by this adbd and gives the response.

4. How can I connect to a single device when multiple devices are connected?

First run the below command to get the list of devices connected your system. 
Command: adb devices -l
Output: It will return the list of devices with the device id (Serial Numbers). 
Get the serial number. and run the below command to interact with the specific device. 

Command: adb -s <serial no of device> shell
Output: It will connect to the specific device and enter into shell. Now we can send commands to this specific device only.

One more example: 
We can use this command to reboot one specific device. 
Command: adb -s <serial no of device> reboot