Skip to content

Sunbird-Ed/Sunbrid-Mobile-UI-Automation

Repository files navigation

APPIUM INSTALLATION DOCUMENT

(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.

  • Download Java Development Kit

Follow the steps given below to download the latest version of JDK –

  1. Open this link – https://www.oracle.com/java/technologies/downloads/
  2. Scroll down a bit and then select Java 17, and then Windows
  • image
  1. Click on .exe link

JDK should successfully download to your machine.

Install Java Development Kit (JDK)

Given below are the steps that you can follow to install the latest version of JDK on your machine –

  1. Navigate to the folder where you had downloaded JDK. Double click on the exe file to start the installation process

image

  1. The installation process would now begin. Click on Next button on the Setup screen

image

  1. 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

image

  1. JDK installation would now begin
  2. Once the installation is completed, you will see the window as shown in the screenshot below. Click on Close button to close the window

image

  1. 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.

image

Setup Java Environment Variables

  1. 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

image

  1. 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

image

  1. This would open the System Properties window as shown below. Now from the Advanced Tab, click on Environment Variables button

image

From the Environment Variables window, click on New button from

System variables section

![Add new value (JAVA_HOME) in System Variables]

image

  1. 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

image

  1. Click on the OK button. You will see that JAVA_HOME variable has now been added in System Variables.

image

If you already have JAVA_HOME previously set, then you can click on Edit button to modify its value.

Setup Path variable

Path variable refers to the location of the bin folder inside the JDK folder.

Let’s see the steps to do this –

  1. Open your latest JDK folder and check that it has bin folder in it image

  2. Now open this bin folder and copy the entire folder location. For us, this folder location is – C:\Program Files\Java\jdk-17\bin

image

  1. 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

  2. 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

image

  1. Select the Path variable and click on the Edit button. Edit environment variable window would be opened
  2. 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]

image

  1. Click on the Ok button. bin folder location is now added in the Path variable
  2. Close the Environment variable window by clicking on the Ok button. With this, we have now successfully setup Path variable as well

Verify that JAVA_HOME and Path variables are set correctly

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 –

  1. Open command prompt
  2. 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

image

              **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 –

Download Android Studio Bundle

Follow the steps given below to download Android Studio –

  1. Open Android Studio download link – https://developer.android.com/studio/index.html. You will see Download Android Studio Electric Eel button as shown below

image

  1. Click on the Download Android Studio Electric Eel button. You will see the Terms and Conditions popup image
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
  1. 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

image

  1. Android Studio will be downloaded to your machine

  2. image

This completes our Android Studio download process. Let us now install Android Studio and the SDK tools.

Install Android Studio and SDK tools

Follow the below steps to install Android Studio and other SDK tools –

  1. 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)

  2. image

    1. 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]

image

  1. Click on the Next button. You will now be taken to the License Agreement screen

  2. image

  3. 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.

image

  1. Click on the Next button. You will be taken to the Choose Start Menu Folder screen image
  2. Click on the Install button to start the installation process.

image

  1. Once the installation is complete, you will see the Installation Complete window as shown below

![Android Studio Setup - Installation Complete]

image

  1. 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.

image

![Completing Android Studio Setup - Finish Installation] image

Select the latest Android version under SDK Manager

Once your Android Studio is opened, go to Tools > SDK Manager (in older versions of Android Studio, this option was Tools > Android > SDK Manager)

image

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

image

Click on OK button

Setup Android Environment Variables

Find the folder location where you installed Android SDK

In the first step we will try to find the folder path where we have installed Android SDK –

  1. 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

image

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
  1. Copy the SDK folder location once you find it. For us, this folder location is – C:\Users\Anish\AppData\Local\Android\sdk

Setup Android Environment Variables

Follow the steps given below to setup ANDROID_HOME environment variable –

  1. Click on the Start menu. Then right click on Computer and select Properties option

image

  1. This would open the System Properties window as shown below. Now from the Advanced Tab, click on Environment Variables button

image

  1. From the Environment Variables window, click on New button from

System variables section

