Appium Mobile App Automation — Tutorial 2
Mobile application automation with Page Object Model
Introduction to Page Object Design Pattern
Page Object is a Design Pattern that has become popular in test automation for enhancing test maintenance and reducing code duplication.
A page object is an object-oriented class that serves as an interface to a page of your AUT. The tests then use the methods of this page object class whenever they need to interact with the UI of that page. The benefit is that if the UI changes for the page, the tests themselves don’t need to change, only the code within the page object needs to change. Subsequently, all changes to support that new UI are located in one place.
The Page Object Design Pattern provides the following advantages:
- There is a clean separation between test code and page-specific code such as locators (or their use if you’re using a UI Map) and layout.
- There is a single repository for the services or operations offered by the page rather than having these services scattered throughout the tests.
Getting Started with Page Object Model
1. Pre-requisites
To set up prerequisites for Android and Appium test automation, please click here.
2. Overview of the application
For this tutorial, we will be taking a simple login application developed for Android.
Note: If you are interested in Android development, Here is the source code for the application.
Functionalities of the application:
- Login will be successful with the username “Osanda” and password “MaxSoft123”.
- Once login is successful, the user will be navigated to the Home page. Then you will be able to see two labels to greet and welcome the logged-in user.
- If the user provides incorrect credentials and the login fails, the attempt counter is reduced by 1 for each attempt.
- After 5 unsuccessful attempts, Login button will be disabled.
3. Updating the pom.xml
There are 3 main dependencies we need to add to the pom.xml
- Appium Java Client
- Selenium-Java
- TestNG
4. Placing the APK file into your project
- Download this APK file which contains the login application.
- Move it to the “src/test/resources” directory.
5. Implementing the page classes
- Login Page
Here on the Login page, we need to have 4 locators for 4 web elements and action methods for those.
Locators:
- Username textbox
- Password textbox
- Login button
- Attempts counter label
Action Methods:
- Set username on the Username textbox
- Set a password on the Password textbox
- Click on the Login button
- Aggregated method for login function by using the above 3 actions
- Get text from the Attempts counter label
2. Home Page
Here on the Home page, we need to have 2 locators for 2 web elements and action methods for those.
Locators:
- Greeting label
- Welcome label
Action Methods:
- Get text from the Greeting label
- Get text from the Welcome label
6. Implementing a test class
7. Boilerplate project
https://github.com/osandadeshan/appium-java-mobile-automation-demo
References
Happy Automation !!!