Since appium supports different search strategies, which also vary slightly across platforms, I use the following approach in one of my projects:
I have a helper that can be easily imported into each class that returns cross-platform (iOS and Android) test id details
export function getTestIdProps (id) { return { accessible: true, accessibilityLabel: id, testID: id } }
During development, we make sure that each component under test receives test identifiers similar to the following:
return ( <ComponentToBeTested> <View {...getTestIdProps('unique-test-id-goes-here')} moreProps> </View> </ComponentToBeTested> )
Caution Be sure to check the response of native documents to see which base element supports these details. Not all responsive native elements support testID or accessibilityLabel . If they do not, these details will be ignored.
Finally, in your Appium test (Java example) you can easily identify an element by its accessibility identifier, for example:
public static By byAccessibilityId(final String id) { return MobileBy.AccessibilityId(id); }
For further reading, also see http://appium.io/docs/en/commands/element/find-elements/
source share