Site Loader
Auckland, New Zealand
In this post we will discuss how to create and work with Page Object Model (POM) in Appium. We have already discuss page POM in greater detail while discussion Selenium framework design and development articles and videos, hence we will change our gears here to focus directly on the coding part of Page Object Model in appium rather talking about its theories. Here is the complete code for Page Object Model (POM) in appium Code for Page
public class CalcAppPage {

	public CalcAppPage(AppiumDriver driver) {
		PageFactory.initElements(new AppiumFieldDecorator(driver), this);

	@AndroidFindBy(id = "edtno1")
	public WebElement txtNum1;

	@AndroidFindBy(id = "edtno2")
	public WebElement txtNum2;

	@AndroidFindBy(id = "txtResult")
	public WebElement txtResult;

	public void Add(String num1, String num2) {

	public boolean VerifyResult(String result) {
		if (txtResult.getText().equals(result))
			return true;
			return false;


Code for Test 
	public void SimpleTest() {

		CalcAppPage calPage = new CalcAppPage(driver);

		calPage.Add("20", "30");

		if (calPage.VerifyResult("50"))
			System.out.println("PASSED Test");
			System.out.println("FAILED Test");

Here is the complete video of the above discussion Thanks for reading the post and watching the video !!! Please leave your comments and let me know if there is anything I should update in this post. Thanks, Karthik KK

Post Author: Karthik kk

9 Replies to “Page Object model with Appium”

  1. Nice and very helpful tutorials… Please add some more videos for automation selenium code on Android and iOS native apps using appium together.

    Thanks a lot Karthik…

  2. Very Helpful. Thanks a lot. Can you please share some more videos considering complex android native / hybrid applications.

  3. Thank you, POM seems an interesting framework.
    Too bad we can’t use variables in AndroidFindBy with xpath to have dynamics object.
    Like getting the x textfield, or to get the textfield with the text “xxx”. Constants only are allowed.

  4. Hi,
    I have implement POM with Appium in java. My code structure follows as below :
    page object classes : LoginPageObjectRepo() and HomePageObjectRepo()
    testng classes : RegisterAndLoginTCs() and HomePageTCs()

    RegisterAndLoginTCs() :
    public void setup() throws Exception{
    //initial setup and capabilities

    public void stopServer() throws IOException{

    public void TC1_login() throws Exception{
    LoginPageObjectRepo objDriver = new LoginPageObjectRepo(driver);
    WebDriverWait wait = new WebDriverWait(driver,300);
    By.xpath(“//*[@text=’Login successful’]”))));“User log in successfull”);

    }catch(Exception e){
    log.error(“User log in failed”);

    //other many test methods

    HomePageTCs :
    AndroidDriver driver;
    public void TC5_HomePageFormat() throws Exception{
    HomePageObjectRepo objdriver = new HomePageObjectRepo(driver);


    Now when i run this project i get nullpointer exception at HomePageTCs.TC5_HomePageFormat( ie. at line objdriver.SearchOption().click();

    I feel it is because driver is defined in RegisterAndLoginTCs class.
    How can i get access to same driver which is defined in setup() method so that once driver is defined with required capabilities, it can be used across multiple testng classes.

Leave a Reply

Your email address will not be published. Required fields are marked *