Get access to View object during testing

49 Views Asked by At

I'm using Barista to test my Android app. At a certain point in my activity's lifecycle, a QR code is displayed on screen. I'm able to successfully test that the image appears on screen:

BaristaVisibilityAssertions.assertDisplayed(R.id.qrCode);

Is there a way to get access to the actual ImageView object? I want to inspect its Bitmap and verify that the QR code's contents are correct.

1

There are 1 best solutions below

0
Daniel Walker On BEST ANSWER

It suffices to get access to the activity object as, from there, you can call findViewById. Assuming you have a BaristaRule<MyActivity>:

public class MyActivityTest {
    @Rule
    public BaristaRule<MyActivity> baristaRule = BaristaRule.create(MyActivity.class);

    ...
}

you can get the activity by baristaRule.getActivityTestRule().getActivity().