Reliable answer Searching for an item using Appium

I use React Native to develop an application that requires end-to-end testing.

Based on the background of Selenium WebDriver, it seems to me that the element found in Appium can be very inconvenient compared to WebDriver, since native components have only ID and one non-user class.

  • Is there a way to add some metadata to elements so that they are easy to find?

Let's say if I have a table with complex elements inside a cell, and I need to first find the right row, then the cell, and then find the right components to control inside the cell.

Ideally, I would like to be able to list strings looking for something like "myTargetRows". This will give me a list of strings.

  1. If I understand correctly, neither of the two components can have the same identifier in their own applications, so I can not use the ID in this way, right? (For example, use the same identifier, "myTargetRows", for multiple row components).
  2. If not, should you use numbered identifiers such as "myTargetRow0", "myTargetRow1", etc., and then use XPath to partially match the ID?
  3. Is there a better way?
  4. If I can do something like this, can I just bind these findElement calls to find the desired nested elements that I want?

Ps: I don’t want to rigidly specify the exact hierarchies of components in my locators in order to avoid their invalidity if I move something around in my views, so these point-and-click solutions will not help.

Ps 2: Solutions should work on both Android and iOS, even if I need to implement some kind of abstraction for myself.

+7
source share
3 answers

You must use the accessibilityLabel details for presentation.

accessibilityLabel PropTypes.node

Overrides the text that the screen reader reads when the user interacts with the item. By default, the label is built to bypass all children and accumulate all Text nodes separated by a space.

More information can be found here.

For unique identifiers, let's say you have a listview and 100 rows. You can combine rowId and static text for accessibilityLabel .

e.g. 0_MyCustomRow, 1_MyCustomRow

0
source

Take a look at the Sauce Labs blog article , this is a good example of working with RN applications.

0
source

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/

0
source

All Articles