Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get View from Matcher<View>

How do I get the View from a Matcher?

I need to get the bitmap from a specific element which findbyview is not giving specifically but I could get it by specifying more matchers

like image 502
kdyz Avatar asked Sep 09 '18 09:09

kdyz


People also ask

How do I get espresso view?

the best way to do it is passing in an instance of one of the Views into the class's constructor. Check: Calling findViewById() from outside an activity. another way is getting view by context. Check android - How to get view from context?


Video Answer


1 Answers

Use the check method of ViewInteraction and implement a custom ViewAssertion

Example in Kotlin:

onView(TODO("ADD YOUR MATCHER")).check { view, noView ->
    // Get bitmap here
}

Example in Java:

onView(/* TODO("ADD YOUR MATCHER") */).check(new ViewAssertion() {
    @Override
    public void check(View view, NoMatchingViewException noViewFoundException) {
        // Get bitmap here
    }
});
like image 181
Mosius Avatar answered Sep 19 '22 15:09

Mosius