Created
November 6, 2018 16:08
-
-
Save RankoR/36b3c3b8972224de55704d31f41b2097 to your computer and use it in GitHub Desktop.
Extend Espresso to make Snackbar testing easier. Note: this code works only for AndroidX.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import androidx.annotation.StringRes | |
import androidx.test.espresso.Espresso.onView | |
import androidx.test.espresso.ViewInteraction | |
import androidx.test.espresso.matcher.ViewMatchers | |
import org.hamcrest.CoreMatchers | |
import org.hamcrest.CoreMatchers.allOf | |
fun onSnackbar(@StringRes withText: Int): ViewInteraction { | |
return onView( | |
CoreMatchers.allOf( | |
ViewMatchers.withId(com.google.android.material.R.id.snackbar_text), | |
ViewMatchers.withText(withText) | |
) | |
) | |
} | |
fun onSnackbarButton(@StringRes withText: Int): ViewInteraction { | |
return onView( | |
allOf( | |
ViewMatchers.withId(com.google.android.material.R.id.snackbar_action), | |
ViewMatchers.withText(withText) | |
) | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment