How to start Driver session via Appium Inspector for inspecting Apps on Android devices

DesiredCapabilities for connecting Apps on Android real and virtual devices for Appium server running on localhost

1. Learning Objectives

  • Start driver session with Android App on Android Virtual Device

  • Start driver session with Android App on real Android device

2. Pre-requisites

Note:

  • If you have not done any installations and setup. Please refer to this Android setup or iOS setup

  • All references here, cli commands, and screenshots are from Mac OS X. It may not work as is, windows specific post is work in progress

Installations required:

  • Android Studio to setup Android virtual devices

  • Appium Server

3. Start Driver Session on Android Virtual Device (AVD) using deviceName

Step 3.1: Start Appium Server

  • Start Appium server from the Terminal by executing 'appium' command

  • Note the Appium server IP and Port form the appium logs. Look for 'Appium REST http interface listener started on x.x.x.x:xxxx'

    • IP# 0.0.0.0 --> running locally on the machine

    • Port# 4723

Step 3.2: Start AVD

Start Appium server from the Device Manager on Android Studio or command line if you already know the device details

In our case, we have setup 3 virtual devices

Launching All 3 devices using the following command from the terminal:

/users/hp/Library/Android/sdk/emulator/emulator -avd <deviceLabel>&

$> /users/hp/Library/Android/sdk/emulator/emulator -avd pixel6Pro&

Step 3.3: Get Device Details from AVD

a. Get the list of all devices from CLI

$> adb devices

Step 3.4: Launch Appium Inspector

The default view when you launch the Appium Inspector contains 127.0.0.1 in the Remote Host, which is the same as 0.0.0.0 as we noted in Step#3.1

Step 3.5: Add Server details in Appium Inspector

As we are running Appium locally, we can provide the Remote Host server as 127.0.0.1 or 0.0.0.0 and in this let's use the host IP 0.0.0.0 as returned by the Appium server in Step#3.1

Step 3.6: Add DesiredCapabilities to be sent to the server to start the session

3.6.1 Prerequisite - Fetch deviceName or device id

a. how to Get the DeviceName from a virtual device

(i) Get the device name from Device Manager as shown below

(ii) note the device name, in this example, it is pixel_6_pro

b. how to Get the Device ID

list of device id returned by `adb devices`

  • device id for pixel6Pro: emulator-5554

  • device id for pixel4a_xl: emulator-5558

  • device id for nexus6: emulator-5556

3.6.2 Add Desired Capabilities

Note: To use the same apk used here, you can download it from here

Desired Capabilities using device name

Desired Capabilities using device id

Step 3.7: Start the driver session

Start the session with Desired Capabilities using device name

Start the session with Desired Capabilities using device id

a. Click on "Start Session", it would append appium prefix in the desired capabilities

If everything is correct, you should be able to see exact same screen on Emulator and Appium Inspector

If there is a mismatch you can always Sync as follows

4 Start Driver Session on Android Real Device (AVD) using UDID / deviceName

Step 4.1: Start Appium Server

Same as Step#3.1

Step 4.2: Start AVD

Same as Step#3.2

Step 4.3: Get Device Details from AVD

Same as Step#3.3

Step 4.4: Launch Appium Inspector

Same as Step#3.4

Step 4.5: Add Server details in Appium Inspector

Same as Step#3.5

Step 4.6: Add DesiredCapabilities to be sent to the server to start the session

4.6.1 Prerequisite - Fetch deviceName or device id

a. how to Get the DeviceName from a virtual device

Usually, it is under Settings >> About phone

In this example, device name is pixel6pro_real

b. how to Get the Device ID

list of device id returned by `adb devices`

  • virtual device id for pixel6Pro: emulator-5554

  • virtual device id for pixel4a_xl: emulator-5558

  • virtual device id for nexus6: emulator-5556

  • Real device id: 23231FDEE000RY

4.6.2 Add Desired Capabilities

Desired Capabilities using device name

Desired Capabilities using device id

Step 4.7: Start the driver session

Start the session with Desired Capabilities using device name

Start the session with Desired Capabilities using device id

Did you find this article valuable?

Support Himanshu Pandey by becoming a sponsor. Any amount is appreciated!