-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathViewInteractionExtensions.kt
53 lines (50 loc) · 1.96 KB
/
ViewInteractionExtensions.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package com.tazkiyatech.utils.espresso
import android.view.View
import androidx.test.espresso.ViewInteraction
import androidx.test.espresso.assertion.ViewAssertions.matches
import org.hamcrest.Matcher
import org.hamcrest.Matchers.allOf
/**
* Checks that the view which is the subject of this [ViewInteraction]
* exists in the view hierarchy and is matched by all of the given view matchers.
*
* This function makes Espresso tests easier to read and write by combining a series of calls into one.
* It offers a nicer alternative to writing the following:
* ```
* onView(withId(R.id.someView)).check(matches(allOf(isDisplayed(), withText("Some text"))))
* ```
* Instead, you can write:
* ```
* onView(withId(R.id.someView)).checkMatches(isDisplayed(), withText("Some text"))
* ```
*
* @param matchers The array of [Matcher]s to match.
* @return This [ViewInteraction] for further perform or verification calls.
*/
fun ViewInteraction.checkMatches(vararg matchers: Matcher<View>): ViewInteraction {
return check(matches(allOf(*matchers)))
}
/**
* Waits up to [timeout] milliseconds for the view which is the subject of this [ViewInteraction]
* to match all of the given view matchers.
*
* This function makes Espresso tests easier to read and write by combining a series of calls into one.
* It offers a nicer alternative to writing the following:
* ```
* onView(withId(R.id.someView)).perform(waitForMatch(allOf(isDisplayed(), withText("Some text"))))
* ```
* Instead, you can write:
* ```
* onView(withId(R.id.someView)).waitForMatch(isDisplayed(), withText("Some text"))
* ```
*
* @param matchers The array of [Matcher]s to wait for.
* @param timeout The length of time in milliseconds to wait for.
* @return This [ViewInteraction] for further perform or verification calls.
*/
fun ViewInteraction.waitForMatch(
vararg matchers: Matcher<View>,
timeout: Long = 3000L
): ViewInteraction {
return perform(ViewActions.waitForMatch(allOf(*matchers), timeout))
}