Scriptworks Logo

Getting Started With Mobile Test Automation (Android)

28 May 2021

This guided series of tutorials will walk you through the basics of getting started with Scriptworks for your mobile Test Automation with Android Emulators on Windows.

Introduction

In this article, we will set up our windows machine with an Android Emulator and use the inspection tool of Scriptworks.  You might like to read our guide on Mobile App Testing to get a clear understanding of the topic before getting hands-on.

Let’s follow a step by step procedure. 

1) First, Install Android Studio on your Windows Machine.

For that, navigate to https://developer.android.com/studio and click on Download Android Studio.

Navigate to Android Studio

2) Accept the terms and conditions by marking the checkbox and click on Download Android Studio for Windows Button.

Putting Terms and Conditions together

Putting Terms and conditions page 2

 3) Double Click on the Downloaded .exe (executable file) to start the installation process.

Welcome to Android setup

Click on the Next Button.

check box while installing

Click on the Next Button.

configuration settings

Click on the Next Button.

choosing start menu folder

Click on the Install Button.

Installation complete

Click on the Next Button

completing android studio setup

Uncheck the Start Android Studio Check box and click on Finish Button. 

4) Now, set up the environment variable for ANDROID_HOME (Pre-requisite:- Make sure Java JDK Version 1.8 or above is successfully installed and configured on your system).

Search for the environment variable in the search bar.

search from task bar for Environment variable

putting click on environment variable

Click on the Environment Variables button

clicking on new button

Click on the new button under the User variables section. Then enter the variable name as “ANDROID_HOME

Variable name should be Android_Home

Now for entering the variable value, we need to go to the Android SDK path. For that, type run in the search bar and hit Enter button and enter “%appdata%” and click on the ok button

Click on the Back button and traverse to the local→ Android→ Sdk.

reach out to sdk path

Now copy the path from the address bar and paste it into the variable value of the New user variable dialog box.

select path value

Setting android_home value

Click on the ok button.

select android_home

Now double click on the path under the system variable. And enter two more paths. 

  1. For Sdk → Platform-tools 
  2. For Sdk → toolsEnter the path variables now

Click on the OK button and close the Environment variable dialog box by clicking on the OK button.

5) Now start android studio, and let’s set up the android emulator needed for installing the android app under test. 

File → New → New Project → Phone and Tablet 

see the phone and tablet view

Click on the Next button.

Now give a name to the new project. I have given the name My Test App for more details, as per the screenshot below:

Project name my test app

Click on the Finish button.

Now go to tools and click on AVD Manager. (Tools → AVD Manager)

Click on Create Virtual Device Button

Click Create Virtual Device

Under Category, Select Phone and select Pixel 4a, then click on the Next button.

select phone for emulator purpose

Now Select a System Image. We are selecting API Level for our emulator. You will see it under the x86 Images option. If it is not present then it can be download. Then click on the Next Button.

Select API level which is 30

Now Finally, Click on Finish Button.

Click on Finish button on Android Virtual Device (AVD) Page

You will see your virtual device/emulator under Android Virtual Device Manager.

selected device listed under AVD Manager

Start it by clicking on the play button. 

watch out for emulator screen

6) Now, we will install the Application Under Test on the Emulator. For this exercise, we will use the Saucelabs Sample mobile app which can be downloaded from this location:-

https://github.com/saucelabs/sample-app-mobile/releases/download/2.7.1/Android.SauceLabs.Mobile.Sample.app.2.7.1.apk

Download it and drag and drop it onto the emulator window. You should see the installation being performed in the emulator, as shown in the screenshot below.

devices on page

6) Now we will install Appium on our windows machine so that Scriptworks can interact with the Appium server and enable us to automate our application installed on the emulator.

To Install Appium, navigate to https://appium.io/ and click on Download Appium.

click on download appium button

Double Click on the Downloaded .exe (executable file) for starting the installation process.

started with appium users

Check the radio button mentioning for all users. And click on the install button.

After the installation process has been completed, uncheck Run Appium and Click on the Finish button. 

completion of appium setup

