How to use RootMatchers class of android.support.test.espresso.matcher package

Best Appium-espresso-driver code snippet using android.support.test.espresso.matcher.RootMatchers

Builders.kt

Source:Builders.kt Github

copy

Full Screen

...5import android.support.annotation.StringRes6import android.support.test.espresso.Espresso7import android.support.test.espresso.Root8import android.support.test.espresso.ViewInteraction9import android.support.test.espresso.matcher.RootMatchers10import android.support.test.espresso.matcher.ViewMatchers11import android.support.test.espresso.web.model.Atom12import android.support.test.espresso.web.model.ElementReference13import android.support.test.espresso.web.sugar.Web14import android.support.test.espresso.web.webdriver.DriverAtoms15import android.support.test.espresso.web.webdriver.Locator16import android.view.View17import org.hamcrest.CoreMatchers18import org.hamcrest.Matcher19import org.hamcrest.Matchers20import org.hamcrest.core.AllOf21/**22 * Class for building view matchers and interactions23 *24 * This class helps to build matches for views and get their interactions.25 * Please note that any function invoking will add specific matcher to the list26 * and after that all of them will be combined with help of AllOf.allOf()27 *28 * @see AllOf.allOf()29 */30class ViewBuilder {31 private val viewMatchers = arrayListOf<Matcher<View>>()32 /**33 * Matches only view at given index, if there are multiple views that matches34 *35 * @param index Index of the view to match36 * @param function ViewBuilder that will result in matcher37 */38 fun withIndex(index: Int, function: ViewBuilder.() -> Unit) {39 viewMatchers.add(IndexMatcher(ViewBuilder().apply(function).getViewMatcher(), index))40 }41 /**42 * Matches the view with given resource id43 *44 * @param id Resource id to match45 */46 fun withId(id: Int) {47 viewMatchers.add(ViewMatchers.withId(id))48 }49 /**50 * Matches the view if it is in ENABLED state51 */52 fun isEnabled() {53 viewMatchers.add(ViewMatchers.isEnabled())54 }55 /**56 * Matches the view if it is not in ENABLED state57 */58 fun isDisabled() {59 viewMatchers.add(CoreMatchers.not(ViewMatchers.isEnabled()))60 }61 /**62 * Matches the view with given text63 *64 * @param text Text to match65 */66 fun withText(text: String) {67 viewMatchers.add(ViewMatchers.withText(text))68 }69 /**70 * Matches the view with given text71 *72 * @param textId String resource to match73 */74 fun withText(@StringRes textId: Int) {75 viewMatchers.add(ViewMatchers.withText(textId))76 }77 /**78 * Matches the view with given text matcher79 *80 * @param matcher Text matcher to add81 */82 fun withText(matcher: Matcher<String>) {83 viewMatchers.add(ViewMatchers.withText(matcher))84 }85 /**86 * Matches if the view does not have a given text87 *88 * @param text Text to be matched89 */90 fun withoutText(text: String) {91 viewMatchers.add(CoreMatchers.not(ViewMatchers.withText(text)))92 }93 /**94 * Matches if the view does not have a given text95 *96 * @param resId String resource to be matched97 */98 fun withoutText(@StringRes resId: Int) {99 viewMatchers.add(CoreMatchers.not(ViewMatchers.withText(resId)))100 }101 /**102 * Matches the view which contains any text103 */104 fun withAnyText() {105 viewMatchers.add(AnyTextMatcher())106 }107 /**108 * Matches the view which contain given text109 *110 * @param text Text to search111 */112 fun containsText(text: String) {113 viewMatchers.add(ViewMatchers.withText(Matchers.containsString(text)))114 }115 /**116 * Matches the view with given resource name117 *118 * @param name Resource name to match119 */120 fun withResourceName(name: String) {121 viewMatchers.add(ViewMatchers.withResourceName(name))122 }123 /**124 * Matches the view by resource name with given matcher125 *126 * @param matcher Matcher for resource name127 */128 fun withResourceName(matcher: Matcher<String>) {129 viewMatchers.add(ViewMatchers.withResourceName(matcher))130 }131 /**132 * Matches the view with given content description133 *134 * @param description Content description to match135 */136 fun withContentDescription(description: String) {137 viewMatchers.add(ViewMatchers.withContentDescription(description))138 }139 /**140 * Matches the view which has parent with given matcher141 *142 * @param function ViewBuilder which will result in parent matcher143 */144 fun withParent(function: ViewBuilder.() -> Unit) {145 viewMatchers.add(ViewMatchers.withParent(ViewBuilder().apply(function).getViewMatcher()))146 }147 /**148 * Matches the view with given drawable149 *150 * @param resId Drawable resource to match151 * @param toBitmap Lambda with custom Drawable -> Bitmap converter (default is null)152 */153 fun withDrawable(@DrawableRes resId: Int, toBitmap: ((drawable: Drawable) -> Bitmap)? = null) {154 viewMatchers.add(DrawableMatcher(resId = resId, toBitmap = toBitmap))155 }156 /**157 * Matches the view with given drawable158 *159 * @param resId Drawable to match160 * @param toBitmap Lambda with custom Drawable -> Bitmap converter (default is null)161 */162 fun withDrawable(drawable: Drawable, toBitmap: ((drawable: Drawable) -> Bitmap)? = null) {163 viewMatchers.add(DrawableMatcher(drawable = drawable, toBitmap = toBitmap))164 }165 /**166 * Matches the first view167 */168 fun isFirst() {169 viewMatchers.add(FirstViewMatcher())170 }171 /**172 * Matches the view with VISIBLE visibility173 */174 fun isVisible() {175 viewMatchers.add(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))176 }177 /**178 * Matches the view with INVISIBLE visibility179 */180 fun isInvisible() {181 viewMatchers.add(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.INVISIBLE))182 }183 /**184 * Matches the view with GONE visibility185 */186 fun isGone() {187 viewMatchers.add(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.GONE))188 }189 /**190 * Matches the view that is displayed191 */192 fun isDisplayed() {193 viewMatchers.add(ViewMatchers.isDisplayed())194 }195 /**196 * Matches the view that is not displayed197 */198 fun isNotDisplayed() {199 viewMatchers.add(Matchers.not(ViewMatchers.isDisplayed()))200 }201 /**202 * Matches the view that is completely displayed203 */204 fun isCompletelyDisplayed() {205 viewMatchers.add(ViewMatchers.isCompletelyDisplayed())206 }207 /**208 * Matchers the view that is not completely displayed209 */210 fun isNotCompletelyDisplayed() {211 viewMatchers.add(Matchers.not(ViewMatchers.isCompletelyDisplayed()))212 }213 /**214 * Matches the view which is descendant of given matcher215 *216 * @param function ViewBuilder which will result in parent matcher217 */218 fun isDescendantOfA(function: ViewBuilder.() -> Unit) {219 viewMatchers.add(ViewMatchers.isDescendantOfA(ViewBuilder().apply(function).getViewMatcher()))220 }221 /**222 * Matches the view which has descendant of given matcher223 *224 * @param function ViewBuilder which will result in descendant matcher225 */226 fun withDescendant(function: ViewBuilder.() -> Unit) {227 viewMatchers.add(ViewMatchers.hasDescendant(ViewBuilder().apply(function).getViewMatcher()))228 }229 /**230 * Matches the view which has sibling of given matcher231 *232 * @param function ViewBuilder which will result in sibling matcher233 */234 fun withSibling(function: ViewBuilder.() -> Unit) {235 viewMatchers.add(ViewMatchers.hasSibling(ViewBuilder().apply(function).getViewMatcher()))236 }237 /**238 * Matches the view which class name matches given matcher239 *240 * @param matcher Matcher of class name241 */242 fun withClassName(matcher: Matcher<String>) {243 viewMatchers.add(ViewMatchers.withClassName( matcher))244 }245 /**246 * Matches the view by class instance247 *248 * @param clazz Class to match249 */250 fun isInstanceOf(clazz: Class<*>) {251 viewMatchers.add(Matchers.instanceOf(clazz))252 }253 /**254 * Matches the view with given custom matcher255 *256 * @param matcher Matcher that needs to be added257 */258 fun withMatcher(matcher: Matcher<View>) {259 viewMatchers.add(matcher)260 }261 /**262 * Returns view interaction based on all given matchers263 *264 * @return ViewInteraction265 */266 fun getViewInteraction(): ViewInteraction {267 check(viewMatchers.isNotEmpty()) { "No matchers inside InteractionBuilder" }268 return Espresso.onView(AllOf.allOf(viewMatchers))269 }270 /**271 * Returns combined view matcher with AllOf.allOf()272 *273 * @return Matcher<View>274 */275 fun getViewMatcher() = AllOf.allOf(viewMatchers)!!276}277/**278 * Class for building root matchers279 *280 * This class helps to build matches for root.281 * Please note that any function invoking will add specific matcher to the list282 * and after that all of them will be combined with help of AllOf.allOf()283 *284 * @see AllOf.allOf()285 */286class RootBuilder {287 private val rootMatchers = arrayListOf<Matcher<Root>>()288 /**289 * Matches root that is dialog290 */291 fun isDialog() {292 rootMatchers.add(RootMatchers.isDialog())293 }294 /**295 * Matches root that is not dialog296 */297 fun isNotDialog() {298 rootMatchers.add(Matchers.not(RootMatchers.isDialog()))299 }300 /**301 * Matches root that is focusable302 */303 fun isFocusable() {304 rootMatchers.add(RootMatchers.isFocusable())305 }306 /**307 * Matches root that is not focusable308 */309 fun isNotFocusable() {310 rootMatchers.add(Matchers.not(RootMatchers.isFocusable()))311 }312 /**313 * Matches root that is platform popup314 */315 fun isPlatformPopup() {316 rootMatchers.add(RootMatchers.isPlatformPopup())317 }318 /**319 * Matches root that is not platform popup320 */321 fun isNotPlatformPopup() {322 rootMatchers.add(Matchers.not(RootMatchers.isPlatformPopup()))323 }324 /**325 * Matches root that is touchable326 */327 fun isTouchable() {328 rootMatchers.add(RootMatchers.isTouchable())329 }330 /**331 * Matches root that is not touchable332 */333 fun isNotTouchable() {334 rootMatchers.add(Matchers.not(RootMatchers.isTouchable()))335 }336 /**337 * Matches root that has decor view matching given matcher338 *339 * @param function ViewBuilder which will result in decor view matcher340 */341 fun withDecorView(function: ViewBuilder.() -> Unit) {342 rootMatchers.add(RootMatchers.withDecorView(ViewBuilder().apply(function).getViewMatcher()))343 }344 /**345 * Matches root with given custom matcher346 *347 * @param matcher Custom root matcher to be added348 */349 fun withMatcher(matcher: Matcher<Root>) {350 rootMatchers.add(matcher)351 }352 /**353 * Returns combined root matchers with AllOf.allOf()354 *355 * @return Matcher<Root>356 */...

Full Screen

Full Screen

SignUpTests.kt

Source:SignUpTests.kt Github

copy

Full Screen

...3import android.support.test.espresso.Espresso4import android.support.test.espresso.action.ViewActions5import android.support.test.espresso.assertion.ViewAssertions6import android.support.test.espresso.assertion.ViewAssertions.matches7import android.support.test.espresso.matcher.RootMatchers8import android.support.test.espresso.matcher.ViewMatchers9import android.support.test.espresso.matcher.ViewMatchers.isDisplayed10import android.support.test.espresso.matcher.ViewMatchers.withId11import android.support.test.rule.ActivityTestRule12import androidx.test.uiautomator.By13import androidx.test.uiautomator.UiDevice14import org.hamcrest.core.IsNot15import org.junit.After16import org.junit.Before17import org.junit.Rule18import org.junit.Test19import java.lang.Thread.sleep20import kotlin.random.Random.Default.nextInt21class SignUpTests {22 @get:Rule23 val rule = ActivityTestRule<LoginActivity>(LoginActivity::class.java)24 //val rule2 = ActivityTestRule<SignUpActivity>(SignUpActivity::class.java)25 lateinit var loginActivity: LoginActivity26 //lateinit var signUpActivity: SignUpActivity27 lateinit var mdevice: UiDevice28 @Before29 fun setup() {30 loginActivity = rule.activity31 //signUpActivity = rule2.activity32 mdevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())33 }34 @Test35 fun check_register_flow() {36 Thread.sleep(1000)37 mdevice.findObject(By.res("cs408.incubator","btn_signup")).click()38 sleep(1000)39 //signUpActivity.onResume()40 mdevice.hasObject(By.res("cs408.incubator","sign_up_button"))41 mdevice.findObject(By.res("cs408.incubator","sign_in_button")).click()42 sleep(1000)43 mdevice.hasObject(By.res("cs408.incubator","btn_signup"))44 }45 @Test46 fun blank_email() {47 val email = ""48 val password = "emptyMail"49 sleep(1000)50 mdevice.findObject(By.res("cs408.incubator","btn_signup")).click()51 sleep(1000)52 Espresso.onView(ViewMatchers.withId(R.id.password)).perform(ViewActions.click())53 Espresso.onView(ViewMatchers.withId(R.id.password)).perform(ViewActions.typeText(password))54 Espresso.onView(ViewMatchers.withId(R.id.sign_up_button)).perform(ViewActions.click())55 Espresso.onView(ViewMatchers.withText("Enter email address!")).inRoot(RootMatchers.withDecorView(IsNot.not(rule.activity.window.decorView))).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))56 }57 @Test58 fun blank_password() {59 val email = "newemail@gmail.com"60 val password = ""61 sleep(1000)62 mdevice.findObject(By.res("cs408.incubator","btn_signup")).click()63 sleep(1000)64 mdevice.findObject(By.res("cs408.incubator","email")).text = email65 Espresso.onView(ViewMatchers.withId(R.id.sign_up_button)).perform(ViewActions.click())66 Espresso.onView(ViewMatchers.withText("Enter password!")).inRoot(RootMatchers.withDecorView(IsNot.not(rule.activity.window.decorView))).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))67 }68 @Test69 fun check_existing_user() {70 val email = "abca@abca.com"71 val password = "123456"72 sleep(1000)73 mdevice.findObject(By.res("cs408.incubator","btn_signup")).click()74 sleep(1000)75 mdevice.findObject(By.res("cs408.incubator","email")).text = email76 Espresso.onView(ViewMatchers.withId(R.id.password)).perform(ViewActions.typeText(password))77 Espresso.onView(ViewMatchers.withId(R.id.sign_up_button)).perform(ViewActions.click())78 sleep(200)79 Espresso.onView(ViewMatchers.withText("Authentication failed. User Already Exists")).inRoot(RootMatchers.withDecorView(IsNot.not(rule.activity.window.decorView))).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))80 }81 @Test82 fun invalid_email() {83 val email = "ab"84 val password = "123456"85 sleep(1000)86 mdevice.findObject(By.res("cs408.incubator","btn_signup")).click()87 sleep(1000)88 mdevice.findObject(By.res("cs408.incubator","email")).text = email89 Espresso.onView(ViewMatchers.withId(R.id.password)).perform(ViewActions.typeText(password))90 Espresso.onView(ViewMatchers.withId(R.id.sign_up_button)).perform(ViewActions.click())91 Espresso.onView(ViewMatchers.withText("Authentication failed. Invalid Email Format")).inRoot(RootMatchers.withDecorView(IsNot.not(rule.activity.window.decorView))).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))92 }93 @Test94 fun invalid_password() {95 val email = "abca@abca.com"96 val password = "12345"97 val errMsg = "Password too short, enter minimum 6 characters!"98 sleep(1000)99 mdevice.findObject(By.res("cs408.incubator","btn_signup")).click()100 sleep(1000)101 mdevice.findObject(By.res("cs408.incubator","email")).text = email102 Espresso.onView(ViewMatchers.withId(R.id.password)).perform(ViewActions.typeText(password))103 Espresso.onView(ViewMatchers.withId(R.id.sign_up_button)).perform(ViewActions.click())104 Espresso.onView(ViewMatchers.withText(errMsg)).inRoot(RootMatchers.withDecorView(IsNot.not(rule.activity.window.decorView))).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))105 }106 @Test107 fun profile_creation() {108 val name = "@az"109 val email = "abcza"+nextInt()+"@gmail.com"110 val password = "123456"111 val errmsg = "Invalid Characters in Name"112 val errmsg2 = "Name cannot be empty!"113 sleep(1000)114 mdevice.findObject(By.res("cs408.incubator","btn_signup")).click()115 sleep(1000)116 mdevice.findObject(By.res("cs408.incubator","email")).text = email117 Espresso.onView(ViewMatchers.withId(R.id.password)).perform(ViewActions.typeText(password))118 Espresso.onView(ViewMatchers.withId(R.id.sign_up_button)).perform(ViewActions.click())119 sleep(1000)120 mdevice.findObject(By.res("cs408.incubator","dispName")).text = name121 mdevice.findObject(By.res("cs408.incubator","submitName")).click()122 Espresso.onView(ViewMatchers.withText(errmsg)).inRoot(RootMatchers.withDecorView(IsNot.not(rule.activity.window.decorView))).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))123 sleep(1000)124 mdevice.findObject(By.res("cs408.incubator","dispName")).text = "abcd"125 mdevice.findObject(By.res("cs408.incubator","submitName")).click()126 sleep(1000)127 Espresso.onView(withId(R.id.fab)).check(matches(isDisplayed()))128 Espresso.onView(ViewMatchers.withContentDescription("Navigate up")).perform(ViewActions.click())129 sleep(1000)130 Espresso.onView(ViewMatchers.withText("Profile")).perform(ViewActions.click())131 sleep(2000)132 Espresso.onView(withId(R.id.sign_out)).perform(ViewActions.click())133 }134}...

Full Screen

Full Screen

ViewMatchersTest.kt

Source:ViewMatchersTest.kt Github

copy

Full Screen

...13import android.support.test.espresso.matcher.LayoutMatchers.hasMultilineText14import android.support.test.espresso.matcher.PreferenceMatchers.withKey15import android.support.test.espresso.matcher.PreferenceMatchers.withSummaryText16import android.support.test.espresso.matcher.PreferenceMatchers.withTitle17import android.support.test.espresso.matcher.RootMatchers.isDialog18import android.support.test.espresso.matcher.RootMatchers.isPlatformPopup19import android.support.test.espresso.matcher.RootMatchers.isTouchable20import android.support.test.espresso.matcher.ViewMatchers.hasContentDescription21import android.support.test.espresso.matcher.ViewMatchers.hasDescendant22import android.support.test.espresso.matcher.ViewMatchers.hasImeAction23import android.support.test.espresso.matcher.ViewMatchers.hasSibling24import android.support.test.espresso.matcher.ViewMatchers.isAssignableFrom25import android.support.test.espresso.matcher.ViewMatchers.isChecked26import android.support.test.espresso.matcher.ViewMatchers.isDescendantOfA27import android.support.test.espresso.matcher.ViewMatchers.isDisplayed28import android.support.test.espresso.matcher.ViewMatchers.isEnabled29import android.support.test.espresso.matcher.ViewMatchers.isFocusable30import android.support.test.espresso.matcher.ViewMatchers.isSelected31import android.support.test.espresso.matcher.ViewMatchers.supportsInputMethods32import android.support.test.espresso.matcher.ViewMatchers.withChild33import android.support.test.espresso.matcher.ViewMatchers.withClassName...

Full Screen

Full Screen

RemoveExistingUserTest.kt

Source:RemoveExistingUserTest.kt Github

copy

Full Screen

...3import android.support.test.espresso.action.ViewActions.click4import android.support.test.espresso.action.ViewActions.typeTextIntoFocusedView5import android.support.test.espresso.assertion.ViewAssertions6import android.support.test.espresso.assertion.ViewAssertions.matches7import android.support.test.espresso.matcher.RootMatchers8import android.support.test.espresso.matcher.RootMatchers.isDialog9import android.support.test.espresso.matcher.RootMatchers.withDecorView10import android.support.test.espresso.matcher.ViewMatchers.*11import android.support.test.rule.ActivityTestRule12import android.support.test.runner.AndroidJUnit413import android.support.v7.widget.RecyclerView14import com.komnacki.sportresultstracker.R15import com.komnacki.sportresultstracker.funtional.Utils.TestUtils16import com.komnacki.sportresultstracker.usersActivity.UsersListActivity17import org.hamcrest.core.IsNot18import org.junit.Before19import org.junit.Rule20import org.junit.Test21import org.junit.runner.RunWith22@RunWith(AndroidJUnit4::class)23class RemoveExistingUserTest {24 private lateinit var stringToBetyped: String25 @get:Rule26 var activityRule: ActivityTestRule<UsersListActivity> = ActivityTestRule(UsersListActivity::class.java)27 @Before28 fun initValidString() {29 // Specify a valid string.30 stringToBetyped = "Espresso"31 }32 @Test33 fun testIfAddNewUserDialogAppear() {34 var listCount = 035 onView(withId(R.id.rv_usersList)).check { view, noViewFoundException ->36 listCount = TestUtils.getSizeOfRecyclerView(view as RecyclerView)37 }38 while (listCount > 0) {39 onView(withId(R.id.item_usersList_btn_delete)).perform(click())40 onView(withText("Delete user"))41 .inRoot(RootMatchers.withDecorView(IsNot.not(activityRule.activity.window.decorView)))42 .check(ViewAssertions.matches(isDisplayed()))43 onView(withId(android.R.id.button1))44 .perform(click())45 onView(withId(R.id.rv_usersList)).check { view, noViewFoundException ->46 listCount = TestUtils.getSizeOfRecyclerView(view as RecyclerView)47 }48 }49 onView(withId(R.id.fab)).perform(click())50 Thread.sleep(TestUtils.timeIntervalMillis)51 onView(withText("Add new user"))52 .check(matches(isDisplayed()))53 Thread.sleep(TestUtils.timeIntervalMillis)54 onView(withId(R.id.tv_input_user))55 .inRoot(isDialog())...

Full Screen

Full Screen

LaunchPage.kt

Source:LaunchPage.kt Github

copy

Full Screen

...3import android.support.test.espresso.Espresso4import android.support.test.espresso.Espresso.onView5import android.support.test.espresso.action.ViewActions6import android.support.test.espresso.assertion.ViewAssertions7import android.support.test.espresso.matcher.RootMatchers8import android.support.test.espresso.matcher.ViewMatchers9object LaunchPage : BasePage() {10 override fun onPageLoaded(): LaunchPage {11 onView(ViewMatchers.withId(R.id.recoverWalletButton))12 onView(ViewMatchers.withId(R.id.createWalletButton))13 return this14 }15 fun createWallet(option : MnemonicType, pin : String): LaunchPage {16 val context = InstrumentationRegistry.getInstrumentation().targetContext17 onView(ViewMatchers.withId(R.id.createWalletButton)).perform(ViewActions.click())18 val optionString : String = when (option) {19 MnemonicType.WORD_12 -> context.getString(R.string.create_word_option_1)20 MnemonicType.WORD_24 -> context.getString(R.string.create_word_option_2)21 }22 Espresso.onView(ViewMatchers.withText(optionString))23 .inRoot(RootMatchers.isDialog())24 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))25 .perform(ViewActions.click())26 Espresso.onView(ViewMatchers.withId(R.id.confirmButton)).perform(ViewActions.click())27 return this28 }29 fun clickRecoverFromSecretKey() : LaunchPage {30 val context = InstrumentationRegistry.getInstrumentation().targetContext31 onView(ViewMatchers.withId(R.id.recoverWalletButton)).perform(ViewActions.click())32 val string = context.getString(R.string.recover_from_seed)33 Espresso.onView(ViewMatchers.withText(string))34 .inRoot(RootMatchers.isDialog())35 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))36 .perform(ViewActions.click())37 return this38 }39 fun clickRecoverFromPhrase(): LaunchPage {40 val context = InstrumentationRegistry.getInstrumentation().targetContext41 onView(ViewMatchers.withId(R.id.recoverWalletButton)).perform(ViewActions.click())42 val string = context.getString(R.string.recover_from_phrase)43 Espresso.onView(ViewMatchers.withText(string))44 .inRoot(RootMatchers.isDialog())45 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))46 .perform(ViewActions.click())47 return this48 }49}...

