Which selector is the best for Appium to test different versions of devices?

249 views
Skip to first unread message

Gokhan Arik

unread,
Aug 15, 2014, 3:02:00 PM8/15/14
to appium-...@googlegroups.com

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.

I also asked this question at SO but didn't get any answer yet, any help would be appreciated. 

http://stackoverflow.com/questions/25317958/which-selector-is-the-best-for-appium-to-test-different-versions-of-devices

Thanks

Christian Hattinger

unread,
Aug 21, 2014, 5:39:04 AM8/21/14
to appium-...@googlegroups.com
Hi!

We test iOS and Android apps (more or less the same apps on both platforms) and the apps are available in different languages.

I prefer to use the resource ID (Android) and the accessibility ID on iOS since they are more stable than the xPath/ Class name (xPath causes troubles with Appium 1.2.1). Both IDs are accessible via Appium. Since we also test agains < API 18 on Android, I use the Selenium Driver for Android. 

I hope this helps,
Christian

Gokhan Arik

unread,
Aug 21, 2014, 12:11:32 PM8/21/14
to appium-...@googlegroups.com
I haven't tried Appium 1.2.1 yet, I will check it. 

I also use Selendroid but UIAutomator doesn't recognize resource ID's if it is API < 18. You have to set content description. Is it what you are doing?

Christian Hattinger

unread,
Aug 22, 2014, 9:45:36 AM8/22/14
to appium-...@googlegroups.com
Hi!

I "only" use the resource ID and no content description (I even don't know what it is, so I do not use it explicitly at least :)

Here is the the way I do it:
// setup
capa.setCapability("automationName", "Selendroid");
capa.setCapability("platformName", "Android");

// find one element 
WebElement elem = = driver.findElement(By.id("resourceID"));

// amount of elements with the same ID
int amount = driver.findElements(By.id("resourceID")).size();


This works for me at least with API 16, 17, 18 and 19 (but most probaly also with other, but I haven't tried yet)

I hope this helps
Christian
Reply all
Reply to author
Forward
0 new messages