image

  1. 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)

image

  1. Click on the OK button. ANDROID_HOME variable will now be added to System variables

image

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 –
C:\Users\Anish\AppData\Local\Android\sdk\platform-tools
    • tools folder which has path –
C:\Users\Anish\AppData\Local\Android\sdk\tools
    • bin folder inside tools folder with path –
    • image
![Folders to be added to Path variable]

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%\platform-tools
    • %ANDROID_HOME%\tools
%ANDROID_HOME%\tools\bin

Let us now add all these three folder locations in Path variable.

Setup Path Variable

Follow the steps given below to setup Path variable –

  1. In the Environment variables window, check that there is a variable called Path under System variables

image

  1. Select the Path variable and click on Edit button. Path variable window would be opened
  2. 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%\platform-tools; %ANDROID_HOME%\tools

%ANDROID_HOME%\tools\bin

image

  1. Click on the OK button. All the three variables would now be added to the Path variables.
  2. Close the Environment variable window by clicking on the Ok button. With this, we have now successfully setup Path variable as well

Verify that Android Environment Variables have been set correctly

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)

image

                        # 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.

Download and Install – Node.js and NPM

Steps to Download Node.js

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

image

Step 3) Node.js will be downloaded to your machine image

Steps to Install Node.js

Step 1) Open the .msi file that you downloaded in the previous step to start the installation process image

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

image

Step 5) Click on Finish button to exit the setup wizard image

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 image

            # Eclipse IDE – Download and Install

Download Eclipse IDE

Perform the steps given below to download the latest version of Eclipse IDE

  1. Open this link – https://www.eclipse.org/downloads/packages/
  2. This link lists the latest Eclipse IDE versions for different programming languages. We are interested in Eclipse IDE for Enterprise Java and Web Developers image

image

  1. 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.

  2. image

  3. Eclipse IDE would start downloading.

  4. 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 –

  1. Go to the folder where you had downloaded Eclipse and locate the Eclipse zip file
  2. Right click on the Zip file and unzip it.
    1. 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

image

  1. 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.

  2. 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

image

                 # Enable USB Debugging on Android Phone

Enabling USB Debugging on your android device is a two-step process:

  1. Firstly, get the Developer options on your phone
  2. Then, use Developer options to enable USB Debugging Let's look at each of these steps in more detail.

Get the Developer Options on your phone

Step 1: Take your Android device -> go to Menu/Home -> search for the Icon named “Settings” image

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. image

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 image

Step 4: Click the “Build Number” option multiple times, till one of these messages appear –

“You are now 1 step away from being a developer”

image

After this, click on “Build Number” couple of more times until you finally see the below message –

“You are a Developer now” or “Developer mode has been enabled”

(To be precise – It is 5 clicks on some devices and 7 clicks on others)

image 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

image

Step 2: Click the “Developer options” and check if “USB Debugging” checkbox is listed under the sub-title “Debugging” as shown below: image

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:

image

            # Appium Desktop – Download and Install

Download Appium Desktop

Follow the steps given below to download the latest version of Appium Desktop –

  1. Open Appium Desktop’s GitHub page – https://github.com/appium/appium-desktop/releases
  2. 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.

image

  1. In the Downloads section of the latest release, you will find different packages for Windows, Mac, Linux etc image

  2. Click on the windows version to download and save it on your machine image 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

  1. Open the folder location where you have downloaded Appium Server GUI and double click on the exe to start the installation process
  2. Appium will first ask you Installation Options. Leave the already selected option as it is and then click on Install button

image

  1. Once the installation process starts, you will see the Appium Setup window as displayed below image
  2. Once installation is complete, you will see the below Appium Setup window

image

  1. Now, leave the Run Appium Server GUI checkbox selected and click on image

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.

  1. 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

  2. image

This shows that the Appium Desktop has been installed successfully.

  1. 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.

image

        # 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

image

  1. Under Assets section, click on windows exe file to download and save it on your machine image

With this, we complete the download process for Appium Inspector. Let us now install it on our machine. image

                **Install Appium Inspector**

