What's the best way to reference resource IDs in UIAutomator tests?

I recently started using UIautomator to test my Android apps.

The following code snippet shows a typical statement in test case code:

mDevice.findObject(By.res(BASIC_SAMPLE_PACKAGE, "editTextUserInput"))
                .setText(STRING_TO_BE_TYPED);

      

As you can see, "editTExtUserInput" is referenced as a string. In the source code of my applications, this is defined as the resource identifier (R.id.editTextUserInput).

In the current situation, when I change the ID name in my application, all my test cases will be messed up (I will have to manually change all the string values). Does anyone have a solution for this question?

+3


source to share


1 answer


Most of the Google Android Testing team spends time building Espresso , a new UI testing framework that specifically simplifies these cases. For example, the string could be

onView(withId(R.id.editTextUserInput)).typeText(STRING_TO_BE_TYPED);

      



And things like ID autocomplete and refactoring will affect those tests as well.

-1


source







All Articles