How to write Appium script which works on Android/iOS/Windows platform

I have a mobile app which works on Android/iOS platform. Is it possible to write single script which should work on both platforms, if yes, what is the best practices.

Hi,

I’ve an app with iOS, Android & Web versions I’ve designed a single script for each - It may be best approach but somehow working fine in my case.

What you want to know about it ?

Naveed

Actually, it is possible.
Please let see us your solution or tell us about it :smile: .

Appium java client has PageFactory tools which are similar Selenium. Do you use it?

Yes It is possible that with out any changes in your scripts you can automate both platforms, but from my limited knowledge (I am kind of new to appium) the only way to do true Hybrid test scripts(best practice) is to reach the UI Elements via AccessibilityID.
So lets say you have a login form with ‘username input field’ & ‘password input field’ and a ‘login’ button.

In iOS you give accessibility ID to these elements and in Android you set contentDescription for these elements.
If you give the same unique string to accessibility ID and contentDescription than this means you can reach the same element in both platform with one script that searches via accessibility id of webdriver.
( self.driver.find_element_by_accessibility_id(‘Email Input Field’) )

Reference :

I have created a framework using page object. There are multiple object locator like ID, className, Xpath, UIAutomator, which attribute should I use to identify object so that same object property can be used to locate object in iOS as well as Android.

Any suggestion/best practices for creating cross platform scripts.

Some time ago I make the pull request to appium java client. [Read this][1].
[1]: https://github.com/appium/java-client/pull/68

@emirozer and @Buddha_Tree
What are you think about this?

2 Likes

Since 2.0.0 was released it is possible to use elements for specific platforms, e.g:

@AndroidFindBy(someStrategy)

//or

@FindBy(someStrategy)
AbdroidElement someElement;

or

@iOSFindBy(someStrategy)

//or

@FindBy(someStrategy)
IOSElement someElement;

3 Likes

I took a quick look at your pull request and i think your proposed idea is really good, I definitely like it!
I will look in detail and see if I can do the same for python client!
Again awesome work Sergey!