Page Object model with Appium

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

Code for 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

7 comments

  1. Labha Bissa says:

    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. Sudheendran P L says:

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

  3. Jean says:

    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. sushma says:

    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() :
    @BeforeTest
    public void setup() throws Exception{
    //initial setup and capabilities
    }

    @AfterTest
    public void stopServer() throws IOException{
    //code
    }

    @Test
    public void TC1_login() throws Exception{
    LoginPageObjectRepo objDriver = new LoginPageObjectRepo(driver);
    objDriver.Login1().click();
    objDriver.Emaild().sendKeys(“[email protected]”);
    objDriver.Password().sendKeys(“abctesting”);
    objDriver.Login2().click();
    WebDriverWait wait = new WebDriverWait(driver,300);
    try{
    assertNotNull(wait.until(ExpectedConditions.presenceOfElementLocated(
    By.xpath(“//*[@text=’Login successful’]”))));
    log.info(“User log in successfull”);

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

    }
    wait.until(ExpectedConditions.presenceOfElementLocated(By.id(“com.ptmobile.catalogapp:id/ab_custom_search”)));
    }
    //other many test methods
    *************************************************************************************************

    HomePageTCs :
    AndroidDriver driver;
    @Test
    public void TC5_HomePageFormat() throws Exception{
    HomePageObjectRepo objdriver = new HomePageObjectRepo(driver);
    objdriver.SearchOption().click();
    }

    **********************************************************************************************

    Now when i run this project i get nullpointer exception at HomePageTCs.TC5_HomePageFormat(HomePageTCs.java:25) 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 *