Complete Guide to Creating Emulators/AVD for Mobile App Testing


1. Introduction

Mobile app testing is a crucial part of the software development life cycle, ensuring that applications perform as expected on various devices and operating systems. However, testing on physical devices can be expensive and time-consuming. That's where emulators come in. Emulators are software applications that simulate real mobile devices, allowing developers and testers to test their apps without the need for physical devices.

This comprehensive guide aims to provide you with a complete understanding of mobile app testing using emulators. We will explore the concept of emulators, the AVD Manager (Android Virtual Device Manager), and how to set up and configure emulators for testing. Additionally, we will delve into writing Appium test scripts to automate testing tasks and cover various aspects of interacting with emulators.

By the end of this guide, you will have a solid foundation for testing mobile apps using emulators, enabling you to efficiently validate your applications across different devices and platforms. Let's dive in and explore the world of mobile app testing with emulators!


Table of Contents

1. Introduction
    1.1 What is an Emulator?
    1.2 What is AVD Manager?

2. Setting Up the Android Emulator
    2.1 Creating an Android Virtual Device (AVD) using AVD Manager
    2.2 Creating an Android Emulator using Command Line
    2.3 Configuring Default Device Definition
    2.4 Creating a Custom Device Definition

3. Automation using an Android Emulator
    3.1 Getting Emulator Platform Version
    3.2 Unlocking the Android Emulator Screen
    3.3 Verifying the Availability of Calculator App in Emulator

4. Running the Appium Test on the Emulator

Conclusion

Setting Up Mobile Devices and Emulators

Before you can automate native mobile apps with Appium, you need to set up the mobile devices or emulators on which your app will run. In this tutorial, we will walk through the process of setting up mobile devices and emulators for Appium automation. Real Devices:
i. If you have physical mobile devices, you can connect them to your computer using USB cables for automation.

ii. Ensure that USB debugging is enabled on the devices by going to the developer options in the device settings.

iii. Install the necessary device drivers and ensure the devices are recognized by your operating system.

1.1. 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 the 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 to closely resemble the devices on which you plan to deploy your application.
The emulator window consists of a device screen on the left and a 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. Appium supports popular emulators like Android Emulator and iOS Simulator.

1.2. 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 a touch screen and/or keyboard, camera support, audio playback support, etc. You can create several AVDs to test your device on several virtual devices.

1.3. iOS Simulator Setup:

On macOS, you can access the iOS Simulator directly from Xcode, which is Apple's development environment.

i. Install Xcode from the Mac App Store and launch it.

ii. Open Xcode preferences and navigate to the Components tab.

iii. Install the simulator for the desired iOS version


2. Setting Up the Emulator

How to Create an Android Virtual Device?

Once installation of all the prerequisites is done, we need to launch the SDK Manager to download relevant files to create an emulator and run the virtual device.
  • In the 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 device
There are two ways to create Android Virtual Devices for mobile testing:
  • Using Command Line
  • Using AVD Manager

2.1. Creating a New Android Virtual Device using AVD Manager

The first step is to launch the AVD Manager and for that, there are a 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 the command prompt window. Type: android AVD
  • Launch AVD Manager from folder location: Browse to the Android SDK folder and Double-click on AVD Manager.
Either of the above ways 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
Create button to create a new AVD
2. A pop-up will open, follow the below screenshot for the values. In case you are simulating a specific device, you might want to name it as such. For example, NexusSix-4.4 refers to an AVD that simulates Nexus-SIx which runs on Android 4.4.2 version.
NexusSix-4.4 refers to an AVD
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.

Click on OK to proceed
4. After you complete the 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.
AVD name and click on Start on the right
5. This would launch the pop-up with a few options, you may choose as you want. Once done, click on Launch, this will launch the emulator.
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
  • Launch from snapshot: This causes the emulated device to start 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 a few minutes to display the Home Screen of the virtual Android device. The time taken is actually equal to the switch-on time 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.
  • If the 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 the new AVD.
The emulator window launched with 5554:Android 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 than one AVD at the same time and can test the app with parallel execution.

2.2. Creating an Android Emulator using Command Line

Android Emulator can be configured differently for simulating different Android devices. With the help of AVD configuration, Android Emulator can simulate:
  • Target platforms versions
  • Screen sizes
  • Solutions
  • Input methods
  • Hardware configurations
  • External storage sizes for SD card
Although there are a good number of default device configurations present in AVD Manager, if you have any particular device in mind that you want to emulate, you need to create an AVD that resembles the features of your target device. For example, you need to know the screen size and resolution and so on. 

Creating Default Device Definition