Full Screen

Full Screen

SaveImage.kt

Source:SaveImage.kt Github

copy

Full Screen

1package hypr.hypergan.com.hypr.Main2import android.support.test.espresso.Espresso.onView3import android.support.test.espresso.action.ViewActions.click4import android.support.test.espresso.assertion.ViewAssertions5import android.support.test.espresso.matcher.RootMatchers6import android.support.test.espresso.matcher.ViewMatchers.*7import android.support.test.rule.ActivityTestRule8import android.support.test.runner.AndroidJUnit49import android.test.suitebuilder.annotation.LargeTest10import android.view.View11import android.view.ViewGroup12import hypr.hypergan.com.hypr.R13import org.hamcrest.Description14import org.hamcrest.Matcher15import org.hamcrest.Matchers.*16import org.hamcrest.TypeSafeMatcher17import org.junit.Rule18import org.junit.Test19import org.junit.runner.RunWith20@LargeTest21@RunWith(AndroidJUnit4::class)22class SaveImage {23 @get:Rule24 var mActivityTestRule = ActivityTestRule(MainActivity::class.java)25 @Test26 fun saveImageToastConfirmation() {27 val actionMenuItemView = onView(28 allOf(withId(R.id.saveImage), withContentDescription("Save"),29 childAtPosition(30 childAtPosition(31 withId(R.id.toolbar),32 1),33 1),34 isDisplayed()))35 actionMenuItemView.perform(click())36 onView(withText(R.string.image_saved_toast))37 .inRoot(RootMatchers.withDecorView(not(`is`(mActivityTestRule.activity.window.decorView))))38 .check(ViewAssertions.matches(isDisplayed()))39 }40 private fun childAtPosition(41 parentMatcher: Matcher<View>, position: Int): Matcher<View> {42 return object : TypeSafeMatcher<View>() {43 override fun describeTo(description: Description) {44 description.appendText("Child at position $position in parent ")45 parentMatcher.describeTo(description)46 }47 public override fun matchesSafely(view: View): Boolean {48 val parent = view.parent49 return parent is ViewGroup && parentMatcher.matches(parent)50 && view == parent.getChildAt(position)51 }...

Full Screen

Full Screen

BookmarkRobot.kt

Source:BookmarkRobot.kt Github

copy

Full Screen

...3import android.support.test.espresso.action.ViewActions.click4import android.support.test.espresso.action.ViewActions.replaceText5import android.support.test.espresso.assertion.ViewAssertions.matches6import android.support.test.espresso.contrib.RecyclerViewActions7import android.support.test.espresso.matcher.RootMatchers8import android.support.test.espresso.matcher.ViewMatchers.isDisplayed9import android.support.test.espresso.matcher.ViewMatchers.withId10import android.support.test.espresso.matcher.ViewMatchers.withText11import android.support.v7.widget.RecyclerView12import org.mozilla.focus.R13import org.mozilla.focus.activity.MainActivity14import org.mozilla.focus.utils.AndroidTestUtils15import org.mozilla.focus.utils.RecyclerViewTestUtils.clickChildViewWithId16inline fun bookmark(func: BookmarkRobot.() -> Unit) = BookmarkRobot().apply(func)17class BookmarkRobot(menuAutomation: MenuAutomation = MenuRobot()) : MenuAutomation by menuAutomation {18 fun checkEmptyViewIsDisplayed() {19 onView(withText(R.string.bookmarks_empty_view_msg)).check(matches(isDisplayed()))20 }21 fun updateBookmarkName(name: String) {22 onView(withId(R.id.bookmark_name)).perform(replaceText(name))23 }24 fun clickSave() {25 onView(withText(R.string.bookmark_edit_save)).perform(click())26 }27 fun clickListItemActionMenu(position: Int) {28 onView(withId(R.id.recyclerview)).perform(RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(position, clickChildViewWithId(R.id.history_item_btn_more)))29 }30 fun checkItemMenuEditIsDisplayed() {31 onView(withText(R.string.edit_bookmark)).inRoot(RootMatchers.isPlatformPopup()).check(matches(isDisplayed()))32 }33 fun clickItemMenuEdit() {34 onView(withText(R.string.edit_bookmark)).inRoot(RootMatchers.isPlatformPopup()).perform(click())35 }36 fun checkBookmarkUpdatedToastIsDisplayed(activity: MainActivity) = AndroidTestUtils.toastContainsText(activity, R.string.bookmark_edit_success)37}...

Full Screen

Full Screen

HistoryRobot.kt

Source:HistoryRobot.kt Github

copy

Full Screen

2import android.support.test.espresso.Espresso.onView3import android.support.test.espresso.action.ViewActions.click4import android.support.test.espresso.assertion.ViewAssertions.matches5import android.support.test.espresso.contrib.RecyclerViewActions6import android.support.test.espresso.matcher.RootMatchers7import android.support.test.espresso.matcher.ViewMatchers.isDisplayed8import android.support.test.espresso.matcher.ViewMatchers.withId9import android.support.test.espresso.matcher.ViewMatchers.withText10import android.support.v7.widget.RecyclerView11import org.mozilla.focus.R12import org.mozilla.focus.utils.RecyclerViewTestUtils.clickChildViewWithId13inline fun history(func: HistoryRobot.() -> Unit) = HistoryRobot().apply(func)14class HistoryRobot(menuAutomation: MenuAutomation = MenuRobot()) : MenuAutomation by menuAutomation {15 fun clickListItemActionMenu(position: Int) {16 onView(withId(R.id.browsing_history_recycler_view)).perform(17 RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(position, clickChildViewWithId(R.id.history_item_btn_more)))18 }19 fun checkItemMenuDeleteIsDisplayed() {20 onView(withText(R.string.browsing_history_menu_delete))21 .inRoot(RootMatchers.isPlatformPopup())22 .check(matches(isDisplayed()))23 }24 fun clickItemMenuDelete() {25 onView(withText(R.string.browsing_history_menu_delete))26 .inRoot(RootMatchers.isPlatformPopup())27 .perform(click())28 }29 fun clickClearBrowsingHistory() {30 onView(withId(R.id.browsing_history_btn_clear)).perform(click())31 }32 fun checkConfirmClearDialogIsDisplayed() {33 onView(withText(R.string.browsing_history_dialog_confirm_clear_message)).check(matches(isDisplayed()))34 }35}...

Full Screen

Full Screen

RootMatchers

Using AI Code Generation

copy

Full Screen

1import android.support.test.espresso.matcher.RootMatchers;2import android.support.test.espresso.matcher.ViewMatchers;3import android.support.test.espresso.ViewInteraction;4import android.support.test.espresso.ViewAction;5import android.support.test.espresso.ViewAssertion;6import andro

Full Screen

Full Screen

RootMatchers

Using AI Code Generation

copy

Full Screen

1ViewInteraction appCompatEditText = onView(2allOf(withId(R.id.et_name),3childAtPosition(4childAtPosition(5withId(android.R.id.content),6isDisplayed()));7appCompatEditText.perform(replaceText("test"), closeSoftKeyboard());8ViewInteraction appCompatEditText2 = onView(9allOf(withId(R.id.et_name), withText("test"),10childAtPosition(11childAtPosition(12withId(android.R.id.content),13isDisplayed()));14appCompatEditText2.perform(click());15ViewInteraction appCompatEditText3 = onView(16allOf(withId(R.id.et_name), withText("test"),17childAtPosition(18childAtPosition(19withId(android.R.id.content),20isDisplayed()));21appCompatEditText3.perform(replaceText("test1"));22ViewInteraction appCompatEditText4 = onView(23allOf(withId(R.id.et_name), withText("test1"),24childAtPosition(25childAtPosition(26withId(android.R.id.content),27isDisplayed()));28appCompatEditText4.perform(closeSoftKeyboard());29ViewInteraction appCompatButton = onView(30allOf(withId(R.id.btn_say_hello), withText("Say Hello"),31childAtPosition(32childAtPosition(33withId(android.R.id.content),34isDisplayed()));35appCompatButton.perform(click());36ViewInteraction textView = onView(37allOf(withId(R.id.tv_output), withText("Hello test1"),38withParent(withParent(withId(android.R.id.content))),39isDisplayed()));40textView.check(matches(withText("Hello test1")));41}42}43* Returns a matcher that matches {@link View}s based on the specified {@code matcher} applied to the44public static Matcher<View> childAtPosition(45final Matcher<View> parentMatcher, final int childPosition) {46return new TypeSafeMatcher<View>() {47@Override public void describeTo(Description description) {48description.appendText("Child at position " + childPosition + " in parent ");49parentMatcher.describeTo(description);50}51@Override public boolean matchesSafely(View view) {52ViewGroup parent = (ViewGroup) view.getParent();53return parent != null && parentMatcher.matches(parent)54&& view.equals(parent.getChildAt(childPosition));55}56};57}58}

Full Screen

Full Screen

RootMatchers

Using AI Code Generation

copy

Full Screen

1public IntentsTestRule<MainActivity> intentsTestRule = new IntentsTestRule<>(MainActivity.class);2public void testIntent() {3onView(withId(R.id.button)).perform(click());4intended(hasComponent(new ComponentName(getTargetContext(), SecondActivity.class)));5}6public IntentsTestRule<MainActivity> intentsTestRule = new IntentsTestRule<>(MainActivity.class);7public void testIntent() {8onView(withId(R.id.button)).perform(click());9intended(hasComponent(new ComponentName(getTargetContext(), SecondActivity.class)));10}11public IntentsTestRule<MainActivity> intentsTestRule = new IntentsTestRule<>(MainActivity.class);12public void testIntent() {13onView(withId(R.id.button)).perform(click());14intended(hasComponent(new ComponentName(getTargetContext(), SecondActivity.class)));15}16public IntentsTestRule<MainActivity> intentsTestRule = new IntentsTestRule<>(MainActivity.class);17public void testIntent() {18onView(withId(R.id.button)).perform(click());19intended(hasComponent(new ComponentName(getTargetContext(), SecondActivity.class)));20}21public IntentsTestRule<MainActivity> intentsTestRule = new IntentsTestRule<>(MainActivity.class);22public void testIntent() {23onView(withId(R.id.button)).perform(click());24intended(hasComponent(new ComponentName(getTargetContext(), SecondActivity.class)));25}26public IntentsTestRule<MainActivity> intentsTestRule = new IntentsTestRule<>(MainActivity.class);27public void testIntent() {28onView(withId(R.id.button)).perform(click());29intended(hasComponent(new ComponentName(getTargetContext(), SecondActivity.class)));30}31public IntentsTestRule<MainActivity> intentsTestRule = new IntentsTestRule<>(MainActivity.class);32public void testIntent() {33onView(withId(R.id.button)).perform(click());34intended(hasComponent(new ComponentName(getTargetContext(), SecondActivity.class)));35}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Appium-espresso-driver automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful