How to use withId method of android.support.test.espresso.matcher.ViewMatchers class

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

FinalFullTest.kt

Source:FinalFullTest.kt Github

copy

Full Screen

...142 .set(espressoUser3)143 }144 @Test145 fun espressoFinalTest() {146 Espresso.onView(ViewMatchers.withId(R.id.signup_username))147 .perform(ViewActions.replaceText("EspressoUsernameFinal1"))148 Espresso.onView(ViewMatchers.withId(R.id.signup_password))149 .perform(ViewActions.replaceText("EspressoPasswordFinal1"))150 Espresso.onView(ViewMatchers.withId(R.id.signup_email))151 .perform(ViewActions.replaceText("EspressoEmailFinal1@gmail.com"))152 Espresso.onView(ViewMatchers.withId(R.id.email_sign_up_button))153 .perform(ViewActions.click())154 Thread.sleep(15000)155 Espresso.onView(ViewMatchers.withId(R.id.main_OpenMenu))156 .perform(ViewActions.click())157 Espresso.onView(ViewMatchers.withId(R.id.main_SignOut))158 .perform(ViewActions.click())159 Thread.sleep(500)160 Espresso.onView(ViewMatchers.withId(R.id.go_to_login))161 .perform(ViewActions.click())162 Espresso.onView(ViewMatchers.withId(R.id.login_email))163 .perform(ViewActions.replaceText("EspressoEmailFinal1@gmail.com"))164 Espresso.onView(ViewMatchers.withId(R.id.login_password))165 .perform(ViewActions.replaceText("EspressoPasswordFinal1"))166 Espresso.onView(ViewMatchers.withId(R.id.email_sign_in_button))167 .perform(ViewActions.click())168 Thread.sleep(5000)169 Espresso.onView(ViewMatchers.withId(R.id.main_OpenMenu))170 .perform(ViewActions.click())171 Espresso.onView(ViewMatchers.withId(R.id.main_SignOut))172 .perform(ViewActions.click())173 Thread.sleep(500)174 //Register and login test done.175 //Starting test of all activities, exchanging, transfering, setting up wager, and rerolling quest176 Espresso.onView(ViewMatchers.withId(R.id.login_email))177 .perform(ViewActions.replaceText("EspressoEmailFinal2@gmail.com"))178 Espresso.onView(ViewMatchers.withId(R.id.login_password))179 .perform(ViewActions.replaceText("EspressoPasswordFinal2"))180 Espresso.onView(ViewMatchers.withId(R.id.email_sign_in_button))181 .perform(ViewActions.click())182 Thread.sleep(5000)183 Espresso.onView(ViewMatchers.withId(R.id.main_OpenMenu))184 .perform(ViewActions.click())185 Espresso.onView(ViewMatchers.withId(R.id.main_Ranking))186 .perform(ViewActions.click())187 Thread.sleep(1000)188 Espresso.onView(ViewMatchers.withId(R.id.ranking_PlayerRanking))189 .check(matches(withText("Player Ranking")))190 Espresso.pressBack()191 Espresso.onView(ViewMatchers.withId(R.id.main_OpenMenu))192 .perform(ViewActions.click())193 Espresso.onView(ViewMatchers.withId(R.id.main_Bank))194 .perform(ViewActions.click())195 Espresso.onView(withId(R.id.bank_GOLDvalue))196 .check(matches(not(withText("0.0"))))197 Espresso.onView(ViewMatchers.withId(R.id.bank_GOLDvalue))198 .check(matches(withText("123.4")))199 Thread.sleep(500)200 Espresso.onData(anything())201 .inAdapterView(withId(R.id.bank_coinzGridView))202 .atPosition(0)203 .onChildView(withId(R.id.coinExchange))204 .perform(ViewActions.click())205 Thread.sleep(2000)206 Espresso.onView(ViewMatchers.withId(R.id.bank_GOLDvalue))207 .check(matches(not(withText("123.4"))))208 Espresso.onData(anything())209 .inAdapterView(withId(R.id.bank_coinzGridView))210 .atPosition(0)211 .onChildView(withId(R.id.coinExchange))212 .perform(ViewActions.click())213 Thread.sleep(500)214 Espresso.onData(anything())215 .inAdapterView(withId(R.id.bank_coinzGridView))216 .atPosition(0)217 .onChildView(withId(R.id.coinExchange))218 .perform(ViewActions.click())219 Thread.sleep(500)220 Espresso.onView(withId(R.id.bank_exchangedTextView))221 .check(matches(withText(containsString("back tomorrow to exchange"))))222 Espresso.onView(withId(R.id.bank_coinzGridView))223 .check(matches(withGridSize(3)))224 Espresso.onView(withId(R.id.bank_transferButton))225 .perform(ViewActions.click())226 Espresso.onView(withId(R.id.bank_transferEmail))227 .perform(ViewActions.replaceText("EspressoEmailFinal2@gmail.com"))228 Espresso.onData(anything())229 .inAdapterView(withId(R.id.bank_coinzGridView))230 .atPosition(0)231 .onChildView(withId(R.id.coinExchange))232 .perform(ViewActions.click())233 Espresso.onView(ViewMatchers.withId(R.id.bank_transferEmail))234 .check(matches(hasErrorText("You cannot transfer Coinz to yourself")))235 Espresso.onView(withId(R.id.bank_transferEmail))236 .perform(ViewActions.replaceText("JustTesting"))237 Espresso.onData(anything())238 .inAdapterView(withId(R.id.bank_coinzGridView))239 .atPosition(0)240 .onChildView(withId(R.id.coinExchange))241 .perform(ViewActions.click())242 Espresso.onView(ViewMatchers.withId(R.id.bank_transferEmail))243 .check(matches(hasErrorText("This email address is invalid")))244 Espresso.onView(withId(R.id.bank_transferEmail))245 .perform(ViewActions.replaceText("EspressoEmailFinal3@gmail.com"))246 Espresso.onData(anything())247 .inAdapterView(withId(R.id.bank_coinzGridView))248 .atPosition(0)249 .onChildView(withId(R.id.coinExchange))250 .perform(ViewActions.click())251 Thread.sleep(500)252 Espresso.onData(anything())253 .inAdapterView(withId(R.id.bank_coinzGridView))254 .atPosition(0)255 .onChildView(withId(R.id.coinExchange))256 .perform(ViewActions.click())257 Thread.sleep(500)258 Espresso.onData(anything())259 .inAdapterView(withId(R.id.bank_coinzGridView))260 .atPosition(0)261 .onChildView(withId(R.id.coinExchange))262 .perform(ViewActions.click())263 Thread.sleep(5000)264 Espresso.onView(withId(R.id.bank_coinzGridView))265 .check(matches(withGridSize(1)))266 Espresso.pressBack()267 Espresso.onView(ViewMatchers.withId(R.id.main_OpenMenu))268 .perform(ViewActions.click())269 Espresso.onView(ViewMatchers.withId(R.id.main_Race))270 .perform(ViewActions.click())271 Espresso.onView(ViewMatchers.withId(R.id.race_TimeSpinner))272 .perform(ViewActions.click())273 Espresso.onData(Matchers.hasToString(startsWith("30")))274 .perform(ViewActions.click())275 Espresso.onView(ViewMatchers.withId(R.id.race_WagerButton))276 .perform(ViewActions.click())277 Thread.sleep(2000)278 Espresso.onView(ViewMatchers.withId(R.id.main_WagerTextView))279 .check(matches(isDisplayed()))280 Espresso.onView(ViewMatchers.withId(R.id.main_WagerTextView))281 .check(matches(withText(startsWith("Time Left:"))))282 Espresso.onView(ViewMatchers.withId(R.id.main_OpenMenu))283 .perform(ViewActions.click())284 Espresso.onView(ViewMatchers.withId(R.id.main_Transfer))285 .perform(ViewActions.click())286 Espresso.onView(ViewMatchers.withId(R.id.transferHistory_TransferHistoryTextView))287 .check(matches(withText("Transfer History")))288 Espresso.pressBack()289 Espresso.onView(ViewMatchers.withId(R.id.main_OpenMenu))290 .perform(ViewActions.click())291 Espresso.onView(ViewMatchers.withId(R.id.main_Quest))292 .perform(ViewActions.click())293 Espresso.onData(anything())294 .inAdapterView(withId(R.id.quest_listView))295 .atPosition(0)296 .onChildView(withId(R.id.quest_rerollButton))297 .perform(ViewActions.click())298 Thread.sleep(500)299 Espresso.onData(anything())300 .inAdapterView(withId(R.id.quest_listView))301 .atPosition(0)302 .onChildView(withId(R.id.quest_rerollButton))303 .check(matches(Matchers.not(isEnabled())))304 Espresso.pressBack()305 Espresso.onView(ViewMatchers.withId(R.id.main_OpenMenu))306 .perform(ViewActions.click())307 Espresso.onView(ViewMatchers.withId(R.id.main_SignOut))308 .perform(ViewActions.click())309 Thread.sleep(500)310 Espresso.onView(ViewMatchers.withId(R.id.login_email))311 .perform(ViewActions.replaceText("EspressoEmailFinal2@gmail.com"))312 Espresso.onView(ViewMatchers.withId(R.id.login_password))313 .perform(ViewActions.replaceText("EspressoPasswordFinal2"))314 Espresso.onView(ViewMatchers.withId(R.id.email_sign_in_button))315 .perform(ViewActions.click())316 Thread.sleep(5000)317 Espresso.onView(ViewMatchers.withId(R.id.main_WagerTextView))318 .check(matches(isDisplayed()))319 Espresso.onView(ViewMatchers.withId(R.id.main_OpenMenu))320 .perform(ViewActions.click())321 Espresso.onView(ViewMatchers.withId(R.id.main_SignOut))322 .perform(ViewActions.click())323 Thread.sleep(500)324 Espresso.onView(ViewMatchers.withId(R.id.login_email))325 .perform(ViewActions.replaceText("EspressoEmailFinal3@gmail.com"))326 Espresso.onView(ViewMatchers.withId(R.id.login_password))327 .perform(ViewActions.replaceText("EspressoPasswordFinal3"))328 Espresso.onView(ViewMatchers.withId(R.id.email_sign_in_button))329 .perform(ViewActions.click())330 Thread.sleep(5000)331 Espresso.onView(ViewMatchers.withId(R.id.main_OpenMenu))332 .perform(ViewActions.click())333 Espresso.onView(ViewMatchers.withId(R.id.main_Transfer))334 .perform(ViewActions.click())335 Thread.sleep(500)336 Espresso.onView(ViewMatchers.withId(R.id.transferHistory_listView))337 .check(matches(withListSize(2)))338 Espresso.onData(anything())339 .inAdapterView(withId(R.id.transferHistory_listView))340 .atPosition(1)341 .onChildView(withId(R.id.transferHistory_DeleteButton))342 .perform(ViewActions.click())343 Thread.sleep(250)344 Espresso.onView(ViewMatchers.withId(R.id.transferHistory_listView))345 .check(matches(withListSize(1)))346 Espresso.onData(anything())347 .inAdapterView(withId(R.id.transferHistory_listView))348 .atPosition(0)349 .onChildView(withId(R.id.transferHistory_DeleteAllButton))350 .perform(ViewActions.click())351 Thread.sleep(250)352 Espresso.onView(ViewMatchers.withId(R.id.transferHistory_listView))353 .check(matches(withListSize(0)))354 Espresso.pressBack()355 Espresso.onView(withId(R.id.main_OpenMenu))356 .perform(ViewActions.click())357 Espresso.onView(withId(R.id.main_Bank))358 .perform(ViewActions.click())359 Espresso.onView(withId(R.id.bank_GOLDvalue))360 .check(matches(not(withText("567.8"))))361 Espresso.onView(withId(R.id.bank_GOLDvalue))362 .check(matches(not(withText("0.0"))))363 Espresso.pressBack()364 Espresso.onView(withId(R.id.main_OpenMenu))365 .perform(ViewActions.click())366 Espresso.onView(withId(R.id.main_SignOut))367 .perform(ViewActions.click())368 Thread.sleep(2500)369 }370}...

Full Screen

Full Screen

MainActivityTest2.kt

Source:MainActivityTest2.kt Github

copy

Full Screen

...27 var mActivityTestRule = ActivityTestRule(MainActivity::class.java)28 @Test29 fun mainActivityTest2() {30 val viewPager = Espresso.onView(31 Matchers.allOf(ViewMatchers.withId(R.id.pager1),32 childAtPosition(33 Matchers.allOf(ViewMatchers.withId(R.id.activity_main),34 childAtPosition(35 ViewMatchers.withId(R.id.content_frame),36 0)),37 1),38 ViewMatchers.isDisplayed()))39 viewPager.perform(ViewActions.swipeLeft())40 val viewPager2 = Espresso.onView(41 Matchers.allOf(ViewMatchers.withId(R.id.pager1),42 childAtPosition(43 Matchers.allOf(ViewMatchers.withId(R.id.activity_main),44 childAtPosition(45 ViewMatchers.withId(R.id.content_frame),46 0)),47 1),48 ViewMatchers.isDisplayed()))49 viewPager2.perform(ViewActions.swipeRight())50 Espresso.openActionBarOverflowOrOptionsMenu(InstrumentationRegistry.getInstrumentation().targetContext)51 val appCompatTextView = Espresso.onView(52 Matchers.allOf(ViewMatchers.withId(R.id.title), ViewMatchers.withText("Settings"),53 childAtPosition(54 childAtPosition(55 ViewMatchers.withId(R.id.content),56 0),57 0),58 ViewMatchers.isDisplayed()))59 appCompatTextView.perform(ViewActions.click())60 val floatingActionButton = Espresso.onView(61 Matchers.allOf(ViewMatchers.withId(R.id.fab),62 childAtPosition(63 childAtPosition(64 ViewMatchers.withId(R.id.drawer_layout),65 0),66 2),67 ViewMatchers.isDisplayed()))68 floatingActionButton.perform(ViewActions.click())69 val snackbarLayout = Espresso.onView(70 Matchers.allOf(childAtPosition(71 childAtPosition(72 ViewMatchers.withId(R.id.drawer_layout),73 0),74 3),75 ViewMatchers.isDisplayed()))76 snackbarLayout.perform(ViewActions.click())77 val appCompatImageButton = Espresso.onView(78 Matchers.allOf(ViewMatchers.withContentDescription("Open navigation drawer"),79 childAtPosition(80 Matchers.allOf(ViewMatchers.withId(R.id.toolbar),81 childAtPosition(82 ViewMatchers.withClassName(Matchers.`is`("android.support.design.widget.AppBarLayout")),83 0)),84 1),85 ViewMatchers.isDisplayed()))86 appCompatImageButton.perform(ViewActions.click())87 val navigationMenuItemView = Espresso.onView(88 Matchers.allOf(childAtPosition(89 Matchers.allOf(ViewMatchers.withId(R.id.design_navigation_view),90 childAtPosition(91 ViewMatchers.withId(R.id.nav_view),92 0)),93 1),94 ViewMatchers.isDisplayed()))95 navigationMenuItemView.perform(ViewActions.click())96 val appCompatImageButton2 = Espresso.onView(97 Matchers.allOf(ViewMatchers.withContentDescription("Open navigation drawer"),98 childAtPosition(99 Matchers.allOf(ViewMatchers.withId(R.id.toolbar),100 childAtPosition(101 ViewMatchers.withClassName(Matchers.`is`("android.support.design.widget.AppBarLayout")),102 0)),103 1),104 ViewMatchers.isDisplayed()))105 appCompatImageButton2.perform(ViewActions.click())106 val navigationMenuItemView2 = Espresso.onView(107 Matchers.allOf(childAtPosition(108 Matchers.allOf(ViewMatchers.withId(R.id.design_navigation_view),109 childAtPosition(110 ViewMatchers.withId(R.id.nav_view),111 0)),112 3),113 ViewMatchers.isDisplayed()))114 navigationMenuItemView2.perform(ViewActions.click())115 val appCompatImageButton3 = Espresso.onView(116 Matchers.allOf(ViewMatchers.withContentDescription("Open navigation drawer"),117 childAtPosition(118 Matchers.allOf(ViewMatchers.withId(R.id.toolbar),119 childAtPosition(120 ViewMatchers.withClassName(Matchers.`is`("android.support.design.widget.AppBarLayout")),121 0)),122 1),123 ViewMatchers.isDisplayed()))124 appCompatImageButton3.perform(ViewActions.click())125 val navigationMenuItemView3 = Espresso.onView(126 Matchers.allOf(childAtPosition(127 Matchers.allOf(ViewMatchers.withId(R.id.design_navigation_view),128 childAtPosition(129 ViewMatchers.withId(R.id.nav_view),130 0)),131 2),132 ViewMatchers.isDisplayed()))133 navigationMenuItemView3.perform(ViewActions.click())134 val appCompatImageButton1 = Espresso.onView(135 Matchers.allOf(ViewMatchers.withContentDescription("Open navigation drawer"),136 childAtPosition(137 Matchers.allOf(ViewMatchers.withId(R.id.toolbar),138 childAtPosition(139 ViewMatchers.withClassName(Matchers.`is`("android.support.design.widget.AppBarLayout")),140 0)),141 1),142 ViewMatchers.isDisplayed()))143 appCompatImageButton1.perform(ViewActions.click())144 Espresso.pressBack()145 }146 companion object {147 private fun childAtPosition(148 parentMatcher: Matcher<View>, position: Int): Matcher<View> {149 return object : TypeSafeMatcher<View>() {150 override fun describeTo(description: Description) {151 description.appendText("Child at position $position in parent ")...

Full Screen

Full Screen

ThemeSettingsTest.kt

Source:ThemeSettingsTest.kt Github

copy

Full Screen

...11import android.support.test.espresso.action.ViewActions.click12import android.support.test.espresso.assertion.ViewAssertions13import android.support.test.espresso.assertion.ViewAssertions.matches14import android.support.test.espresso.matcher.ViewMatchers15import android.support.test.espresso.matcher.ViewMatchers.withId16import android.support.test.espresso.matcher.ViewMatchers.withSpinnerText17import android.support.test.rule.ActivityTestRule18import android.support.test.runner.AndroidJUnit419import android.util.Log20import android.view.View21import android.widget.TextView22import org.hamcrest.CoreMatchers.anything23import org.hamcrest.CoreMatchers.containsString24import org.hamcrest.Matcher25import org.junit.Before26import org.junit.Rule27import org.junit.Test28import org.junit.runner.RunWith29@RunWith(AndroidJUnit4::class)30class ThemeSettingsTest {31 @Rule32 @JvmField33 var activityRule: ActivityTestRule<MainActivity> =34 ActivityTestRule(MainActivity::class.java)35 private lateinit var startValue: String36 private lateinit var nextValue: String37 @Before38 fun setBotClockStatValues() {39 startValue = getText(onView(withId(R.id.bot_clock)))40 val parts = startValue.split(":")41 var min = parts[0].toInt()42 var sec = parts[1].toInt()43 Log.d(min.toString(), sec.toString())44 val timeInSec = (min*60 + sec)-145 min = timeInSec/6046 sec = timeInSec%6047 var minutes = min.toString()48 val seconds = sec.toString()49 if (minutes.length == 1){50 minutes = "0$minutes"51 }52 nextValue = "$minutes:$seconds"53 }54 private fun getText(matcher: ViewInteraction): String {55 var text = String()56 matcher.perform(object : ViewAction {57 override fun getConstraints(): Matcher<View> {58 return ViewMatchers.isAssignableFrom(TextView::class.java)59 }60 override fun getDescription(): String {61 return "Text of the view"62 }63 override fun perform(uiController: UiController, view: View) {64 val tv = view as TextView65 text = tv.text.toString()66 }67 })68 return text69 }70 // How to get string resources71 private fun getResourceString(id: Int): String? {72 val targetContext: Context = InstrumentationRegistry.getTargetContext()73 return targetContext.getResources().getString(id)74 }75 @Test76 fun test_selfStart_option_onTop() {77 Espresso.onView(ViewMatchers.withId(R.id.settings_button)).perform(click())78 Espresso.onView(ViewMatchers.withText(getResourceString(R.string.themeStr)))79 .perform(click())80 Espresso.onView(ViewMatchers.withId(R.id.self_start_check)).perform(click())81 Espresso.pressBack()82 Espresso.onView(ViewMatchers.withId(R.id.top_sq)).perform(click())83 Espresso.onView(ViewMatchers.withId(R.id.top_clock))84 .check(ViewAssertions.matches(ViewMatchers.withText(nextValue)))85 Espresso.onView(ViewMatchers.withId(R.id.settings_button)).perform(click())86 Espresso.onView(ViewMatchers.withText(getResourceString(R.string.themeStr)))87 .perform(click())88 Espresso.onView(ViewMatchers.withId(R.id.self_start_check)).perform(click())89 }90 @Test91 fun test_selfStart_option_onBot() {92 Espresso.onView(ViewMatchers.withId(R.id.settings_button)).perform(click())93 Espresso.onView(ViewMatchers.withText(getResourceString(R.string.themeStr)))94 .perform(click())95 Espresso.onView(ViewMatchers.withId(R.id.self_start_check)).perform(click())96 Espresso.pressBack()97 Espresso.onView(ViewMatchers.withId(R.id.bot_sq)).perform(click())98 Espresso.onView(ViewMatchers.withId(R.id.bot_clock))99 .check(ViewAssertions.matches(ViewMatchers.withText(nextValue)))100 Espresso.onView(ViewMatchers.withId(R.id.settings_button)).perform(click())101 Espresso.onView(ViewMatchers.withText(getResourceString(R.string.themeStr)))102 .perform(click())103 Espresso.onView(ViewMatchers.withId(R.id.self_start_check)).perform(click())104 }105 @Test106 fun test_dark_mode() {107 Espresso.onView(ViewMatchers.withId(R.id.settings_button)).perform(click())108 Espresso.onView(ViewMatchers.withText(getResourceString(R.string.themeStr)))109 .perform(click())110 Espresso.onView(ViewMatchers.withId(R.id.action_theme)).perform(click())111 Espresso.onView(ViewMatchers.withId(R.id.action_theme)).perform(click())112 }113 @Test114 fun test_sound_selection() {115 Espresso.onView(ViewMatchers.withId(R.id.settings_button)).perform(click())116 Espresso.onView(ViewMatchers.withText(getResourceString(R.string.themeStr)))117 .perform(click())118 Espresso.onView(ViewMatchers.withId(R.id.drop_down)).perform(click())119 onData(anything()).atPosition(1).perform(click());120 onView(withId(R.id.drop_down)).check(121 matches(122 withSpinnerText(123 containsString(124 getResourceString(R.string.clearTroatStr)125 )126 )127 )128 );129 Espresso.pressBack()130 Espresso.onView(ViewMatchers.withId(R.id.bot_sq)).perform(click())131 Espresso.onView(ViewMatchers.withId(R.id.settings_button)).perform(click())132 Espresso.onView(ViewMatchers.withText(getResourceString(R.string.themeStr)))133 .perform(click())134 Espresso.onView(ViewMatchers.withId(R.id.drop_down)).perform(click())135 onData(anything()).atPosition(2).perform(click());136 onView(withId(R.id.drop_down)).check(137 matches(138 withSpinnerText(139 containsString(140 getResourceString(R.string.mechClickStr)141 )142 )143 )144 );145 Espresso.pressBack()146 Espresso.onView(ViewMatchers.withId(R.id.top_sq)).perform(click())147 }148}...

Full Screen

Full Screen

BaseRobot.kt

Source:BaseRobot.kt Github

copy

Full Screen

...28 }29 }30 }31 fun assertText(@IdRes id: Int, message: String): ViewInteraction =32 Espresso.onView(CoreMatchers.allOf(ViewMatchers.withId(id), ViewMatchers.isDisplayed()))33 .check(ViewAssertions.matches(ViewMatchers.withText(message)))34 fun componentInList(component: Matcher<View>, list: Matcher<View>, index: Int): ViewInteraction {35 return Espresso.onView(Matchers.allOf(component, ViewMatchers.isDescendantOfA(childAtPosition(list, index))))36 }37 fun componentInTagged(component: Matcher<View>, tagValue: Matcher<Any>): ViewInteraction {38 return Espresso.onView(Matchers.allOf(component, ViewMatchers.isDescendantOfA(ViewMatchers.withTagValue(tagValue))))39 }40 fun componentInTagged(component: Matcher<View>, key: Int, tagValue: Matcher<Any>): ViewInteraction {41 return Espresso.onView(Matchers.allOf(component, ViewMatchers.isDescendantOfA(ViewMatchers.withTagKey(key, tagValue))))42 }43 fun scrollTo(list: Matcher<View>, item: Matcher<View>) {44 Espresso.onView(list).perform(RecyclerViewActions.scrollTo<RecyclerView.ViewHolder>(item))45 }46 fun scrollTo(item: Matcher<View>) {47 scrollTo(ViewMatchers.withId(R.id.list), item)48 }49 fun scrollToPosition(list: Matcher<View>, position: Int) {50 Espresso.onView(list).perform(RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(position))51 }52 fun scrollToPosition(position: Int) {53 scrollToPosition(ViewMatchers.withId(R.id.list), position)54 }55 fun getTextByTag(@IdRes id: Int, tag: String) = componentInTagged(ViewMatchers.withId(id), R.id.tag_test, Matchers.equalTo(tag))56 fun assertDialogText(title: Matcher<String>, message: Matcher<String>) {57 Espresso.onView(ViewMatchers.withId(R.id.md_title)).check(ViewAssertions.matches(ViewMatchers.withText(title)))58 Espresso.onView(ViewMatchers.withId(R.id.md_content)).check(ViewAssertions.matches(ViewMatchers.withText(message)))59 }60 fun assertDialogText(title: Int, message: Matcher<String>) {61 Espresso.onView(ViewMatchers.withId(R.id.md_title)).check(ViewAssertions.matches(ViewMatchers.withText(title)))62 Espresso.onView(ViewMatchers.withId(R.id.md_content)).check(ViewAssertions.matches(ViewMatchers.withText(message)))63 }64 fun assertDialogText(title: Int, message: Int) {65 Espresso.onView(ViewMatchers.withId(R.id.md_title)).check(ViewAssertions.matches(ViewMatchers.withText(title)))66 Espresso.onView(ViewMatchers.withId(R.id.md_content)).check(ViewAssertions.matches(ViewMatchers.withText(message)))67 }68 fun assertNeutralText(text: Matcher<String>) {69 Espresso.onView(ViewMatchers.withId(R.id.md_buttonDefaultNeutral)).check(ViewAssertions.matches(ViewMatchers.withText(text)))70 }71 fun assertNeutralNotVisible() {72 Espresso.onView(ViewMatchers.withId(R.id.md_buttonDefaultNeutral)).check(ViewAssertions.matches(Matchers.not(ViewMatchers.isDisplayed())))73 }74 fun clickDialogPositive() {75 clickButton(R.id.md_buttonDefaultPositive)76 }77 fun clickDialogNeutral() {78 clickButton(R.id.md_buttonDefaultNeutral)79 }80 fun clickDialogNegative() {81 clickButton(R.id.md_buttonDefaultNegative)82 }83 fun clickPromptCheckbox() {84 clickButton(R.id.md_promptCheckbox)85 }86 fun clickButton(@IdRes id: Int) {87 Espresso.onView(ViewMatchers.withId(id)).perform(ViewActions.click())88 }89 fun sleep(ms: Long) {90 SystemClock.sleep(ms)91 }92 fun pressBack() {93 Espresso.closeSoftKeyboard()94 val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())95 mDevice.pressBack()96 }97}...

Full Screen

Full Screen

MainActivityTest.kt

Source:MainActivityTest.kt Github

copy

Full Screen

...23 var mRuntimePermissionRule = GrantPermissionRule24 .grant(android.Manifest.permission.ACCESS_FINE_LOCATION)25 @Test26 fun mainActivityExchangeCoin() {27 Espresso.onView(ViewMatchers.withId(R.id.main_OpenMenu))28 .perform(ViewActions.click())29 Espresso.onView(ViewMatchers.withId(R.id.main_Bank))30 .perform(ViewActions.click())31 Espresso.onView((ViewMatchers.withId(R.id.coinExchange)))32 .perform(ViewActions.click())33 }34 @Test35 fun mainActivityWagerNoGold() {36 Espresso.onView(ViewMatchers.withId(R.id.main_OpenMenu))37 .perform(ViewActions.click())38 Espresso.onView(ViewMatchers.withId(R.id.main_Race))39 .perform(ViewActions.click())40 Espresso.onView(ViewMatchers.withId(R.id.race_WagerButton))41 .perform(ViewActions.click())42 /*Espresso.onView(ViewMatchers.withId(R.id.main_WagerTextView))43 .check(matches(isDisplayed()))*/44 Espresso.onView(ViewMatchers.withId(R.id.race_WagerTextView))45 .check(matches(withText("You don't have enough GOLD")))46 }47 @Test48 fun mainActivityAlreadyWagered() {49 Espresso.onView(ViewMatchers.withId(R.id.go_to_login))50 .perform(ViewActions.click())51 Espresso.onView(ViewMatchers.withId(R.id.login_email))52 .perform(ViewActions.replaceText("EspressoEmail@gmail.com"))53 Espresso.onView(ViewMatchers.withId(R.id.login_password))54 .perform(ViewActions.replaceText("EspressoPassword"))55 Espresso.onView(ViewMatchers.withId(R.id.email_sign_in_button))56 .perform(ViewActions.click())57 Thread.sleep(5000)58 Espresso.onView(ViewMatchers.withId(R.id.main_OpenMenu))59 .perform(ViewActions.click())60 Espresso.onView(ViewMatchers.withId(R.id.main_Race))61 .perform(ViewActions.click())62 Espresso.onView(ViewMatchers.withId(R.id.race_WagerButton))63 .perform(ViewActions.click())64 Espresso.onView(ViewMatchers.withId(R.id.race_WagerTextView))65 .check(matches(withText("You have already wagered today")))66 }67 @Test68 fun mainActiviRerollQuest() {69 Espresso.onView(ViewMatchers.withId(R.id.main_OpenMenu))70 .perform(ViewActions.click())71 Espresso.onView(ViewMatchers.withId(R.id.main_Quest))72 .perform(ViewActions.click())73 Espresso.onView(ViewMatchers.withId(R.id.quest_rerollButton))74 .perform(ViewActions.click())75 Thread.sleep(1000)76 Espresso.onView(ViewMatchers.withId(R.id.quest_rerollButton))77 .check(matches(not(isEnabled())))78 }79 @Test80 fun mainActivitySpinnerSelect() {81 Espresso.onView(ViewMatchers.withId(R.id.main_OpenMenu))82 .perform(ViewActions.click())83 Espresso.onView(ViewMatchers.withId(R.id.main_Race))84 .perform(ViewActions.click())85 Espresso.onView(ViewMatchers.withId(R.id.race_TimeSpinner))86 .perform(ViewActions.click())87 Espresso.onData(hasToString(startsWith("30")))88 .perform(ViewActions.click())89 }90}...

Full Screen

Full Screen

SignUpActivityTest1.kt

Source:SignUpActivityTest1.kt Github

copy

Full Screen

...22 var mRuntimePermissionRule = GrantPermissionRule23 .grant(android.Manifest.permission.ACCESS_FINE_LOCATION)24 @Test25 fun signUpActivityTestNoCredentials() {26 Espresso.onView(ViewMatchers.withId(R.id.email_sign_up_button))27 .perform(ViewActions.click())28 Espresso.onView(ViewMatchers.withId(R.id.signup_username))29 .check(matches(hasErrorText("This username is too short")))30 }31 @Test32 fun signUpActivityTestOnlyUsername() {33 Espresso.onView(ViewMatchers.withId(R.id.signup_username))34 .perform(ViewActions.replaceText("EspressoUsername"))35 Espresso.onView(ViewMatchers.withId(R.id.email_sign_up_button))36 .perform(ViewActions.click())37 Espresso.onView(ViewMatchers.withId(R.id.signup_email))38 .check(matches(hasErrorText("This field is required")))39 }40 @Test41 fun signUpActivityTestNoPassword() {42 Espresso.onView(ViewMatchers.withId(R.id.signup_username))43 .perform(ViewActions.replaceText("EspressoUsername"))44 Espresso.onView(ViewMatchers.withId(R.id.signup_email))45 .perform(ViewActions.replaceText("EspressoEmail@gmail.com"))46 Espresso.onView(ViewMatchers.withId(R.id.email_sign_up_button))47 .perform(ViewActions.click())48 Espresso.onView(ViewMatchers.withId(R.id.signup_password))49 .check(matches(hasErrorText("This password is too short")))50 }51 @Test52 fun signUpActivityTestInvalidEmail() {53 Espresso.onView(ViewMatchers.withId(R.id.signup_username))54 .perform(ViewActions.replaceText("EspressoUsername"))55 Espresso.onView(ViewMatchers.withId(R.id.signup_password))56 .perform(ViewActions.replaceText("EspressoPassword"))57 Espresso.onView(ViewMatchers.withId(R.id.signup_email))58 .perform(ViewActions.replaceText("EspressoEmailgmail.com"))59 Espresso.onView(ViewMatchers.withId(R.id.email_sign_up_button))60 .perform(ViewActions.click())61 Espresso.onView(ViewMatchers.withId(R.id.signup_email))62 .check(matches(hasErrorText("This email address is invalid")))63 }64 @Test65 fun signUpActivityTestValidRegister() {66 Espresso.onView(ViewMatchers.withId(R.id.signup_username))67 .perform(ViewActions.replaceText("EspressoUsername"))68 Espresso.onView(ViewMatchers.withId(R.id.signup_password))69 .perform(ViewActions.replaceText("EspressoPassword"))70 Espresso.onView(ViewMatchers.withId(R.id.signup_email))71 .perform(ViewActions.replaceText("EspressoEmail@gmail.com"))72 Espresso.onView(ViewMatchers.withId(R.id.email_sign_up_button))73 .perform(ViewActions.click())74 Thread.sleep(15000)75 Espresso.onView(ViewMatchers.withId(R.id.main_OpenMenu))76 .perform(ViewActions.click())77 }78}...

Full Screen

Full Screen

TestSkenario.kt

Source:TestSkenario.kt Github

copy

Full Screen

...27 @Test28 fun behaviorTest(){29 Thread.sleep(3000)30 val recyclerView = Espresso.onView(31 Matchers.allOf(ViewMatchers.withId(R.id.rv),32 ViewMatchers.isDisplayed()))33 recyclerView.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))34 recyclerView35 .perform(RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(8))36 .perform(RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(7, ViewActions.click()))37 Thread.sleep(3000)38 Espresso.onView(ViewMatchers.withId(add_to_favorite)).perform(ViewActions.click())39 Espresso.pressBack()40 Espresso.onView(ViewMatchers.withId(fav)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))41 .perform(ViewActions.click())42 recyclerView.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))43 recyclerView44 .perform(RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(0, ViewActions.click()))45 Espresso.onView(ViewMatchers.withId(add_to_favorite)).perform(ViewActions.click())46 Espresso.pressBack()47 Thread.sleep(1000)48 val linearLayout3 = Espresso.onView(49 Matchers.allOf(childAtPosition(50 childAtPosition(51 ViewMatchers.withId(R.id.rv),52 0),53 0),54 ViewMatchers.isDisplayed()))55 linearLayout3.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))56 }57 private fun childAtPosition(58 parentMatcher: Matcher<View>, position: Int): Matcher<View> {59 return object : TypeSafeMatcher<View>() {60 override fun describeTo(description: Description) {61 description.appendText("Child at position $position in parent ")62 parentMatcher.describeTo(description)63 }64 public override fun matchesSafely(view: View): Boolean {65 val parent = view.parent...

Full Screen

Full Screen

LoginActivityTest.kt

Source:LoginActivityTest.kt Github

copy

Full Screen

...22 var mRuntimePermissionRule = GrantPermissionRule23 .grant(android.Manifest.permission.ACCESS_FINE_LOCATION)24 @Test25 fun loginActivityTestNoCredentials() {26 Espresso.onView(ViewMatchers.withId(R.id.email_sign_in_button))27 .perform(ViewActions.click())28 Espresso.onView(ViewMatchers.withId(R.id.login_email))29 .check(matches(hasErrorText("This field is required")))30 }31 @Test32 fun loginActivityTestNoPassword() {33 Espresso.onView(ViewMatchers.withId(R.id.login_email))34 .perform(ViewActions.replaceText("EspressoEmail@gmail.com"))35 Espresso.onView(ViewMatchers.withId(R.id.email_sign_in_button))36 .perform(ViewActions.click())37 Espresso.onView(ViewMatchers.withId(R.id.login_password))38 .check(matches(hasErrorText("This password is too short")))39 }40 @Test41 fun loginActivityInvalidEmail() {42 Espresso.onView(ViewMatchers.withId(R.id.login_email))43 .perform(ViewActions.replaceText("EspressoEmailgmail.com"))44 Espresso.onView(ViewMatchers.withId(R.id.email_sign_in_button))45 .perform(ViewActions.click())46 Espresso.onView(ViewMatchers.withId(R.id.login_email))47 .check(matches(hasErrorText("This email address is invalid")))48 }49 @Test50 fun loginActivityValidLogin() {51 Espresso.onView(ViewMatchers.withId(R.id.login_email))52 .perform(ViewActions.replaceText("EspressoEmail@gmail.com"))53 Espresso.onView(ViewMatchers.withId(R.id.login_password))54 .perform(ViewActions.replaceText("EspressoPassword"))55 Espresso.onView(ViewMatchers.withId(R.id.email_sign_in_button))56 .perform(ViewActions.click())57 Thread.sleep(5000)58 }59}...

Full Screen

Full Screen

withId

Using AI Code Generation

copy

Full Screen

1import android.support.test.espresso.matcher.ViewMatchers.withId;2import android.support.test.espresso.matcher.ViewMatchers.withText;3import org.hamcrest.Matchers.allOf;4import org.hamcrest.Matchers.is;5import org.hamcrest.Matchers.instanceOf;6import android.support.test.espresso.matcher.ViewMatchers.withId;7import android.support.test.espresso.matcher.ViewMatchers.withText;8import org.hamcrest.Matchers.allOf;9import org.hamcrest.Matchers.is;10import org.hamcrest.Matchers.instanceOf;11import android.support.test.espresso.matcher.ViewMatchers.withId;12import android.support.test.espresso.matcher.ViewMatchers.withText;13import org.hamcrest.Matchers.allOf;14import org.hamcrest.Matchers.is;15import org.hamcrest.Matchers.instanceOf;16import android.support.test.espresso.matcher.ViewMatchers.withId;17import android.support.test.espresso.matcher.ViewMatchers.withText;18import org.hamcrest.Matchers.allOf;19import org.hamcrest.Matchers.is;20import org.hamcrest.Matchers.instanceOf;21import android.support.test.espresso.matcher.ViewMatchers.withId;22import android.support.test.espresso.matcher.ViewMatchers.withText;

Full Screen

Full Screen

withId

Using AI Code Generation

copy

Full Screen

1import android.support.test.espresso.matcher.ViewMatchers.withId;2import android.support.test.espresso.matcher.ViewMatchers.isDisplayed;3import org.hamcrest.Matchers.allOf;4import org.hamcrest.Matchers.is;5import org.hamcrest.Matchers.hasToString;6import org.hamcrest.Matchers.anyOf;7import org.hamcrest.Matchers.not;8import org.hamcrest.Matchers.containsString;9import org.hamcrest.Matchers.instanceOf;10import org.hamcrest.Matchers.hasToString;11import org.hamcrest.Matchers.startsWith;12import org.hamcrest.Matchers.endsWith;13import org.hamcrest.Matchers.closeTo;14import org.hamcrest.Matchers.greaterThan;15import org.hamcrest.Matchers.lessThan;16import org.hamcrest.Matchers.greaterThanOrEqualTo;17import org.hamcrest.Matchers.lessThanOrEqualTo;18import org.hamcrest.Matc

Full Screen

Full Screen

withId

Using AI Code Generation

copy

Full Screen

1withId(R.id.button1).perform(click());2withId(R.id.button2).perform(click());3withId(R.id.button3).perform(click());4withId(R.id.button4).perform(click());5withId(R.id.button5).perform(click());6withId(R.id.button6).perform(click());7withId(R.id.button7).perform(click());8withId(R.id.button8).perform(click());9withId(R.id.button9).perform(click());10withId(R.id.button10).perform(click());11withId(R.id.button11).perform(click());12withId(R.id.button12).perform(click());13withId(R.id.button13).perform(click());14withId(R.id.button14).perform(click());15withId(R.id.button15).perform(click());16withId(R.id.button16).perform(click());17withId(R.id.button17).perform(click());18withId(R.id.button18).perform(click());19withId(R.id.button19).perform(click());

Full Screen

Full Screen

withId

Using AI Code Generation

copy

Full Screen

1withId(R.id.abc)2withText("abc")3withHint("abc")4withContentDescription("abc")5withTagValue(is("abc"))6withParent(withId(R.id.abc))7withChild(withText("abc"))8withParentIndex(0)9withParent(withId(R.id.abc))10withContentDescription("abc")11withTagValue(is("abc"))12withParent(withId(R.id.abc))13withChild(withText("abc"))14withParentIndex(0)15withParent(withId(R.id.abc))16withContentDescription("abc")17withTagValue(is("abc"))18withParent(withId(R.id.abc))19withChild(withText("abc"))20withParentIndex(0)21withParent(withId(R.id.abc))

Full Screen

Full Screen

withId

Using AI Code Generation

copy

Full Screen

1onView(withId(R.id.editText)).perform(typeText("Hello World"));2onView(withText("Hello World")).perform(click());3onView(withId(R.id.editText)).perform(clearText());4onView(withId(R.id.editText)).perform(replaceText("Hello World"));5onView(withId(R.id.editText)).perform(closeSoftKeyboard());6onView(withId(R.id.editText)).perform(pressImeActionButton());7onView(withId(R.id.editText)).perform(scrollTo());8onView(withId(R.id.editText)).perform(swipeDown());9onView(withId(R.id.editText)).perform(swipeLeft());10onView(withId(R.id.editText)).perform(swipeRight());11onView(withId(R.id.editText)).perform(swipeUp());12onView(withId(R.id.editText)).perform(longClick());13onView(withId(R.id.editText)).perform(click());14onView(withId(R.id.editText)).perform(doubleClick());15onView(withId(R.id.editText)).perform(longClick());16onView(withId(R.id.editText)).perform(click());17onView(withId(R.id.editText)).perform(doubleClick());

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful