(MOBILE AUTOMATION)
Pre-Requisite to install the APPIUM: -
[Before download and install APPIUM in windows, please make sure bellow given prerequisites are fulfilled.]
-
JDK Installed.
-
Android SDK Installed.
-
Set ANDROID_HOME and Path Environment Variables.
-
Eclipse/ IntelliJ Installed.
-
Node JS and npm Installed.
Follow the steps given below to download the latest version of JDK –
- Open this link – https://www.oracle.com/java/technologies/downloads/
- Scroll down a bit and then select Java 17, and then Windows
- Click on .exe link
JDK should successfully download to your machine.
Given below are the steps that you can follow to install the latest version of JDK on your machine –
- Navigate to the folder where you had downloaded JDK. Double click on the exe file to start the installation process
- The installation process would now begin. Click on Next button on the Setup screen
- Wait for a few seconds for Java to install some files. After that, it will ask you to specify the destination folder for JDK. Leave the default location as it is and click on Next button
- JDK installation would now begin
- Once the installation is completed, you will see the window as shown in the screenshot below. Click on Close button to close the window
- To verify that the installation is successful, open Java folder in Program files. You would see that a new JDK folder with the latest version numbers has been created.
- As the first step, please copy the folder location where the latest version of JDK is installed, we had installed JDK at the default location (C:\Program Files\Java). If you have also done the same, then open that location
- You have to open the environment variables window in your machine. To do this, click on the Search icon and then type environment variables in the search bar. Click on Edit the system environment variables option to open it
- This would open the System Properties window as shown below. Now from the Advanced Tab, click on Environment Variables button
From the Environment Variables window, click on New button from
System variables section
![Add new value (JAVA_HOME) in System Variables]
- Enter JAVA_HOME in Variable Name field and JDK folder location (C:\Program Files\Java\jdk-17) in Variable value field as shown in below image. Please enter the correct folder location that you have in your machine
- Click on the OK button. You will see that JAVA_HOME variable has now been added in System Variables.
If you already have JAVA_HOME previously set, then you can click on Edit button to modify its value.
Path variable refers to the location of the bin folder inside the JDK folder.
Let’s see the steps to do this –
-
Open your latest JDK folder and check that it has bin folder in it
-
Now open this bin folder and copy the entire folder location. For us, this folder location is – C:\Program Files\Java\jdk-17\bin
-
Since the JDK folder location is already represented by JAVA_HOME variable, so we can replace the location of JDK folder with JAVA_HOME like this – %JAVA_HOME%\bin
-
In the Environment variables window, check that there is a variable called Path under System variables. Please note that Path is an existing variable, and we would edit it to add the bin folder location
- Select the Path variable and click on the Edit button. Edit environment variable window would be opened
- Click on the New button. A new line is highlighted in the window. Add JDK bin path %JAVA_HOME%\bin as shown in the below image
![Add bin folder location to PATH variable]
- Click on the Ok button. bin folder location is now added in the Path variable
- Close the Environment variable window by clicking on the Ok button. With this, we have now successfully setup Path variable as well
After you have added JAVA_HOME and Path variables, it’s time to check if the variables are set correctly. Follow the steps given below to check this –
- Open command prompt
- Run the command javac -version. This should show the javac version number. Verify that this version number is same as the latest JDK version (from JDK folder name). You can also run the command where javac. This command should show the JDK bin folder location. This should be the same folder location that you had set in the Path variable
**Android Studio installation and setup:**
#### Prerequisites to installing Android SDK tools
Before you download and install Android, make sure that you complete the below given prerequisites –
-
- You should have downloaded and installed Java (JDK) and set up Java environment variables
Follow the steps given below to download Android Studio –
- Open Android Studio download link – https://developer.android.com/studio/index.html. You will see Download Android Studio Electric Eel button as shown below
- Click on the Download Android Studio Electric Eel button. You will see the Terms and Conditions popup
Important Note: Please make sure that you always install the latest version of Android Studio and SDK tools. With the older versions, there has been a change in the way you open SDK Manager and some other tools. And this might result in some confusion in the way you use these tools
- Scroll down to the bottom, then select the checkbox and click on Download Android Studio Electric Eel button. The download process would now begin. Click on Save File to download the .exe file to your machine
This completes our Android Studio download process. Let us now install Android Studio and the SDK tools.
Follow the below steps to install Android Studio and other SDK tools –
-
Double click on the downloaded exe file. Android Studio Setup Welcome Screen would be displayed, as shown below (sometimes it might take a minute or so for the below screen to load when you try it the first time)
-
- Click on the Next button. You will see the Choose Components screen. On this screen, let both check boxes remain selected. You would observe that Android SDK (which you need for Appium Scripts) is not displayed here. But once you install Android Studio and open it for the first time then
![Android Studio Setup - Choose Components]
-
Click on the Next button. You will now be taken to the License Agreement screen
-
Click on I Agree on the License Agreement screen. You will now see the Configuration Settings screen. Let the default installation location remain the same.
- Click on the Next button. You will be taken to the Choose Start Menu Folder screen
- Click on the Install button to start the installation process.
- Once the installation is complete, you will see the Installation Complete window as shown below
![Android Studio Setup - Installation Complete]
- Click on the Next button. You will see Completing Android Studio Setup screen. Uncheck Start Android Studio checkbox and then click on Finish button to close the screen.
![Completing Android Studio Setup - Finish Installation]
Once your Android Studio is opened, go to Tools > SDK Manager (in older versions of Android Studio, this option was Tools > Android > SDK Manager)
If you don’t see SDK Manager option in Tools menu, then please wait for a couple of minutes. Android Studio takes some time to setup all the necessary components when you open it for the first time. After 2-3 minutes you would start seeing this Android option in the Tools menu
Once you select SDK Manager option, Settings screen would be opened with Android SDK option selected by default, as shown in the below image. Also, please note that there are 3 main tabs in this screen – SDK Platform, SDK Tools and SDK Update Sites. We will be checking only the first two tabs – SDK Platform and SDK Tools
![Default Settings - Android SDK option selected]
In SDK Platform tab, check that the latest version of Android is installed. Even if it shows Partially Available or Update available, then its ok for now
Click on OK button
In the first step we will try to find the folder path where we have installed Android SDK –
- The default folder location where Android SDK is installed is – C:\Users\Anish\AppData\Local\Android\sdk. Please open this folder path and see if you have Android SDK folder in there with contents as shown below
Please note that if you try to open this folder location by going to each folder one by one (i.e. C > Users > YourUserName and so on…), then you might not see the App Data folder as it's a hidden folder. So, you will have to make hidden folders visible first
- Copy the SDK folder location once you find it. For us, this folder location is – C:\Users\Anish\AppData\Local\Android\sdk
Follow the steps given below to setup ANDROID_HOME environment variable –
- Click on the Start menu. Then right click on Computer and select Properties option
- This would open the System Properties window as shown below. Now from the Advanced Tab, click on Environment Variables button
- From the Environment Variables window, click on New button from
System variables section
- Enter ANDROID_HOME in Variable Name field and SDK folder location (C:\Users\Anish\AppData\Local\Android\sdk) in Variable value field as shown in below image (Please enter the correct folder location that you have in your machine)
- Click on the OK button. ANDROID_HOME variable will now be added to System variables
With this, we have successfully added ANDROID_HOME variable. Let us see how to add the Path variable.
# Folder locations to be added to Path variable
In the Android SDK folder, there are three specific folders that you need to add to the Path variable. These folders are –
-
- platforms-tools folder which has path –
-
- tools folder which has path –
Since we have already added ANDROID_HOME in System variables and it's represented by – C:\Users\Anish\AppData\Local\Android\sdk, hence all these above three folder locations can be written as –
-
- %ANDROID_HOME%\tools
Let us now add all these three folder locations in Path variable.
Follow the steps given below to setup Path variable –
- In the Environment variables window, check that there is a variable called Path under System variables
- Select the Path variable and click on Edit button. Path variable window would be opened
- Move over to the end in the Variable value text field. Put a semicolon (;) at the end and start adding all the 3 folder paths separated by semicolon (Semicolon acts as a delimiter between different folder locations added in the Path variable). You should have added all the 3 folder locations as this
%ANDROID_HOME%\tools\bin
- Click on the OK button. All the three variables would now be added to the Path variables.
- Close the Environment variable window by clicking on the Ok button. With this, we have now successfully setup Path variable as well
To verify that all the Android Environment Variables are correctly setup, open command prompt and run this command: sdkmanager – -list (please note that there should be no space between the 2 hyphens, as shown in the below image). This would list down all the installed and available packages which would look a bit like something as shown below (please wait for 3-5 seconds for the list to be displayed)
# Appium tool setup
This mainly involves downloading and installing Appium Desktop, setting up an Appium project IntelliJ, adding all the Appium related dependencies and setting up your mobile device for test automation.
Follow the steps given below to download Node.js – Step 1) Open Node.js website using this link – https://nodejs.org/en Step 2) Click on the LTS button. This is the latest, most stable and supported version of Node.js
Step 3) Node.js will be downloaded to your machine
Step 1) Open the .msi file that you downloaded in the previous step to start the installation process
Step 2) Click on Next button, accept the License Agreement, leave the default values Destination Folder and Custom Setup screens
Step 3) Leave the checkbox unchecked in Tools for Native Modules screen and click on Next button Step 4) Click on Install button to start the installation
Step 5) Click on Finish button to exit the setup wizard
The npm comes preinstalled with Node.js. So, to verify that both Node.js and npm have been setup correctly, open command prompt and run these commands: node -v and npm -v
# Eclipse IDE – Download and Install
Perform the steps given below to download the latest version of Eclipse IDE
- Open this link – https://www.eclipse.org/downloads/packages/
- This link lists the latest Eclipse IDE versions for different programming languages. We are interested in Eclipse IDE for Enterprise Java and Web Developers
-
Once you click on the link, you will be navigated to the download page as shown below. Click on the Download button to start the download process.
-
Eclipse IDE would start downloading.
-
With this, we complete the process of downloading Eclipse IDE for Java. Let’s now have a look at how to set it up.
### Install/Setup Eclipse IDE
Unlike a lot of software tools, Eclipse doesn’t need to be installed. Once
you unzip it, you can start using it directly. Let us see how this is done –
- Go to the folder where you had downloaded Eclipse and locate the Eclipse zip file
- Right click on the Zip file and unzip it.
-
- After unzipping the zip file, you will get eclipse folder. Open this eclipse folder, it would have contents similar to what is shown in the below image
-
Double click on eclipse.exe file to open the IDE. Once it starts, it would ask you to select a workspace directory. In eclipse, workspace is the directory where all your projects would be saved.
-
Leave the default folder path as it is and click on the Launch button. Eclipse would open the IDE and you would see the Welcome tab as shown below
# Enable USB Debugging on Android Phone
Enabling USB Debugging on your android device is a two-step process:
- Firstly, get the Developer options on your phone
- Then, use Developer options to enable USB Debugging Let's look at each of these steps in more detail.
Step 1: Take your Android device -> go to Menu/Home -> search for the Icon named “Settings”
Step 2: Click on the “Settings” Icon and scroll down and check for an option named “Developer options”. If you can see “Developer options” listed there, it means Developer options is already enabled on your Android device.
On the other hand, if you do not find the “Developer options” listed there, then please follow the below procedure to enable it – Step 3: Click on the “About phone” option, you can see the list of options as shown in the below image
Step 4: Click the “Build Number” option multiple times, till one of these messages appear –
After this, click on “Build Number” couple of more times until you finally see the below message –
(To be precise – It is 5 clicks on some devices and 7 clicks on others)
Step 5: Tap the back button on your device to verify the “Developer options” is listed under the settings
So now you can see the “Developer options” enabled on your device. Let us now see how to enable the USB debugging option on your android device.
Enable USB Debugging option on your phone By default, the USB debugging mode is disabled for any brand-new device to avoid unintentional modifications on it. But you would need to enable debugging option manually for your Android development/testing process.
So now, let's see how to enable the USB debugging mode by following the steps given below: Step 1: Go to the “Settings” option of your phone and verify again, if you can see the “Developer options” listed under the “Settings” section as shown below
Step 2: Click the “Developer options” and check if “USB Debugging” checkbox is listed under the sub-title “Debugging” as shown below:
Step 3: Tick the “USB Debugging” checkbox and click “OK” in the popup message. You can see that “USB Debugging” has been enabled now as shown in the below image:
# Appium Desktop – Download and Install
Follow the steps given below to download the latest version of Appium Desktop –
- Open Appium Desktop’s GitHub page – https://github.com/appium/appium-desktop/releases
- This page lists all the versions of Appium Desktop. You will have to download the latest version which is shown at the top of the page. Please Note: New beta versions are released often. Even if you see a newer version on Github, please go ahead and download that version.
-
In the Downloads section of the latest release, you will find different packages for Windows, Mac, Linux etc
-
Click on the windows version to download and save it on your machine With this, we complete the download process for Appium Server GUI. Let us now install it on our machine.
### Install Appium Desktop (Appium Server GUI)
Use the steps given below to install Appium Server GUI on your machine
- Open the folder location where you have downloaded Appium Server GUI and double click on the exe to start the installation process
- Appium will first ask you Installation Options. Leave the already selected option as it is and then click on Install button
- Once the installation process starts, you will see the Appium Setup window as displayed below
- Once installation is complete, you will see the below Appium Setup window
Appium server requires a minimum of 2 parameters to run – Host and Port. The default values for these parameters are “0.0.0.0” (for Host) and “4723” (for Port). So, if you don’t provide any specific values for these parameters, Appium would take the default ones to start the server.
-
To verify that the installation and setup is successful, click on the start Server button. This would start the Appium server, and you would see ‘The server is running’ message in Appium window
This shows that the Appium Desktop has been installed successfully.
- Click on Stop Server button (3rd button with pause icon) to stop the Appium server and then Close Log button (one with X icon) to close the Appium server, you can close the Appium Server GUI window.
# Appium Inspector – Download and Install
#### Download Appium Inspector
Follow the steps given below to download the latest version of Appium Desktop Inspector –
1. Click on this link to open [Appium Inspector Github Releases page](https://github.com/appium/appium-inspector/releases)On this GitHub page, you will be able to see the latest release details
With this, we complete the download process for Appium Inspector. Let us now install it on our machine.
**Install Appium Inspector**
Follow the steps given below to install this tool on your machine –
- Open the folder location where you have downloaded the inspector tool and double click on the exe to start the installation process
- Appium will first ask you Installation Options. Leave the already selected option as it is and then click on Install button
- Once the installation process starts, you will see the Appium Setup window as displayed below
-
When the installation is completed, you will see the installation completed screen as shown below
-
Now, leave the Run Appium Inspector option checked and then click on the Finish button. Appium GUI window would look like this
Inspecting your mobile app and starting to identify elements is a multi- step process. You would need to do the following tasks to get rolling –
-
- Start Appium Server
- Open Appium Inspector and provide Desired Capabilities of your mobile device and app
- Start New Session (i.e., Start Appium Inspector)
- Inspect elements on your mobile app
- Start Appium Server
Click on the start Server button. This would start the Appium server, and you would see ‘The server is running’ message in Appium window
- Go to Windows -> Start, search for Appium Inspector and then open it
-
Appium Inspector start screen would be opened as shown in the below image
-
You would notice that Remote Host is already defaulted to 127.0.0.1, and Remote Port is also set to 4723 by default. Remote Path also has / as the default greyed out value.
-
# Get your Mobile Phone’s Device ID
-
Connect your mobile device to your computer using a USB cable. (If your mobile device shows a popup to allow debugging, then accept that popup)
-
Now open command prompt and run this command: adb devices
-
Once you run this command, you will see the details of the device as shown in the below image (if you see some other response such as “daemon not running. daemon started successfully”, then run the command again)
**Ways to find appPackage and appActivity name of your App**
in Command Prompt Step 1: Unlock your mobile device and connect it to your computer using USB cable Step 2: Open Command Prompt and run ‘adb devices’ command. We are running this command to just make sure that your mobile is properly connected. Step 3: Once you run ‘adb devices’ command, you should see that it displays the list of attached devices as shown in the below image (the actual device name that you see would be different based on what mobile phone you use) –
Step 4: Run ‘adb shell’ command. After running this command, the command prompt should look something like this –
Step 5: Now on your mobile phone, open the app for which you want to find the appPackage and appActivity. Step 6:* Now run this command: dumpsyswindowdisplays|grep-E ‘mCurrentFocus’
Step 7: The above command would display the details of the app which is currently in focus. From that, you can figure out the appPackage and appActivity name as per the below image –
appPackage starts with com. and ends before backslash (/). So, from the above image, appPackage name is – com.android.vending
appActivity starts after the backslash (/) and goes till the end. From the above image, appActivity name is – com.android.vending.AssetBrowserActivity
Step 8: There is one more similar command that provides the appPackage and appActivity name. This command adds some additional details before and after the package name & activity name, but you can still try it out just to verify that the results from the above command are the same. This command is – dumpsys window displays | grep -E ‘mFocusedApp’ and the output of this command is shown below –
In this example, where we used mFocusedApp, appActivity name is shown as a relative name, i.e., it doesn’t start with com. In such cases, you would need to add com…. at the beginning to get the complete activity name. So,
in our case, complete activity name for .AssetBrowserActivity would be com.android.vending.AssetBrowserActivity
### Provide Appium Inspector Desired Capabilities
Once you have added Appium Server details, the next step is to add the Desired Capabilities. Desired Capabilities are keys and values encoded in a JSON object and are sent by Appium Inspector to the server when you request a new automation session.
Note: If someone is working on the same project then they can use these capabilities, they just need to copy and paste the capabilities under JSON representation and save it. Here, Android version and Device name, you have to give based on your testing devices.
{
"platformName": "android", "appium:platformVersion": 12, "appium:deviceName": "RZ8N810NC1K", "appium:appPackage": "org.sunbird.app.staging", "appium:appActivity": "org.sunbird.app.MainActivity"
}
For the new project, they have to follow the below steps to add the capabilities to Appium Inspector You will have to add each of these capabilities to Appium Inspector. Follow the steps given below to do this –
- To add the first capability, type ‘udid’ in Name field and ‘ENUL630010’
- in Value field. Your screen would now look like this (note that the JSON Representation block would automatically show the capability that you have added just now)
[Add new blank row by clicking on plus button]
- Add the second capability (appium:appPackage) in this row
- Keep on adding new rows till you add all the capabilities and your screen should now look like this
You have now successfully added all the Desired Capabilities. Let us now save this Capability Set and then start the Appium Desktop Inspector.
It’s a good approach to save the Desired Capabilities set especially when you are using multiple devices or testing multiple apps. This is because once you save a Desired Capability set, then you can directly select it from the Saved Capabilities Set section and start the inspector. So, if you use multiple devices or android versions, you can save these capabilities as say ‘Samsung Galaxy S7’, ‘Nexus 6P’, ‘Calculator App’ etc.
Let’s quickly see the steps that you must follow to save the Desired
Capabilities –
- At the bottom of the screen, where you entered all the Desired
Capabilities, click on ‘Save As…’ button
- Enter any name you wish to use and click on the Save button. The capability set would get saved
- Click on Saved Capabilities Sets tab and then click on edit icon. You will see that the capability set you saved just now is displayed here
### Start Appium Inspector
First, make sure that your mobile device is connected to your machine. Also see that it's unlocked. To start Appium Desktop Inspector, click on the Start Session button.
Once you click on the button, you will see that the screen starts getting refreshed. Then after a few moments, Appium window would display the
screenshot of app together with its Object Hierarchy Dump. The Appium window screen would like this –
Steps to follow to launch App on real device:
- Open IntelliJ in your system
- Connect mobile device with your laptop via USB
- Appium test script should be added into IntelliJ
- Run your test script and check that it launches the app
-
Open the IntelliJ
-
Select the Test folder under src(expand it)
-
Select ‘UserOnboardingSaniy’ component and double click
[Note: Here you can select one test script, otherwise you can run all scripts of sanity component at once] Here, we will see how to run all scripts of Sanity component:
Click on ‘Suiteinventory’ and expand it and then click on ‘Smoke_test.xml’ Once you open the Smoke_test.xml file, you scroll to the bottom and give this class name < class name="com.qualitrrix.test.UserOnBoardingSanity"t; And then right click on the same screen and click on the Run option
[Note: You can give the same class name, where you have kept your script]
Your script would start running and you would see that app would get launched on your mobile device. This entire process might take 10-15 seconds because Appium must connect to your mobile device first.