Reputation: 2766
There are different ways to find element on a page (name, id, xpath, content-description, class name).
For devices with API > 18, id works well but if it is API < 18 you need to add content-description to your element. Finding element by name also looks good but not in my case.
I have never used xPath before and for now it looks like the best option.
I am writing an automation app that uses Appium and allows testers testing the application on multiple Android devices at the same time. Therefore I want to have a method that will work best with everything rather than writing different test classes/methods for each version.
Thanks
Upvotes: 1
Views: 1461
Reputation: 155
Please avoid using xPath as locator strategy. You will have to tinker with xPath time & again if the App is under Active Dev/Support cycle. Instead come up with locator strategy with Developers & explain the need & purpose of it
I'm attaching screenshot of UIAutomator screen with identifiers & the locator strategy that we followed in preferential order
Resource-id - Most of the time this Element remains Unique unless fiddled unnecessarily. This locator usually remains unique
Placeholder Text a.k.a text can also serve you well as locator strategy but again this should be agreed upon during Project kickstart. Its hard to maintain (code) different locator strategy for similar elements from different screen
Content-Desc
Combination of Class & Index can also serve you well if all the above strategy fails
I would suggest avoid Xpath & co-ordinates locator strategy as much as you can. Ultimately fails the test during the App life cycle
Its a completely different ball game if the App is cross platform & you need to have common locator strategy. For Ex:- Accessibility id (IOS) is not the same as Resource-id (Android)
Its better that the Accessibility id in IOS platform is mapped to one of the above locator strategy mentioned for Android platform. Again, this has to be agreed & planned well/pushed/agreed upon right during project kickstart or frustration can show up while you are at it :-)
Sample code from github which may be of some help!
Upvotes: 2