How to setup android virtual devices(AVD)(Emulator) for Android test automation:

Requirements:

1.Install latest Java JDK

2.Install latest Android SDK

 

Android SDK comes with AVD manager which will help in creating AVDs of required configuration. User can create many of these devices and save them for later use.

Below are the steps by step instruction on how to create AVD

  1. Go to Android SDK folder (default path: C:/Users/<username>/AppData/Local/Android/sdk)
  2. Run by double clicking on AVD Manager.exe executable

avdmanager

3. Clicking on create button will give you create new AVD . Fill in all the configuration required to match the device which you are planning to test on. Remember the AVD name you have entered which will be used to bring up the AVD in the next steps.

createnewavd

 

  1. You can bring up/start  the AVD you created either through the AVD manager UI or through command line. For automation command line is the better option.

Using AVD manager to start the ADV device created:

starting-avd

 

Using AVD manager to start the ADV device created:

In the Command prompt >>Go to android sdk tools folder and run below command you should remember the ADV name you created in earlier step.

C:/Users/<username>/AppData/Local/Android/sdk/tools>emulator.exe -netdelay none -netspeed full -avd Nexus_5X_API_23

where Nexus_5X_API_23 is the name you have give to the AVD you created.

 

starting-avd-cmd-line

 

  1. To verify that the AVD device is successfully launched you can confirm it in two ways either through UI or by command

Once you start AVD you see a pop up with android devic

actual-avd-image-after-launching

 

Or through command line you run the below command by going to Android sdk platfrom-tools folder

C:/Users/<username>/AppData/Local/Android/sdk/platform-tools>adb.exe devices

verify-avd-is-running

Note the AVD device name . This is needed during automation test case creation.

Appium function where we will be using device name of AVD(Emulator) in automation script is as shown below

Open Application  http://localhost:4723/wd/hub  platformName=Android  platformVersion=5.1.1  deviceName=emulator-5554  app=com.android.browser  automationName=appium  appPackage=com.android.browser  appActivity=AddBookmarkPage

Please refer Sample Robot Framework Test case  section of Appium up & running with Robot Framework blog for more details on how to setup and run the test cases.

This is it.

Please write to us if you are unable to follow the blog or you need any assistance in setting up the device.

 

Thank you,

Raghavendra Balgi

Like to come up with simple solutions to complex issues encountered during testing security products/applications and to share my knowledge thru blogs. Working as Technical leader in network security domain.

6 thoughts on “How to setup android virtual devices(AVD)(Emulator) for Android test automation:

  1. Hi Thanks for your post but I have one question

    On point 3 screenshot, It is complaining about no CPU found at bottom, How did you resolve that issue?

  2. I get this error after pybot the txt in cli. The “com.android.chrome” do available by checking adb package.

    (Original error: An unknown server-side error occurred while processing the command. (Original error: unknown error: com.android.chrome is not installed on device emulator-5554

    This is my Open Application:
    Open Application http://localhost:4723/wd/hub platformName=Android platformVersion=6.0 deviceName=emulator-5554 app=com.android.browser automationName=appium appPackage=com.android.browser appActivity=AddBookmarkPage

    1. Hi Ben,
      The open application command I mentioned in the blog works for stock android default browser package. If you are interested in chrome browser . please use below command.

      Open Application http://localhost:4723/wd/hub platformName=Android platformVersion=6.0.1 deviceName=emulator-5554 app=com.android.chrome automationName=appium appPackage=com.android.chrome appActivity=com.google.android.apps.chrome.Main

      You can use below test case to open chrome browser and go to http://www.testnblog.com url.

      ———————————————————–

      *** Settings ***

      Library AppiumLibrary
      Library demo_library.py
      Documentation demo for appium library
      Force Tags demo
      #Resource demo_resoure.txt

      *** Variables ***

      ${app} com.enfini.remindus

      *** Test Cases ***
      test_demo
      [Tags]

      Open Application http://localhost:4723/wd/hub platformName=Android platformVersion=6.0.1 deviceName=emulator-5554 app=com.android.chrome automationName=appium appPackage=com.android.chrome appActivity=com.google.android.apps.chrome.Main
      Click Element id=terms_accept
      sleep 2
      Click Element id=next_button
      sleep 2
      Click Element id=negative_button
      sleep 2
      Go to Url http://www.testnblog.com
      Close All Applications

      ——————————————————————

      Let me know if it works for you.

      -Raghavendra Balgi

  3. I have same problem as Ben was having. M yopen application command says com.android.browser which is what you used in the blog, but when I ran it, it keeps complaining about com.android.chrome is not installed on device emulator. Can you please help?

    1. Hi Jen,
      Can you try this. In the is I have changed com.android.browse to com.android.chrome

      Open Application http://localhost:4723/wd/hub platformName=Android platformVersion=6.0.1 deviceName=emulator-5554 app=com.android.chrome automationName=appium appPackage=com.android.chrome appActivity=com.google.android.apps.chrome.Main
      Click Element id=terms_accept

      let me know if this works.

Leave a Reply