Basic refactoring to use PageObjects with Appium (using .NET)

What is PageObject model(POM) ?

POM is a technique to hide some of the details of interacting with Web & Mobile elements, so that writing tests and reading code is easier.

Here is a good starter resource for understanding POM for Appium –

POM in action – 

I want to use this blog post to show a before vs after comparison of using POM , thus highlighting the effectivness of it ( in terms of achieving code abstraction) and hence reducing the cognitive load on someone writing the test .

Before state –

I wrote couple of tests using NUnit to loginto the TradeMe Android app and confirm that the expected user name is being displayed (on successful logon).

Here are the guts of the test –

After state –

Key difference –

In the after state all the locator related code has been abstracted away into the Page Object class.

So, rather than saying

Find me this element and type some text in it ….

We are just calling a method that does that for us , with worrying about which locator/element to call

Imagine this being repeated for each element and it’s operation across your tests, makes for significant gains in terms of code readibility

How did I abstract the detail out ?

I did some background reading

here –>

and looked a some code samples here —>

All the element locator related info was moved to another class. Operations (e.g. entering text or getting text of an element) were exposed as methods by that class.

The above methods and elements were then consumed by the NUnit test

To Do/Debt –

  1. As you might have observed in one of the code snippets above,I have to still refactor the explicit wait related code . Need to do some research on how to do it 😉
  2.  For the same element, I am using  Interface “IWebElement” in the Page Object class vs “AppiumWebElement” in my original NUnit test . The reason I had to do it because using “AppiumWebElement” type in the Page Object class used to throw an exception when called from the test. I still have to figure out why !?










Leave a Reply