Follow the steps given below to install this tool on your machine –

  1. Open the folder location where you have downloaded the inspector tool and double click on the exe to start the installation process
  2. Appium will first ask you Installation Options. Leave the already selected option as it is and then click on Install button

image

  1. Once the installation process starts, you will see the Appium Setup window as displayed below

image

  1. When the installation is completed, you will see the installation completed screen as shown below image

  2. Now, leave the Run Appium Inspector option checked and then click on the Finish button. Appium GUI window would look like this

image

Appium Inspector Steps to get started

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 image

Open Appium Inspector and provide server details

  1. Go to Windows -> Start, search for Appium Inspector and then open it

image

  1. Appium Inspector start screen would be opened as shown in the below image image

  2. 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.

  3. image

         # Get your Mobile Phone’s Device ID
    
  4. 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)

  5. Now open command prompt and run this command: adb devices

  6. 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) image

           **Ways to find appPackage and appActivity name of your App**
    

Method 1: Using ‘mCurrentFocus’ or ‘mFocusedApp’

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) – image

Step 4: Run ‘adb shell’ command. After running this command, the command prompt should look something like this – image

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 –

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 –

image

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 –

  1. To add the first capability, type ‘udid’ in Name field and ‘ENUL630010’
  2. 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)

image

[Add new blank row by clicking on plus button] image

  1. Add the second capability (appium:appPackage) in this row
  2. Keep on adding new rows till you add all the capabilities and your screen should now look like this

image You have now successfully added all the Desired Capabilities. Let us now save this Capability Set and then start the Appium Desktop Inspector.

Save the Desired Capabilities Set

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 –

  1. At the bottom of the screen, where you entered all the Desired

Capabilities, click on ‘Save As…’ button

image

  1. Enter any name you wish to use and click on the Save button. The capability set would get saved
  2. 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

image

             ### 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 –

image

Appium Test Script to Launch App on Real Device

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
  1. Open the IntelliJ

  2. Select the Test folder under src(expand it)

  3. image

    1. Expand the ‘test’ and then again expand the ‘com.qualitrix.com’ image
  4. Select ‘UserOnboardingSaniy’ component and double click

image [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.xmlimage 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

image

[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.

      ******  Key Observations ***********
  • To set mobile configuration details to the framework follow the below steps

      * Go to Caps folder, open capabilities.Json file
      * Update the below details as per the connected device
    

    "devices":[ { "name": "RZCRC00YG9R",

    "version": "13.0.0",

    "Platform": "Android" }

  • To set APK Path follow the below steps

    * Add the APK file to the caps folder
    * Go to Caps folder, open capabilities.Json file
    * Give the path as shown below
    
           app: ".\\caps\\SUNBIRD_6_0_544staging.apk",
    
  • To set appPackage and appActivity follow the below steps

    • Go to Caps folder, open capabilities.Json file

    • Update the below details as per the APK file

      "Capabilities": {

      "android": {
      
      "appPackage": "org.sunbird.app.staging",
      "appActivity": "org.sunbird.app.MainActivity",
      
  • To change the Execution Environment follow the below steps

     * Go to the Configs folder, open the config.properties file
     * Enable the appPackage and appActivity as per the environment apk
    
               appPackage=org.sunbird.app.staging
               appActivity=org.sunbird.app.MainActivity
    
  • To change the TestData path as per the Environment follow the below steps

    • Go to the Configs folder, open the config.properties file

    • Enable the excelpath variable as per the environment

      excelpath=./testdata/StagTestData.xlsx
      
    • To change the suite execution follow the below steps

       * Open TestNg.XMl in suite inventory
       * Give packagename.className
      <class name="sanitySuite.Sanity"/>
      
  • To Trigger the TestNG.xml follow the below steps

      * Open any TestNG.xml file
      *  Right-click and click on Run as "TestNG.xml"
    
  • Check the Extent report after the execution in the below path

      * In the Framework root directory, Open the Report folder
      * .Html file will be created 
    

About

Sunbird mobile app UI automation test cases

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages