Testing Black Box for Android Espresso

I am trying to test Black Box in a third-party apk file using Android Espresso. I do not have access to the source code of a third-party apk file.

So, I can get the identifiers of the interface elements with UIAutomatorViewer. However, in the Espresso file I do not have access to "R".

So when I call onView(withId(R.id.<ui id>)), it returns an error:

package R does not exist

Example:

onView(withId(R.id.fragment_onboarding_skip_button)).perform(click());
+4
source share
1 answer

It can be solved by creating a method for extracting an integer identifier from an ID name:

...    
public int getId(String id) {
    Context appContext = InstrumentationRegistry.getTargetContext();
    return appContext.getResources().getIdentifier(id, "id", "<applicationId>");
}

@Test
public void testSomething() {
    //here just pass the ID name
    onView(withId(getId("fragment_onboarding_skip_button"))).perform(click());
}
...
+1
source

Source: https://habr.com/ru/post/1685381/


All Articles