Element Locators with different environment


We are implementing an appium automation that should be ran on different environments having the same app/code. I am using @AndroidFindBy and pageFactory to locate my elements in Android. Now with the new issue we’re facing, the ID of an element will change with respect to the environment we are testing on: for example, in the staging environment the element’s ID will be similar to: “com.app.staging:firstName” while in the second environment, the element’s ID will be similar to “com.app.developer:firstName”. How can I achieve such dynamic implementation of element locators?

@AndroidFindBy does not support dynamic strings in the find by expression. Please feel free to share any idea regarding this topic under this post.

Thank you!

If change only in app package name then do not worry. Just set id without package name. Appium will add it.

Thank you @Aleksei , I did not think about such approach. What I have implemented for now is:

@AndroidFindBy(xpath = "//*[ends-with(@resource-id, 'id/firstName')]")

Do you recommend that I switch back to your answer, or are both fine to implement

@AndroidFindBy(id = "firstName")

is better way

1 Like