This is an important chapter of Mobile Testing as this will teach us How to Create An Android Virtual Device using Android Emulator or AVD Manager which is used during the Manual Mobile Testing and in Mobile Automation using Appium. But before Moving ahead with this long chapter it is necessary to understand the terms like Emulator, Android Virtual Device (AVD) & AVD Manager.
What is an Emulator?
An Emulator is an application that emulates real mobile device software, hardware and operating systems, allowing us to test and debug our application. It is generally provided by device manufacturer. Mobile emulators are free and provided as a part of SDK with each new OS release. As a developer or a tester, you can configure the emulator closely resemble the devices on which you plan to deploy your application.
A typical Android Emulator looks like this:
The emulator window consists of a device screen on the left and phone controls/keyboard on the right. The device screen initially displays ‘ANDROID‘, and then displays the graphical logo, while the Android platform associated with the AVD is initializing.
Tips to use Emulators effectively
- Use keyboard commands to easily interact with emulators.
- Mouse also works with Emulators, so one can use Mouse click, dragging & scrolling and keyboard arrows buttons.
- Buttons displayed on the right side of the Emulator also work with the help of the mouse click, like volume up/down, Home, Menu etc.
- If the machine is connected to internet, same can be used with in the Emulator as well.
- Notifications such as incoming messages appears in the white notification bar at the top of the screen, along with battery life and so on.
Note: Android Emulator is a powerful tool but no substitute for testing on the true target devices.
What is AVD Manager?
AVD Manager is a tool to create and manage Android Virtual Devices(AVDs), which define device configuration for the Android Emulator. Before you can actually run an emulator, you need to install the Android SDK on your machine, and define an AVD which defines the hardware characteristics of the emulator. You can define things like the device RAM, whether there is touch screen and/or keyboard, camera support, audio playback support, etc. You can create several AVDs to test your device on several virtual devices.
How to Create an Android Virtual Device using AVD Manager
Prerequisites for AVD Manager
- Install the Java Development Kit (JDK)
- Set Up Java Environment Variable Path
- Install Android SDK / ADB on Windows
- Set up Android Environment Variable
Once installation of the above prerequisites are done, we need to launch the SDK Manager to download relevant files to create an emulator and run the virtual device. In command line(cmd), type in android sdk. It would open the SDK Manager for you to download the relevant files. In the SDK Manager select the files as shown below. This will help you create a virtual devices.
Select the above files and choose to install, once done close the SDK manager.
- Get the latest SDK tools: Under Tools, install Android SDK Tools, Android SDK Platform tools and Android SDK Build Tools.
- Get the Android API: Select different Android versions and APIs for AVDs. These are the different environments for your application under test. You can choose multiple from Android 4.4.2 to 5.1.1.
- Get the Extras: Install the default selections as well as the “Intel x86 Emulator Accelerator (HAXM installer)”.
There are two ways to create Android Virtual Devices for Mobile testing:
- Using Command Line
- Using AVD Manager
Creating a New Android Virtual Device using AVD Manager
First step is to launch the AVD Manager and for that there are number of options you can follow:
- Launch AVD Manager using Program Menu
Go to Start > All Program > Android SDK Tools > AVD Manager
- Launch AVD Manager using Command Line
Go to Run and type cmd to open command prompt window. Type Android AVD.
- Launch AVD Manager from folder location
Browse to Android SDK folder and Double-click on AVD Manager.
Either of the above ways, it would open the Android Virtual Device Manager, which would help you create the virtual devices. The AVD Manager main screen shows one default virtual device, which is Nexus 5.
1) Click on Create button to create a new AVD.
2) A pop up will open, follow the below screenshot for the values. Choose a name for the AVD, in case simulating a specific device, you might want to name it as such. For example NexusSix-4.4 that refer to an AVD that simulate Nexus-SIx which runs on Android 4.4.2 version or anything that resemble your device configuration. In this test I choose a very generic name Android to keep it simple.
Note: You can play around with different configurations for your virtual device.
3) Click on OK to proceed with the save changes.
4) After you complete above steps, the emulator will be displayed under the Android Virtual Devices tab, configured on the AVD Manager. Now Select the AVD name and click on Start on the right.
5) This would launch the pop up with few options, you may choose as you want. Once done click on Launch, this will launch the emulator.
- Scale display to real size: This causes the resolution of the emulator’s display to be scaled to match the screen size.
- Wipe user data: This would wipe any previous app installation you have done and would launch a plain fresh emulator. Wipe user data.
- Launch from snapshot: This cause the emulated device to be started from a previously saved snapshot of the device’s state. The emulator launches much faster when launched from a snapshot.
- Save to snapshot: This causes the emulated device’s state to be saved to a snapshot upon device exit.
6) Emulator will launch, it would take few minutes to display the Home Screen of the virtual android device, actually it is as equal to Switch On the real Mobile device.
Note: You can use the command ‘adb devices‘ to see if the adb is detecting the emulator. This basically completes the android SDK installation part.
Note:If ANDROID logo appears for more than 15-30 minutes, something has probably gone wrong. Reboot your computer, start AVD Manager, delete our created ‘Android’ AVD, recreate this AVD, and relaunch new AVD.
The above screenshot shows the emulator window with 5554:Andoid in its title bar. Value 5554 identifies a console port that you can use to query and control the AVD’s environment. Android supports a maximum of 16 concurrently executing AVDs, where each AVD is assigned an even-numbered port number that starts at 5554. It means that we can initialize more then one AVD at the same time and can test the app with parallel execution.
Creating an Android Emulator using Command Line