Android Espresso Black Box Testing

567 views Asked by At

I'm trying to conduct Black Box testing on a 3rd party apk file using Android Espresso. I don't have access to the source code of the 3rd party apk file.

So, I'm able to get the UI element ids using UIAutomatorViewer. However, in the Espresso file, I don't have access to "R".

So when I'm calling onView(withId(R.id.<ui id>)), it's returning an error:

package R does not exist

Example:

onView(withId(R.id.fragment_onboarding_skip_button)).perform(click());
1

There are 1 answers

0
Anatolii On

It can be solved by creating a method extracting an integer ID from the 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());
}
...