Best Appium-espresso-driver code snippet using android.support.test.espresso.matcher.ViewMatchers.isDisplayed
MainActivityTest2.kt
Source:MainActivityTest2.kt
...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 ")152 parentMatcher.describeTo(description)153 }154 public override fun matchesSafely(view: View): Boolean {155 val parent = view.parent156 return (parent is ViewGroup && parentMatcher.matches(parent)...
NextLeagueTest.kt
Source:NextLeagueTest.kt
...6import android.support.test.espresso.contrib.RecyclerViewActions7import android.support.test.espresso.matcher.RootMatchers8import android.support.test.espresso.matcher.RootMatchers.withDecorView9import android.support.test.espresso.matcher.ViewMatchers10import android.support.test.espresso.matcher.ViewMatchers.isDisplayed11import android.support.test.espresso.matcher.ViewMatchers.withText12import android.support.test.rule.ActivityTestRule13import android.support.test.runner.AndroidJUnit414import android.support.v7.widget.RecyclerView15import com.example.root.finalproject.HomeActivity16import com.example.root.finalproject.R17import com.example.root.finalproject.R.id.*18import org.hamcrest.CoreMatchers.not19import org.hamcrest.Matchers20import org.junit.Rule21import org.junit.Test22import org.junit.runner.RunWith23@RunWith(AndroidJUnit4::class)24class NextLeagueTest {25 @Rule26 @JvmField27 var activityRule = ActivityTestRule(HomeActivity::class.java)28 @Test29 fun testRecyclerViewBehaviour() {30 onView(ViewMatchers.withText("NEXT MATCH")).perform(ViewActions.click())31 Thread.sleep(7000)32 onView(Matchers.allOf(ViewMatchers.withId(recycler_view_team), ViewMatchers.isDisplayed())).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))33 onView(Matchers.allOf(ViewMatchers.withId(recycler_view_team), ViewMatchers.isDisplayed())).perform(RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(8))34 onView(Matchers.allOf(ViewMatchers.withId(recycler_view_team), ViewMatchers.isDisplayed())).perform(RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(5, ViewActions.click()))35 }36 @Test37 fun testDetailBehaviour() {38 onView(ViewMatchers.withText("NEXT MATCH")).perform(ViewActions.click())39 Thread.sleep(7000)40 onView(Matchers.allOf(ViewMatchers.withId(recycler_view_team), ViewMatchers.isDisplayed())).perform(RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(1, ViewActions.click()))41 Thread.sleep(7000)42 onView(ViewMatchers.withId(date_events_detail)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))43 onView(ViewMatchers.withId(date_events_detail)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))44 onView(ViewMatchers.withId(ll_score_detail)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))45 onView(ViewMatchers.withId(image_home_detail)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))46 onView(ViewMatchers.withId(tv_image_home_detail)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))47 onView(ViewMatchers.withId(image_home_detail)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))48 onView(ViewMatchers.withId(score_detail)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))49 onView(ViewMatchers.withId(image_away_detail)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))50 onView(ViewMatchers.withId(tv_image_away_detail)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))51 onView(ViewMatchers.withId(date_events_detail)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))52 onView(ViewMatchers.withId(view_line_goals)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))53 onView(ViewMatchers.withId(home_goal_details)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))54 onView(ViewMatchers.withId(away_goal_details)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))55 onView(ViewMatchers.withId(view_line_goals)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))56 onView(ViewMatchers.withId(home_shots_detail)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))57 onView(ViewMatchers.withId(away_shots_detail)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))58 onView(ViewMatchers.withId(view_line_up_goals)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))59 onView(ViewMatchers.withId(line_ups)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))60 onView(ViewMatchers.withId(home_line_up_goal_keeper)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))61 onView(ViewMatchers.withId(away_line_up_goal_keeper)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))62 onView(ViewMatchers.withId(home_line_up_defense)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))63 onView(ViewMatchers.withId(away_line_up_defense)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))64 onView(ViewMatchers.withId(home_lineup_substitutes)).perform(ViewActions.scrollTo())65 Thread.sleep(2000)66 onView(ViewMatchers.withId(home_line_up_midfield)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))67 onView(ViewMatchers.withId(away_lineup_midfield)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))68 onView(ViewMatchers.withId(home_lineup_forward)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))69 onView(ViewMatchers.withId(away_lineup_forward)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))70 onView(ViewMatchers.withId(home_lineup_substitutes)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))71 onView(ViewMatchers.withId(away_lineup_substitutes)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))72 }73 @Test74 fun testTeamNextLeagueFavoriteBehaviour() {75 onView(ViewMatchers.withText("NEXT MATCH")).perform(ViewActions.click())76 Thread.sleep(7000)77 onView(Matchers.allOf(ViewMatchers.withId(recycler_view_team), ViewMatchers.isDisplayed())).perform(RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(2, ViewActions.click()))78 Thread.sleep(7000)79 onView(ViewMatchers.withId(add_to_favorite)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))80 onView(ViewMatchers.withId(add_to_favorite)).perform(ViewActions.click())81 onView(ViewMatchers.withText("Added to Favorite"))82 .inRoot(RootMatchers.withDecorView(Matchers.not(activityRule.activity.window.decorView)))83 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))84 Thread.sleep(4000)85 onView(ViewMatchers.withId(add_to_favorite)).perform(ViewActions.click())86 onView(ViewMatchers.withText("Removed to Favorite"))87 .inRoot(RootMatchers.withDecorView(Matchers.not(activityRule.activity.window.decorView)))88 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))89 Thread.sleep(4000)90 onView(ViewMatchers.withId(add_to_favorite)).perform(ViewActions.click())91 onView(ViewMatchers.withText("Added to Favorite"))92 .inRoot(RootMatchers.withDecorView(Matchers.not(activityRule.activity.window.decorView)))93 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))94 Thread.sleep(4000)95 onView(ViewMatchers.withContentDescription(R.string.abc_action_bar_up_description)).perform(ViewActions.click())96 onView(ViewMatchers.withId(bottom_navigation)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))97 onView(ViewMatchers.withId(favorites)).perform(ViewActions.click())98 Thread.sleep(2000)99 onView(ViewMatchers.withText("MATCHES")).perform(ViewActions.click())100 onView(Matchers.allOf(ViewMatchers.withId(rv_favorite), ViewMatchers.isDisplayed())).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))101 onView(Matchers.allOf(ViewMatchers.withId(rv_favorite), ViewMatchers.isDisplayed())).perform(RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(0, ViewActions.click()))102 Thread.sleep(6000)103 onView(ViewMatchers.withId(add_to_favorite)).perform(ViewActions.click())104 onView(withText("Removed to Favorite"))105 .inRoot(withDecorView(not(activityRule.activity.window.decorView)))106 .check(matches(isDisplayed()))107 }108}
InputCodeActivityInstrumentedTest.kt
Source:InputCodeActivityInstrumentedTest.kt
...31 @Test32 fun check0to4Buttons() {33 SystemClock.sleep(100)34 Espresso.onView(ViewMatchers.withId(R.id.bt_0))35 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))36 .perform(ViewActions.click())37 Espresso.onView(ViewMatchers.withId(R.id.bt_1))38 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))39 .perform(ViewActions.click())40 Espresso.onView(ViewMatchers.withId(R.id.bt_2))41 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))42 .perform(ViewActions.click())43 Espresso.onView(ViewMatchers.withId(R.id.bt_3))44 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))45 .perform(ViewActions.click())46 Espresso.onView(ViewMatchers.withId(R.id.bt_4))47 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))48 .perform(ViewActions.click())49 Espresso.onView(Matchers.allOf(ViewMatchers.withId(R.id.tv_code), ViewMatchers.withText("0 1 2 3 4 ")))50 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))51 }52 @Test53 fun check5to9Buttons() {54 SystemClock.sleep(100)55 Espresso.onView(ViewMatchers.withId(R.id.bt_5))56 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))57 .perform(ViewActions.click())58 Espresso.onView(ViewMatchers.withId(R.id.bt_6))59 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))60 .perform(ViewActions.click())61 Espresso.onView(ViewMatchers.withId(R.id.bt_7))62 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))63 .perform(ViewActions.click())64 Espresso.onView(ViewMatchers.withId(R.id.bt_8))65 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))66 .perform(ViewActions.click())67 Espresso.onView(ViewMatchers.withId(R.id.bt_9))68 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))69 .perform(ViewActions.click())70 Espresso.onView(Matchers.allOf(ViewMatchers.withId(R.id.tv_code), ViewMatchers.withText("5 6 7 8 9 ")))71 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))72 }73 @Test74 fun checkBackButton() {75 SystemClock.sleep(100)76 Espresso.onView(ViewMatchers.withId(R.id.bt_back))77 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))78 .perform(ViewActions.click())79 Espresso.onView(ViewMatchers.withId(R.id.bt_5))80 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))81 .perform(ViewActions.click())82 Espresso.onView(ViewMatchers.withId(R.id.bt_6))83 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))84 .perform(ViewActions.click())85 Espresso.onView(ViewMatchers.withId(R.id.bt_back))86 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))87 .perform(ViewActions.click())88 Espresso.onView(ViewMatchers.withId(R.id.bt_8))89 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))90 .perform(ViewActions.click())91 Espresso.onView(ViewMatchers.withId(R.id.bt_9))92 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))93 .perform(ViewActions.click())94 Espresso.onView(ViewMatchers.withId(R.id.bt_back))95 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))96 .perform(ViewActions.click())97 Espresso.onView(Matchers.allOf(ViewMatchers.withId(R.id.tv_code), ViewMatchers.withText("5 8 ")))98 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))99 }100 @Test101 fun goLoginregisterOn6DigitsClickWithCorrectData() {102 Intents.init()103 SystemClock.sleep(100)104 Espresso.onView(ViewMatchers.withId(R.id.bt_6))105 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))106 .perform(ViewActions.click())107 Espresso.onView(ViewMatchers.withId(R.id.bt_5))108 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))109 .perform(ViewActions.click())110 Espresso.onView(ViewMatchers.withId(R.id.bt_4))111 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))112 .perform(ViewActions.click())113 Espresso.onView(ViewMatchers.withId(R.id.bt_3))114 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))115 .perform(ViewActions.click())116 Espresso.onView(ViewMatchers.withId(R.id.bt_2))117 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))118 .perform(ViewActions.click())119 Espresso.onView(ViewMatchers.withId(R.id.bt_1))120 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))121 .perform(ViewActions.click())122 SystemClock.sleep(3500)123 Intents.intended(IntentMatchers.hasComponent(LoginRegisterActivity::class.java.name))124 Intents.release()125 }126}...
LoginActivityInstrumentedTest.kt
Source:LoginActivityInstrumentedTest.kt
...27 Intents.init()28 try {29 SystemClock.sleep(100)30 Espresso.onView(ViewMatchers.withId(R.id.et_email))31 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))32 .perform(replaceText("test@email.com"))33 SystemClock.sleep(100)34 Espresso.onView(ViewMatchers.withId(R.id.et_pass))35 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))36 .perform(replaceText("12345"))37 SystemClock.sleep(100)38 Espresso.onView(ViewMatchers.withId(R.id.bt_login))39 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))40 .perform(ViewActions.click())41 SystemClock.sleep(1500)42 Intents.intended(IntentMatchers.hasComponent(MainActivity::class.java.name))43 } finally {44 Intents.release()45 }46 }47 @Test48 fun showErrorOnLoginClickWithBadMail() {49 SystemClock.sleep(200)50 Espresso.onView(ViewMatchers.withId(R.id.et_email))51 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))52 .perform(replaceText("test@email"))53 SystemClock.sleep(100)54 Espresso.onView(ViewMatchers.withId(R.id.et_pass))55 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))56 .perform(replaceText("12345"))57 SystemClock.sleep(100)58 Espresso.onView(ViewMatchers.withId(R.id.bt_login))59 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))60 .perform(ViewActions.click())61 SystemClock.sleep(200)62 Espresso.onView(ViewMatchers.withId(R.id.et_email))63 .check(matches(hasErrorText("Invalid email format")))64 }65 @Test66 fun showErrorOnLoginClickWithNoMail() {67 Espresso.onView(ViewMatchers.withId(R.id.et_email))68 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))69 .perform(replaceText(""))70 SystemClock.sleep(100)71 Espresso.onView(ViewMatchers.withId(R.id.et_pass))72 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))73 .perform(replaceText("12345"))74 SystemClock.sleep(100)75 Espresso.onView(ViewMatchers.withId(R.id.bt_login))76 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))77 .perform(ViewActions.click())78 SystemClock.sleep(200)79 Espresso.onView(ViewMatchers.withId(R.id.et_email))80 .check(matches(hasErrorText("Invalid email format")))81 }82 @Test83 fun showErrorOnLoginClickWithNoPass() {84 Espresso.onView(ViewMatchers.withId(R.id.et_email))85 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))86 .perform(replaceText("test@email.com"))87 SystemClock.sleep(100)88 Espresso.onView(ViewMatchers.withId(R.id.et_pass))89 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))90 .perform(replaceText(""))91 SystemClock.sleep(100)92 Espresso.onView(ViewMatchers.withId(R.id.bt_login))93 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))94 .perform(ViewActions.click())95 Espresso.onView(ViewMatchers.withId(R.id.et_pass))96 .check(matches(hasErrorText("Password cannot be empty")))97 }98 @Test99 fun forgotDialogOpensAndCloses() {100 Espresso.onView(ViewMatchers.withId(R.id.et_email))101 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))102 .perform(replaceText("test@email.com"))103 SystemClock.sleep(100)104 Espresso.onView(ViewMatchers.withId(R.id.et_pass))105 .perform(setFocus())106 val btForgot = Espresso.onView(ViewMatchers.withId(R.id.bt_forgot))107 btForgot.check(matches(ViewMatchers.isDisplayed()))108 btForgot.perform(ViewActions.click())109 Espresso.onView(ViewMatchers.withText(R.string.confirm_pass_change)).check(matches(ViewMatchers.isDisplayed()))110 val cancelButton = Espresso.onView(ViewMatchers.withText(R.string.cancel))111 cancelButton.perform(ViewActions.click())112 Espresso.onView(ViewMatchers.withText(R.string.confirm_pass_change)).check(ViewAssertions.doesNotExist())113 }114 @Test115 fun forgotDialogOpensInputCodeActivity() {116 Intents.init()117 Espresso.onView(ViewMatchers.withId(R.id.et_email))118 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))119 .perform(replaceText("test@email.com"))120 SystemClock.sleep(100)121 Espresso.onView(ViewMatchers.withId(R.id.et_pass))122 .perform(setFocus())123 val btForgot = Espresso.onView(ViewMatchers.withId(R.id.bt_forgot))124 btForgot.check(matches(ViewMatchers.isDisplayed()))125 btForgot.perform(ViewActions.click())126 Espresso.onView(ViewMatchers.withText(R.string.confirm_pass_change)).check(matches(ViewMatchers.isDisplayed()))127 val confirmButton = Espresso.onView(ViewMatchers.withText(R.string.confirm))128 confirmButton.perform(ViewActions.click())129 Intents.intended(IntentMatchers.hasComponent(ChangePassActivity::class.java.name))130 Intents.release()131 }132}...
TeamsTest.kt
Source:TeamsTest.kt
...6import android.support.test.espresso.assertion.ViewAssertions.matches7import android.support.test.espresso.contrib.RecyclerViewActions8import android.support.test.espresso.matcher.RootMatchers9import android.support.test.espresso.matcher.ViewMatchers10import android.support.test.espresso.matcher.ViewMatchers.isDisplayed11import android.support.test.espresso.matcher.ViewMatchers.withId12import android.support.test.rule.ActivityTestRule13import android.support.test.runner.AndroidJUnit414import android.support.v7.widget.RecyclerView15import com.example.root.finalproject.HomeActivity16import com.example.root.finalproject.R17import com.example.root.finalproject.R.id.*18import org.hamcrest.CoreMatchers19import org.hamcrest.Matchers20import org.junit.Rule21import org.junit.Test22import org.junit.runner.RunWith23@RunWith(AndroidJUnit4::class)24class TeamsTest {25 @Rule26 @JvmField27 var activityRule = ActivityTestRule(HomeActivity::class.java)28 @Test29 fun testRecyclerViewBehaviour() {30 Thread.sleep(2000)31 onView(withId(bottom_navigation)).check(matches(isDisplayed()))32 onView(withId(teams)).perform(click())33 Thread.sleep(7000)34 onView(withId(list_event)).check(matches(isDisplayed()))35 onView(withId(list_event)).perform(RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(4))36 onView(withId(list_event)).perform(RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(3, click()))37 }38 @Test39 fun testPlayerBehaviour() {40 Thread.sleep(2000)41 onView(withId(teams)).perform(click())42 Thread.sleep(7000)43 onView(withId(list_event)).perform(RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(3, click()))44 Thread.sleep(7000)45 onView(ViewMatchers.withText("PLAYERS")).perform(ViewActions.click())46 Thread.sleep(7000)47 onView(withId(rv_players)).perform(RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(3))48 onView(withId(rv_players)).perform(RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(1, click()))49 }50 @Test51 fun testDetailTeamBehaviour() {52 Thread.sleep(2000)53 onView(withId(teams)).perform(click())54 Thread.sleep(7000)55 onView(withId(list_event)).perform(RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(3, click()))56 Thread.sleep(7000)57 onView(ViewMatchers.withId(add_to_favorite)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))58 onView(ViewMatchers.withId(add_to_favorite)).perform(ViewActions.click())59 onView(ViewMatchers.withText("Added to Favorite"))60 .inRoot(RootMatchers.withDecorView(Matchers.not(activityRule.activity.window.decorView)))61 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))62 Thread.sleep(4000)63 onView(ViewMatchers.withId(add_to_favorite)).perform(ViewActions.click())64 onView(ViewMatchers.withText("Removed to Favorite"))65 .inRoot(RootMatchers.withDecorView(Matchers.not(activityRule.activity.window.decorView)))66 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))67 Thread.sleep(4000)68 onView(ViewMatchers.withId(add_to_favorite)).perform(ViewActions.click())69 onView(ViewMatchers.withText("Added to Favorite"))70 .inRoot(RootMatchers.withDecorView(Matchers.not(activityRule.activity.window.decorView)))71 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))72 Thread.sleep(4000)73 onView(ViewMatchers.withContentDescription(R.string.abc_action_bar_up_description)).perform(ViewActions.click())74 onView(ViewMatchers.withId(bottom_navigation)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))75 onView(ViewMatchers.withId(favorites)).perform(ViewActions.click())76 Thread.sleep(2000)77 onView(ViewMatchers.withText("TEAMS")).perform(ViewActions.click())78 onView(Matchers.allOf(ViewMatchers.withId(rv_favorite), ViewMatchers.isDisplayed())).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))79 onView(Matchers.allOf(ViewMatchers.withId(rv_favorite), ViewMatchers.isDisplayed())).perform(RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(0, ViewActions.click()))80 Thread.sleep(6000)81 onView(ViewMatchers.withId(add_to_favorite)).perform(ViewActions.click())82 onView(ViewMatchers.withText("Removed to Favorite"))83 .inRoot(RootMatchers.withDecorView(CoreMatchers.not(activityRule.activity.window.decorView)))84 .check(matches(isDisplayed()))85 onView(ViewMatchers.withContentDescription(R.string.abc_action_bar_up_description)).perform(ViewActions.click())86 }87}...
HighscoreFragmentTest.kt
Source:HighscoreFragmentTest.kt
1package com.jakelaurie.colormemory2import android.support.test.espresso.Espresso.onView3import android.support.test.espresso.assertion.ViewAssertions.matches4import android.support.test.espresso.matcher.ViewMatchers5import android.support.test.espresso.matcher.ViewMatchers.isDisplayed6import android.support.test.espresso.matcher.ViewMatchers.withText7import android.support.test.rule.ActivityTestRule8import com.jakelaurie.colormemory.base.DBTest9import com.jakelaurie.colormemory.base.FragmentTestActivity10import com.jakelaurie.colormemory.model.Score11import com.jakelaurie.colormemory.ui.highscore.HighscoreFragment12import com.jakelaurie.colormemory.ui.highscore.HighscorePresenter13import com.jakelaurie.colormemory.ui.highscore.list.HighscoreAdapter14import org.junit.Rule15import org.junit.Test16class HighscoreFragmentTest: DBTest() {17 val fragment = HighscoreFragment()18 private val playerName = "test"19 private val playerScore = 10020 @get:Rule21 val rule = object : ActivityTestRule<FragmentTestActivity>(FragmentTestActivity::class.java) {22 override fun afterActivityLaunched() = runOnUiThread {23 activity.startFragment(fragment, this@HighscoreFragmentTest::inject)24 }25 }26 fun inject(fragment: HighscoreFragment) {27 initDb()28 val scoreDAO = db.scoreDao()29 val score = Score("$playerScore")30 score.score = playerScore31 score.playerName = playerName32 scoreDAO.addScore(score)33 fragment.presenter = HighscorePresenter(HighscoreAdapter(), scoreDAO)34 }35 /**36 * Test actionbar37 */38 @Test39 fun testActionbar() {40 onView(ViewMatchers.withId(R.id.highscoreActionbarTitle))41 .check(matches(ViewMatchers.isDisplayed()))42 .check(matches(ViewMatchers.withText("Top 10 high scores")))43 }44 /**45 * Test header and recycler visibility46 */47 @Test48 fun testHeader() {49 onView(ViewMatchers.withId(R.id.titleHighScoreRank))50 .check(matches(ViewMatchers.isDisplayed()))51 .check(matches(ViewMatchers.withText("Rank")))52 onView(ViewMatchers.withId(R.id.titleHighScoreName))53 .check(matches(ViewMatchers.isDisplayed()))54 .check(matches(ViewMatchers.withText("Name")))55 onView(ViewMatchers.withId(R.id.titleHighScoreScore))56 .check(matches(ViewMatchers.isDisplayed()))57 .check(matches(ViewMatchers.withText("Points")))58 }59 /**60 * Test the 'score' we put in the Db is actually shown in recycler61 */62 @Test63 fun testRecyclerContent() {64 onView(ViewMatchers.withId(R.id.highScoreRecyclerView))65 .check(matches(ViewMatchers.isDisplayed()))66 onView(withText("#1")).check(matches(isDisplayed()))67 onView(withText(playerName)).check(matches(isDisplayed()))68 onView(withText("$playerScore")).check(matches(isDisplayed()))69 }70}...
EmojiTestRecord.kt
Source:EmojiTestRecord.kt
...5import android.support.test.espresso.action.ViewActions.closeSoftKeyboard6import android.support.test.espresso.action.ViewActions.replaceText7import android.support.test.espresso.assertion.ViewAssertions.matches8import android.support.test.espresso.matcher.ViewMatchers9import android.support.test.espresso.matcher.ViewMatchers.isDisplayed10import android.support.test.espresso.matcher.ViewMatchers.withId11import android.support.test.espresso.matcher.ViewMatchers.withParent12import android.support.test.espresso.matcher.ViewMatchers.withText13import android.support.test.rule.ActivityTestRule14import android.support.test.runner.AndroidJUnit415import android.test.suitebuilder.annotation.LargeTest16import android.view.View17import com.jakewharton.espresso.OkHttp3IdlingResource18import com.xamarin.azuredevdays.HTTP_CLIENT19import com.xamarin.azuredevdays.MainActivity20import com.xamarin.azuredevdays.R21import com.xamarin.testcloud.espresso.Factory22import com.xamarin.testcloud.espresso.ReportHelper23import org.hamcrest.CoreMatchers.allOf24import org.junit.After25import org.junit.Rule26import org.junit.Test27import org.junit.runner.RunWith28@LargeTest29@RunWith(AndroidJUnit4::class)30class EmojiTestRecord {31 @Rule @JvmField val activityTestRule = ActivityTestRule(MainActivity::class.java)32 @Rule @JvmField val reportHelper: ReportHelper = Factory.getReportHelper()33 @Test34 fun emojiTestRecord() {35 val sentimentText = onView(36 allOf<View>(37 ViewMatchers.withId(R.id.sentimentText),38 withParent(withId(R.id.backgroundLayout)),39 isDisplayed()40 )41 )42 reportHelper.label("On Main Page")43 sentimentText.perform(click())44 sentimentText.perform(replaceText("Happy"), closeSoftKeyboard())45 reportHelper.label("Text value entered:: Happy")46 val submitButton = onView(47 allOf<View>(48 withId(R.id.getSentimentButton), withText("Submit"),49 withParent(withId(R.id.backgroundLayout)),50 isDisplayed()51 )52 )53 submitButton.perform(click())54 val idlingResource = OkHttp3IdlingResource.create("okhttp", HTTP_CLIENT)55 IdlingRegistry.getInstance().register(idlingResource)56 onView(withId(R.id.emojiView)).check(matches(isDisplayed()))57 reportHelper.label("Result Emoji Loaded")58 IdlingRegistry.getInstance().unregister(idlingResource)59 }60 @After61 fun tearDown() {62 reportHelper.label("Stopping App")63 }64}...
SearchActivityInstrumentedTest.kt
Source:SearchActivityInstrumentedTest.kt
...22 @get:Rule23 val activityRule = ActivityTestRule<SearchActivity>(SearchActivity::class.java)24 @Test25 fun toolbarShouldBeShown() {26 onView(withText("Edinburgh - London")).check(matches(ViewMatchers.isDisplayed()))27 onView(withText("19 Feb - 20 Feb, 1 adult, Economy")).check(matches(ViewMatchers.isDisplayed()))28 }29}...
isDisplayed
Using AI Code Generation
1onView(withId(R.id.myView)).check(matches(isDisplayed()));2onView(withId(R.id.myView)).check(ViewAssertions.matches(isDisplayed()));3onView(withId(R.id.myView)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()));4onView(withId(R.id.myView)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()));5onView(withId(R.id.myView)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()));6onView(withId(R.id.myView)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()));7onView(withId(R.id.myView)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()));8onView(withId(R.id.myView)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()));9onView(withId(R.id.myView)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()));10onView(withId(R.id.myView)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()));11onView(withId(R.id.myView)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()));12onView(withId(R.id.myView)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()));13onView(withId(R.id.myView)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()));14onView(withId(R.id.myView)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()));15onView(withId(R.id.myView)).check(ViewAssertions.matches(ViewMatchers
isDisplayed
Using AI Code Generation
1if (ViewMatchers.isDisplayed().matches(view)) {2}3if (Matchers.isDisplayed().matches(view)) {4}5if (Matchers.isDisplayed().matches(view)) {6}7if (Matchers.isDisplayed().matches(view)) {8}9if (Matchers.isDisplayed().matches(view)) {10}11if (Matchers.isDisplayed().matches(view)) {12}13if (Matchers.isDisplayed().matches(view)) {14}15if (Matchers.isDisplayed().matches(view)) {16}17if (Matchers.isDisplayed().matches(view)) {18}19if (Matchers.isDisplayed().matches(view)) {20}21if (Matchers.isDisplayed().matches(view)) {22}23if (Matchers.isDisplayed().matches(view)) {24}25if (Matchers.isDisplayed().matches(view)) {26}27if (Matchers.isDisplayed().matches(view)) {28}29if (Matchers.isDisplayed().matches(view)) {30}31if (Matchers.isDisplayed().matches(view)) {32}33if (Matchers.isDisplayed().matches(view)) {34}
isDisplayed
Using AI Code Generation
1@Rule public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule(MainActivity.class);2public void testIsDisplayed() {3 onView(withId(R.id.button)).check(matches(isDisplayed()));4}5@Rule public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule(MainActivity.class);6public void testIsEnabled() {7 onView(withId(R.id.button)).check(matches(isEnabled()));8}9@Rule public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule(MainActivity.class);10public void testIsClickable() {11 onView(withId(R.id.button)).check(matches(isClickable()));12}13@Rule public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule(MainActivity.class);14public void testIsFocusable() {15 onView(withId(R.id.button)).check(matches(isFocusable()));16}17@Rule public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule(MainActivity.class);18public void testIsFocused() {19 onView(withId(R.id.button)).check(matches(isFocused()));20}21@Rule public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule(MainActivity.class);22public void testIsSelected() {23 onView(withId(R.id.button)).check(matches(isSelected()));24}25@Rule public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule(MainActivity.class);26public void testWithId() {27 onView(withId(R.id.button)).check(matches(isDisplayed()));28}29@Rule public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule(MainActivity.class);30public void testWithText() {31 onView(withText("Hello World!")).check(matches(isDisplayed()));32}33@Rule public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule(MainActivity.class);34public void testWithHint() {35 onView(with
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!