Before beginning with the next step towards learning Appium, do make sure that you have read my previous blog on Appium Setup in Windows. Only after you have made all the installations described in that blog, you can start running your test scripts without any hindrance.
My blog on Automating a Mobile Application using Appium, describes a very basic Login flow of a demo application.
The simple steps are as follows: User (the one who is already registered) selects the Country to which he belongs, enters his registered Mobile Number and his name, all on one screen after which the entered Mobile Number is validated. And after successful validation, user is re-directed to a screen where he is asked to enter his password.
Please Note: I have only discussed the happy flow here, i.e. using just valid values.
LOGIN PROCESS IN A DEMO APPLICATION USING APPIUM
Before beginning make sure Developer options as well as USB debugging mode is enabled for your android device.
There are some other set of things you need to do:-
1. Following list of parameters of the Android device as well as the application under test which will be needed in our test script should be noted down:
a) Device Name: Run command “adb devices” in command prompt. You’ll get the device name there.
b) OS Version: Android version of your device.
c) App Activity Name & Package Name: Download APK Info application in your Android device. The APK path section will give the package name (e.g. : com.example.android.contactmanager) and the launcher activity can be obtained from the Activities section here. (The very first one in the list!).
2. Start Appium Node Server. It takes some time for it to start. When you get this, consider it as started:
3. Locating application elements using UI Automator Viewer.
UI Automator Viewer (in the tools folder of SDK) helps us in locating elements in our application, so as to first identify them and perform some action on them subsequently. It gives certain properties of the application components, which we can be further used to create xpaths and can be used in our automation test scripts. (You will find “uiautomatorviewer.bat” file in tools folder of SDK).
In UI Automator Viewer tool, click on Device Screenshot image button while the application to be tested is open in your mobile device. This shows your application’s UI in UI Automator Viewer, as shown below.
The top right hand side part explains how elements are arranged. The bottom right hand side part shows the properties of the selected elements along with their values.
LOCATING ELEMENTS IN OUR DEMO APPLICATION:
a) As can be seen, the Submit button has a unique class -> “android.widget.Button” having index=8. So, the xpath for the Submit button would be:
b) Taking another example of the combo box that pops up on the click of the field which reads “SELECT THE COUNTRY YOU LIVE IN”:
Two things need to be considered here:
1. Clicking on the field itself, which opens a list of countries in turn:
Here the field has class “android.widget.TextView”, which is not a unique one (A few other elements have the same class). So in order to create a unique xpath I need some other property that makes this element unique. I can identify the element using the resource-id property. So, the xpath for the field will be:
2. Selecting one country from the list
Now, I wish to select country “India” from the list. In this case each country has a unique text attribute. So, we can uniquely identify this particular element just by the name (i.e. text= “India”)
Below is the code for launching the demo app and performing Login operation:
This launches the demo application on the android device, validates the entered Mobile Number (according to the country selected as well as length), enters the password in the next screen and on verifying the above sent data logs in the user successfully and exits from the app immediately.
Before running the above test script from Eclipse, you need to start Appium server first.
Please note that, the same process will be followed each time you are testing your application, whether it be performing an end-to-end test, or to just test a particular flow (say, Registration). The core lies in detecting the elements right and in a unique manner.
Apart from this, there are a whole lot of other things which can also be tested while automating an Android application, say picking an image from gallery/clicking an image from a custom camera, scrolling to a particular element, handling of alert dialogue, swipe vertical and horizontal, taking screenshot etc. This blog would help you take one step towards achieving it all and much more!
Thanks for reading. 🙂