Page Object Mode:- IOSElement & AndroidElement in same page

Hi Team,

I am going to start Mobile Automation project for a native app in iOS and Android. Client confirms that the screenflow for the application is the same in iOS and Android.

If that is the case, when using Selenium Page Factory to follow Page Object Model scripting pattern, can I keep the IOSElement and AndroidElement in the same page class

e.g)

@AndroidFindBy(id=”fab”)

@iOSXCUITFindBy(accessibility=”plus.circle”

MobileElement addButton;

I understand that this is possible.

What I really wanted to know that, is maintaining iOS & Android elements in the same class, so that the same code base can be used for the Automation, is advisable?

Or, should the team follow the approach in keeping seperate code repositories for iOS and Android ?

Kindly suggest

Hi, I can tell you that this is exactly what I do and it works great for me.
I am a single automation developer and this is easier to manage your code on a single repository.
moreover, you have the ability to annotate each field with different platform’s annotations android, iOS, windows so, if you separate the repositories won’t be any use of this feature… it is there for you to use.

Personally, I automate android and iOS app, they should be the same so the test logic is the same as well, if you will maintain two different repos you just have a lot of duplicate code!!! because the logic is the same so, all your 100 test cases (for example) will be just the same on the other repository (just with different instance names…)

What I do: I hold page objects and use appium Widget class, each page object/ Widget class I create I make it abstract and in each class I create an inner class (you can separate it to external classes but it will make it harder to maintain) so, I use two inner class which extends the page object/widget I am currently working on.
regarding the test classes I use one class per test since it has the same test logic for both platform and I do not extend each test with a platform specific name.
what I do is that I created a method which inits all page objects using java reflection API and for each page object it return a page object instace of the current platform.
For example:

let’s say I have a page object class named LogIn
inside this class I have two inner classes, one name Android and the other IOS (names should be fixed across all project for java reflection to work).
if you you have a method let’s say enterPassword() which has different implementation for each platform you can just override this method with the desired platform and when a class of this platfom will be made during execution it will use the override method.

then, from test class I just call login.enterPassword() and for each platform the same test logic will be interfered differently.

it is a bit messy, please ask more question if you want, of course it has some cons as well but the majority are pros. you can send me private message or ask for examples.

would recommend to read appium java-client Widget class docs here: https://github.com/appium/java-client/blob/master/docs/Page-objects.md

see the example with abstract classes

Thanks for the detailed information.

So as per your suggestion, it is ok to maintain same codebase for both iOS and Android if the screen structure and flow are the same.

I am having some more doubts. Will definitely get back to you. Once again thanks for your time.

We have project with 900+ tests for ios and android. Only benefits. One code. One logic.
Specially it helps when teams make features a bit different to find such issues. Minor logic difference hidden in page object. Larger difference in test classes.