1. Go to the Device Definitions tab and select one of the presets and click ‘Create AVD’
2. Every default device will provide you some preset AVD that can be changed according to your need
how 6
Note: Notice that the OK button is disabled, just because under CPU/ABI it says that “No system Images installed for this target“. To avoid this, select a different Device configuration from Device & select any skin or select none for skin and proceed.
Below is the list of optional and mandatory settings:
  • AVD NAME: Choose a name for the AVD like NexusSix-4.4 that refers to your device configuration
  • Device: Select the AVD resolution as per the device options
  • Target: Select the Android version / Test Environment or Target Platform
  • CPU/ABI: Select Intel Atom (x86) for 32-bit and ARM (armeabi-v7) for 64-bit.
  • Keyboard: Select this box to use the keyboard in the AVD
  • Skin: Select this box to get the hardware buttons
  • Front Camera: If the system has a webcam, that can be used with AVD
  • Back Camera: If the system has a webcam, that can be used with AVD
  • Memory Options: Set RAM & VM Heap for the device according to your need
  • Internal Storage: Set this as per your need and Select GiB/MiB from the drop-down
  • SD Card: Set this as per your need and Select GiB/MiB from the drop-down
  • Emulation Options
        - Snapshot: Select this to persist, it lets you quickly start the emulator after the first startup.
        - Use Host GPU: Select this to use the computer graphics

3. After you complete the above steps, the emulator will be displayed under the Android Virtual Devices tab, configured on the AVD Manager. Now Select the newly added AVD name and click on Start on the right.
4. This would launch the pop-up with a 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
  • Launch from snapshot: This causes 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
Once done, Emulator will launch. It would take a few minutes to display the Home Screen of the virtual Android device.

2.3. Creating a Custom Device Definition

In case the available device definitions do not match the device type you’d like to emulate, you can create a custom device definition for your AVD:
1. If the AVD manager is opened, go to Device Definitions
2. Click on Create Devices.
3. The Configure Hardware Profile window will display and it will allow you to specify various configurations such as the screen size, memory options, input type, and sensors.
Note: Once all the information is filled in properly, Create Device button will get enabled and you may proceed then.
4. After you complete the above steps, the emulator will be displayed under the Device Definition tab, configured on the AVD Manager. Now Select the newly created AVD name and click on Create AVD on the right.

3. Automation using an Android Emulator

  • Get Emulator Platform Version
  • Unlock the Android emulator screen
  • Go to Settings. You will find About Phone under settings.
  • Go to About Phone. It will show you the Android version
  • Verify calculator App Is Available In Emulator 

We are going to run an Appium test for the calculator application so it should be there in the emulator. Generally, the calculator app will be already installed in the emulator. To check if it is installed or not,
1. Unlock the emulator
2. Verify if there is an application with the name Calculator
3. Get app activity and package name. We need the launcher activity and package name of the calculator app. The activity and package name of the calculator app for me are:
  • Package name: com.android.calculator2
  • Activity name: com.android.calculator2.Calculator
4. Create Appium Test Script In Eclipse. Now we are ready to create and run our first Appium test on an Android emulator for the calculator application. I have prepared the Appium test script below. I have used RemoteWebDriver of Selenium Webdriver to launch an app with the required capabilities.
5. To start an instance of the emulator from the command line, navigate to the tools/ folder of the SDK. Enter the emulator command like this: emulator -and  []
So that was all about performing Appium testing on the emulator.


Guest Author

Deepshikha Singh

Automation Expert

Follow Techlistic

YouTube Channel | Facebook Page | Telegram Channel | Quora Space
If you like our blogs and tutorials, then sponsor us via PayPal

Comments

  1. Great post, your all points fully clarify, Android Mobile Development Dubai These steps are very helpful for us. Thank you for providing such a valuable information.

    ReplyDelete
  2. I am attracted by the presentation of this article. This information about Mobile App Development Company is really good. I really appreciate your work. It is a gainful article for us. Keep posting. Thank you.

    ReplyDelete

Post a Comment

Popular posts from this blog

Automation Practice: Automate Amazon like E-Commerce Website with Selenium

17 Best Demo Websites for Automation Testing Practice

Top 7 Web Development Trends in the Market

Mastering Selenium Practice: Automating Web Tables with Demo Examples

Web Automation Simplified By Virtual Ninja (Robot Framework)

14 Best Selenium Practice Exercises for Automation Practice

Handle Multiple Browser Tabs and Alerts with Selenium WebDriver

Boost Your Career: Top 10 Job Search and Skill-Enhancing Websites for Success

How to Automate Google Search with Selenium WebDriver

Mastering Selenium WebDriver: 25+ Essential Commands for Effective Web Testing