Usually it would be recommended to use resource IDs as the primary identifier for element location in Android automation tests. If resource IDs are not available or not unique, then other identifying attributes like element IDs, class names, text, and content descriptions can be used. Accessibility IDs can be a helpful addition, but they should be used as a fallback option and not relied on exclusively.
When it comes to adding Accessibility IDs to your app's UI elements, here are some guidelines that I would suggest:
Ensure that each Accessibility ID is unique and specific to the UI element it represents.
Use descriptive names for Accessibility IDs that clearly indicate the purpose or function of the element.
Avoid using special characters or spaces in the Accessibility ID, as this can cause issues with automated tests.
Use Accessibility IDs in combination with other identifying attributes to ensure the most stable and efficient element location.
For example, if you have a button that opens a menu, and the menu items do not have unique resource IDs, you can add unique Accessibility IDs to the menu items to make them easily locatable in automated tests. The Accessibility IDs can be something like "menu_item_1", "menu_item_2", etc.
While Accessibility IDs can be helpful in some cases, it's important to prioritize using resource IDs and other identifying attributes first for the most efficient and reliable element location in automated tests.