7) Android Studio is Installed, the Android Emulator with the Application Under Test is ready, Appium is Installed. Now, what is left? 

We are left with starting our scriptworks-client. If we have not installed it yet and don’t know how to run it, then please follow this Article

Next we will set up Scriptworks Run Settings. Before filling out the Run Settings Info, we require three important parameters, which are as follows:- 

  1. The app package of the mobile application under test
  2. The app activity of mobile application under test
  3. The avd id of the emulator

Let’s figure out how we can get all of them one by one. 

To get the app package and app activity of the mobile application:- 

Open windows command prompt.

open cmd shell on windows machine

Now open the mobile app under test in your emulator. As shown below, screenshot.

open the emulator

In the command prompt, check if any devices are connected to it by entering “adb devices”'

enter command as adb devices

Now enter the command “adb shell

Enter Adb Shell command

After that, enter the command:

dumpsys window | grep - E mCurrentFocus

and hit enter/return.

enter command for finding app package and app activity

Here, the part before the '/' character, i.e., com.swaglabsmobileapp is the Package name, and the part after that, i.e., com.swaglabsmobileapp.MainActivity is the Activity name.

Now what we are left with is the AVD Id of the emulator. For that, go back to AVD Manager and click on the carrot symbol on the right and click on view details from the drop-down list.

Click on view details

Details dialogue box of your emulator will get open. Scroll down till you find AvdId

Click on view details

scroll till you see AvdId

Now we the three important parameters required for creating the Scriptworks run settings info. We can proceed: 

8) Let’s create the Scriptworks Run Settings info. 

To do that, Navigate to scriptworks.io  and log in with your credentials.

open scriptworks.io

Then Navigate to your project and click on Cog Icon on the left-hand side.

hover over cog icon and click on it

Click on New Run Settings button.

click on new run settings button

And fill in the required info in the Run Settings info dialogue box.

Run Settings info

Let’s name this Run setting as “Pixel 4a API 30” the same name as the emulator present in Virtual Devices in Android Studio. 

After that Give a suitable description like “Android Emulator Running Locally” 

Then Enter Selenium Server:- http://localhost:4723/wd/hub which will actually be the local Appium Server this time for testing a mobile application under test. 

Now Click on Add new and fill in details as shown below:-

see new details

Hint - The JSON section on the right hand side can be edited directly by cutting and pasting the following:

{
  "platformName": "Android",
  "deviceName ": "Pixel 4a API 30",
  "platformVersion": "11.0",
  "browserName": "",
  "avd": "Pixel_4a_API_30",
  "appPackage": "com.swaglabsmobileapp",
  "appActivity": "com.swaglabsmobileapp.MainActivity",
  "unicodeKeyboard": "true",
  "resetKeyboard": "true"
}

Hit Save to update the values in the Desired capabilities.

Now start scriptworks-client in your command prompt as shown below:-

watch out for scriptworks client running or not

Now Start the Appium Server:

view appium server dialogue box

view appium server running or not

Click on the Test Button beside Selenium server in the Scriptworks run settings info to validate whether the connection between Scriptworks and the Appium server has been made successfully or not?

click on test button

A Status Request will be shown in the Appium Log:

indication between appium server and scriptworks

And the light should show green if connection is successful:

If the Light shows red, please check the previous steps have been performed successfully and all components are started correctly.

Click on the save button to save the run settings.

9) Now click on the target symbol to go to Scriptworks inspector and click on the mode drop-down to select local session

target symbol is on left panel

select local session from the dropdown

Click on Start Button

start button on top right

Select the Pixel 4a API 30 entry from the "Select run settings to run session with" dialog and the application under test should launch in the Emulator and a screenshot display in the Inspector as shown below:

sync with emulator and scriptworks

If the screenshot is blank hit the Refresh button on the Inspector dialog to grab a fresh screenshot.

This is how after setting up Android Studio, Appium and Scriptworks our Windows machine, we can Inspect a Native Android application on the Emulator using Scriptworks.

Next Post>>

Scriptworks logo
© Copyright 2024 | Scriptworks is part of Odin Technology Ltd, a company registered in England no. 03735083