简体   繁体   中英

Android Espresso Black Box Testing

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());

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());
}
...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM