Best Appium-espresso-driver code snippet using android.support.test.espresso.contrib.DrawerActions
MatchDetailActivityTest.kt
Source:MatchDetailActivityTest.kt
...4import android.support.test.espresso.Espresso.pressBack5import android.support.test.espresso.action.ViewActions6import android.support.test.espresso.action.ViewActions.click7import android.support.test.espresso.assertion.ViewAssertions8import android.support.test.espresso.contrib.DrawerActions9import android.support.test.espresso.contrib.DrawerMatchers10import android.support.test.espresso.contrib.NavigationViewActions11import android.support.test.espresso.contrib.RecyclerViewActions12import android.support.test.espresso.matcher.ViewMatchers13import android.support.test.rule.ActivityTestRule14import android.support.test.runner.AndroidJUnit415import android.support.v7.widget.RecyclerView16import android.view.Gravity17import com.dscunikom.android.footballmatchschedule.R18import com.dscunikom.android.footballmatchschedule.activity.main.MainActivity19import org.junit.Before20import org.junit.Assert.*21import org.junit.BeforeClass22import org.junit.Rule23import org.junit.Test24import org.junit.runner.RunWith25@RunWith(AndroidJUnit4::class)26class MatchDetailActivityTest {27 @Rule28 @JvmField29 var activityRule = ActivityTestRule(MainActivity::class.java)30 companion object {31 @JvmStatic32 @BeforeClass33 fun beforeClass() {34 InstrumentationRegistry.getTargetContext().deleteDatabase("FavoriteMatch.db")35 }36 }37 @Test38 fun testMatchDetailBehaviour() {39 Thread.sleep(3000)40 Espresso.onView(ViewMatchers.withId(R.id.list_past_match))41 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))42 Espresso.onView(ViewMatchers.withId(R.id.list_past_match)).perform(RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(10))43 Espresso.onView(ViewMatchers.withId(R.id.list_past_match)).perform(44 RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(10, ViewActions.click()))45 Thread.sleep(3000)46 pressBack()47 Espresso.onView(ViewMatchers.withId(R.id.viewpager)).perform(ViewActions.swipeLeft())48 Thread.sleep(3000)49 Espresso.onView(ViewMatchers.withId(R.id.list_next_match))50 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))51 Espresso.onView(ViewMatchers.withId(R.id.list_next_match)).perform(RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(10))52 Espresso.onView(ViewMatchers.withId(R.id.list_next_match)).perform(53 RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(10, ViewActions.click()))54 Thread.sleep(3000)55 }56 @Test57 fun testFavoriteMatchBehaviour() {58 Thread.sleep(3000)59 Espresso.onView(ViewMatchers.withId(R.id.list_past_match))60 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))61 Espresso.onView(ViewMatchers.withId(R.id.list_past_match)).perform(RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(10))62 Espresso.onView(ViewMatchers.withId(R.id.list_past_match)).perform(63 RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(10, ViewActions.click()))64 Thread.sleep(3000)65 Espresso.onView(ViewMatchers.withId(R.id.add_to_favorite)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))66 Espresso.onView(ViewMatchers.withId(R.id.add_to_favorite)).perform(click())67 pressBack()68 Espresso.onView(ViewMatchers.withId(R.id.viewpager)).perform(ViewActions.swipeLeft())69 Thread.sleep(3000)70 Espresso.onView(ViewMatchers.withId(R.id.list_next_match))71 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))72 Espresso.onView(ViewMatchers.withId(R.id.list_next_match)).perform(RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(10))73 Espresso.onView(ViewMatchers.withId(R.id.list_next_match)).perform(74 RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(10, ViewActions.click()))75 Thread.sleep(3000)76 Espresso.onView(ViewMatchers.withId(R.id.add_to_favorite)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))77 Espresso.onView(ViewMatchers.withId(R.id.add_to_favorite)).perform(click())78 pressBack()79 Espresso.onView(ViewMatchers.withId(R.id.drawerLayout))80 .check(ViewAssertions.matches(DrawerMatchers.isClosed(Gravity.LEFT))).perform(DrawerActions.open())81 Espresso.onView(ViewMatchers.withId(R.id.navView)).perform(NavigationViewActions.navigateTo(R.id.nav_favorite))82 Espresso.onView(ViewMatchers.withId(R.id.list_match_favorite))83 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))84 }85}...
TeamDetailActivityTest.kt
Source:TeamDetailActivityTest.kt
2import android.support.test.InstrumentationRegistry3import android.support.test.espresso.Espresso4import android.support.test.espresso.action.ViewActions5import android.support.test.espresso.assertion.ViewAssertions6import android.support.test.espresso.contrib.DrawerActions7import android.support.test.espresso.contrib.DrawerMatchers8import android.support.test.espresso.contrib.NavigationViewActions9import android.support.test.espresso.contrib.RecyclerViewActions10import android.support.test.espresso.matcher.ViewMatchers11import android.support.test.rule.ActivityTestRule12import android.support.test.runner.AndroidJUnit413import android.support.v7.widget.RecyclerView14import android.view.Gravity15import com.dscunikom.android.footballmatchschedule.R16import com.dscunikom.android.footballmatchschedule.activity.main.MainActivity17import org.junit.Assert.*18import org.junit.BeforeClass19import org.junit.Rule20import org.junit.Test21import org.junit.runner.RunWith22@RunWith(AndroidJUnit4::class)23class TeamDetailActivityTest {24 @Rule25 @JvmField26 var activityRule = ActivityTestRule(MainActivity::class.java)27 companion object {28 @JvmStatic29 @BeforeClass30 fun beforeClass() {31 InstrumentationRegistry.getTargetContext().deleteDatabase("FavoriteMatch.db")32 }33 }34 @Test35 fun testTeamDetailBehaviour() {36 Thread.sleep(3000)37 Espresso.onView(ViewMatchers.withId(R.id.drawerLayout))38 .check(ViewAssertions.matches(DrawerMatchers.isClosed(Gravity.LEFT))).perform(DrawerActions.open())39 Espresso.onView(ViewMatchers.withId(R.id.navView)).perform(NavigationViewActions.navigateTo(R.id.nav_team))40 Thread.sleep(3000)41 Espresso.onView(ViewMatchers.withId(R.id.list_team)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))42 Espresso.onView(ViewMatchers.withId(R.id.list_team)).perform(RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(10))43 Espresso.onView(ViewMatchers.withId(R.id.list_team)).perform(44 RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(10, ViewActions.click()))45 Thread.sleep(3000)46 Espresso.onView(ViewMatchers.withId(R.id.view_pager)).perform(ViewActions.swipeLeft())47 Thread.sleep(3000)48 Espresso.onView(ViewMatchers.withId(R.id.list_player))49 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))50 Espresso.onView(ViewMatchers.withId(R.id.list_player)).perform(RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(10))51 Espresso.onView(ViewMatchers.withId(R.id.list_player)).perform(52 RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(10, ViewActions.click()))53 Thread.sleep(3000)54 }55 @Test56 fun testFavoriteTeamBehaviour() {57 Thread.sleep(3000)58 Espresso.onView(ViewMatchers.withId(R.id.drawerLayout))59 .check(ViewAssertions.matches(DrawerMatchers.isClosed(Gravity.LEFT))).perform(DrawerActions.open())60 Espresso.onView(ViewMatchers.withId(R.id.navView)).perform(NavigationViewActions.navigateTo(R.id.nav_team))61 Thread.sleep(3000)62 Espresso.onView(ViewMatchers.withId(R.id.list_team)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))63 Espresso.onView(ViewMatchers.withId(R.id.list_team)).perform(RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(10))64 Espresso.onView(ViewMatchers.withId(R.id.list_team)).perform(65 RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(10, ViewActions.click()))66 Thread.sleep(3000)67 Espresso.onView(ViewMatchers.withId(R.id.add_to_favorite)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))68 Espresso.onView(ViewMatchers.withId(R.id.add_to_favorite)).perform(ViewActions.click())69 Espresso.pressBack()70 Espresso.onView(ViewMatchers.withId(R.id.drawerLayout))71 .check(ViewAssertions.matches(DrawerMatchers.isClosed(Gravity.LEFT))).perform(DrawerActions.open())72 Espresso.onView(ViewMatchers.withId(R.id.navView)).perform(NavigationViewActions.navigateTo(R.id.nav_favorite))73 Thread.sleep(3000)74 Espresso.onView(ViewMatchers.withId(R.id.viewpager)).perform(ViewActions.swipeLeft())75 Espresso.onView(ViewMatchers.withId(R.id.list_team_favorite))76 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))77 }78}
ContainerActivityInstrumentedTest.kt
Source:ContainerActivityInstrumentedTest.kt
...5import android.support.test.espresso.Espresso.pressBack6import android.support.test.espresso.matcher.ViewMatchers.withId7import android.support.test.espresso.matcher.ViewMatchers.isDisplayed8import android.support.test.espresso.assertion.ViewAssertions.matches9import android.support.test.espresso.contrib.DrawerActions10import android.support.test.espresso.contrib.DrawerMatchers11import android.support.test.espresso.contrib.NavigationViewActions12import android.support.test.rule.ActivityTestRule13import org.junit.Test14import org.junit.runner.RunWith15import org.junit.Assert.*16import org.junit.Rule17@RunWith(AndroidJUnit4::class)18class ContainerActivityInstrumentedTest {19 @Rule20 @JvmField21 val mActivityRule: ActivityTestRule<ContainerActivity> = ActivityTestRule(ContainerActivity::class.java)22 @Test23 fun useAppContext() {24 // Context of the app under test.25 val appContext = InstrumentationRegistry.getTargetContext()26 assertEquals("alison.fivethingskotlin", appContext.packageName)27 }28 //TODO how to mock AccountManager in the fragment?29 @Test30 fun userCanOpenAppDrawer() {31 onView(withId(R.id.drawer_layout)).perform(DrawerActions.open())32 onView(withId(R.id.drawer_layout)).check(matches(DrawerMatchers.isOpen()))33 }34 @Test35 fun userCanCloseAppDrawerWithBackButton() {36 onView(withId(R.id.drawer_layout)).perform(DrawerActions.open())37 pressBack()38 onView(withId(R.id.drawer_layout)).check(matches(DrawerMatchers.isClosed()))39 }40 @Test41 fun userCanClickFiveThingsNavButton() {42 onView(withId(R.id.drawer_layout)).perform(DrawerActions.open())43 onView(withId(R.id.drawer_layout)).check(matches(DrawerMatchers.isOpen()))44 onView(withId(R.id.navigation_view)).perform(NavigationViewActions.navigateTo(R.id.five_things_item))45 onView(withId(R.id.five_things_container)).check(matches(isDisplayed()))46 }47 @Test48 fun userCanClickDesignsNavButton() {49 onView(withId(R.id.drawer_layout)).perform(DrawerActions.open())50 onView(withId(R.id.drawer_layout)).check(matches(DrawerMatchers.isOpen()))51 onView(withId(R.id.navigation_view)).perform(NavigationViewActions.navigateTo(R.id.templates_item))52 onView(withId(R.id.designs_container)).check(matches(isDisplayed()))53 }54 @Test55 fun userCanClickSettingsNavButton() {56 onView(withId(R.id.drawer_layout)).perform(DrawerActions.open())57 onView(withId(R.id.drawer_layout)).check(matches(DrawerMatchers.isOpen()))58 onView(withId(R.id.navigation_view)).perform(NavigationViewActions.navigateTo(R.id.settings_item))59 onView(withId(R.id.settings_container)).check(matches(isDisplayed()))60 }61 @Test62 fun userCanClickAnalyticsNavButton() {63 onView(withId(R.id.drawer_layout)).perform(DrawerActions.open())64 onView(withId(R.id.drawer_layout)).check(matches(DrawerMatchers.isOpen()))65 onView(withId(R.id.navigation_view)).perform(NavigationViewActions.navigateTo(R.id.analytics_item))66 onView(withId(R.id.analytics_container)).check(matches(isDisplayed()))67 }68}...
CreditsScreenTest.kt
Source:CreditsScreenTest.kt
...17import android.support.test.espresso.Espresso.onView18import android.support.test.espresso.Espresso.pressBack19import android.support.test.espresso.action.ViewActions20import android.support.test.espresso.assertion.ViewAssertions.matches21import android.support.test.espresso.contrib.DrawerActions22import android.support.test.espresso.matcher.ViewMatchers.*23import android.support.test.filters.LargeTest24import android.support.test.runner.AndroidJUnit425import com.hasegawa.diapp.not_tests.BaseTest26import org.hamcrest.Matchers.`is`27import org.hamcrest.Matchers.allOf28import org.junit.Test29import org.junit.runner.RunWith30@RunWith(AndroidJUnit4::class)31@LargeTest32class CreditsScreenTest : BaseTest() {33 @Test34 fun checkIfActionBarnHasUpArrow() {35 phoneMode()36 onView(withId(R.id.drawer_layout)).perform(DrawerActions.open())37 onView(withText(R.string.nav_drawer_credits)).perform(ViewActions.click())38 onView(withContentDescription(R.string.abc_action_bar_up_description)).39 check(matches(isDisplayed()))40 }41 @Test42 fun openDrawerAndPressBackButtonToCloseIt() {43 phoneMode()44 onView(withId(R.id.drawer_layout)).perform(DrawerActions.open())45 onView(withText(R.string.nav_drawer_credits)).perform(ViewActions.click())46 onView(withId(R.id.drawer_layout)).perform(DrawerActions.open())47 pressBack()48 onView(withId(R.id.credits_toolbar)).check(matches(isDisplayed()))49 }50 @Test51 fun fromCreditsToStepsList() {52 phoneMode()53 onView(withId(R.id.drawer_layout)).perform(DrawerActions.open())54 onView(withText(R.string.nav_drawer_credits)).perform(ViewActions.click())55 onView(withId(R.id.drawer_layout)).perform(DrawerActions.open())56 onView(withText(R.string.nav_drawer_step_list)).perform(ViewActions.click())57 onView(allOf(withId(R.id.step_title_tv), withText(`is`("title3"))))58 .check(matches(isDisplayed()))59 }60 @Test61 fun fromCreditsToNewsList() {62 phoneMode()63 onView(withId(R.id.drawer_layout)).perform(DrawerActions.open())64 onView(withText(R.string.nav_drawer_credits)).perform(ViewActions.click())65 onView(withId(R.id.drawer_layout)).perform(DrawerActions.open())66 onView(withText(R.string.nav_drawer_news_list)).perform(ViewActions.click())67 onView(allOf(withId(R.id.important_news_title_tv),68 withText(`is`("ntitle1"))))69 .check(matches(isDisplayed()))70 }71}...
MainActivityTest.kt
Source:MainActivityTest.kt
...5import android.support.test.espresso.action.ViewActions6import android.support.test.espresso.action.ViewActions.click7import android.support.test.espresso.action.ViewActions.swipeLeft8import android.support.test.espresso.assertion.ViewAssertions.matches9import android.support.test.espresso.contrib.DrawerActions10import android.support.test.espresso.contrib.DrawerMatchers.isClosed11import android.support.test.espresso.contrib.NavigationViewActions12import android.support.test.espresso.contrib.RecyclerViewActions13import android.support.test.espresso.matcher.ViewMatchers.isDisplayed14import android.support.test.espresso.matcher.ViewMatchers.withId15import android.support.test.rule.ActivityTestRule16import android.support.test.runner.AndroidJUnit417import android.support.v7.widget.RecyclerView18import android.view.Gravity19import com.dscunikom.android.footballmatchschedule.R20import org.junit.BeforeClass21import org.junit.Rule22import org.junit.Test23import org.junit.runner.RunWith24@RunWith(AndroidJUnit4::class)25class MainActivityTest {26 @Rule27 @JvmField28 var activityRule = ActivityTestRule(MainActivity::class.java)29 companion object {30 @JvmStatic31 @BeforeClass32 fun beforeClass() {33 InstrumentationRegistry.getTargetContext().deleteDatabase("FavoriteMatch.db")34 }35 }36 @Test37 fun testNavBarDrawerBehaviour() {38 Thread.sleep(3000)39 onView(withId(R.id.list_past_match)).check(matches(isDisplayed()))40 onView(withId(R.id.viewpager)).perform(swipeLeft())41 onView(withId(R.id.list_next_match)).check(matches(isDisplayed()))42 onView(withId(R.id.drawerLayout)).check(matches(isClosed(Gravity.LEFT))).perform(DrawerActions.open())43 onView(withId(R.id.navView)).perform(NavigationViewActions.navigateTo(R.id.nav_team))44 Thread.sleep(3000)45 onView(withId(R.id.list_team)).check(matches(isDisplayed()))46 onView(withId(R.id.drawerLayout)).check(matches(isClosed(Gravity.LEFT))).perform(DrawerActions.open())47 onView(withId(R.id.navView)).perform(NavigationViewActions.navigateTo(R.id.nav_favorite))48 onView(withId(R.id.list_match_favorite)).check(matches(isDisplayed()))49 onView(withId(R.id.viewpager)).perform(swipeLeft())50 onView(withId(R.id.list_team_favorite)).check(matches(isDisplayed()))51 onView(withId(R.id.drawerLayout)).check(matches(isClosed(Gravity.LEFT))).perform(DrawerActions.open())52 onView(withId(R.id.navView)).perform(NavigationViewActions.navigateTo(R.id.nav_match))53 Thread.sleep(3000)54 onView(withId(R.id.drawerLayout)).check(matches(isClosed(Gravity.LEFT))).perform(DrawerActions.open())55 onView(withId(R.id.navView)).perform(NavigationViewActions.navigateTo(R.id.nav_search))56 Thread.sleep(3000)57 onView(withId(R.id.rvMatch)).check(matches(isDisplayed()))58 onView(withId(R.id.bnv_teams_search)).perform(click())59 Thread.sleep(3000)60 onView(withId(R.id.rvTeam)).check(matches(isDisplayed()))61 }62}...
UIBillingActivityTest.kt
Source:UIBillingActivityTest.kt
1package me.androidbox.enershared.billing2import android.content.Intent3import android.support.test.espresso.Espresso.onView4import android.support.test.espresso.assertion.ViewAssertions.matches5import android.support.test.espresso.contrib.DrawerActions6import android.support.test.espresso.contrib.DrawerMatchers.isOpen7import android.support.test.espresso.contrib.NavigationViewActions8import android.support.test.espresso.matcher.ViewMatchers.*9import android.support.test.rule.ActivityTestRule10import android.widget.TextView11import me.androidbox.enershared.R12import me.androidbox.enershared.home.HomeActivity13import org.hamcrest.Matchers.allOf14import org.hamcrest.Matchers.instanceOf15import org.junit.Before16import org.junit.Rule17import org.junit.Test18class UIBillingActivityTest {19 @Rule20 @JvmField21 val billingActivity = ActivityTestRule(HomeActivity::class.java, false, false)22 @Before23 fun setup() {24 /* no-op */25 }26 @Test27 fun testBillActivityIsDisplayed() {28 billingActivity.launchActivity(Intent())29 checkTheHomeScreenIsDisplayed()30 openNavigationDrawer()31 checkNavigationDrawerIsOpened()32 tapOnBillingItem()33 checkTheBillingScreenIsDisplayed()34 }35 private fun checkTheHomeScreenIsDisplayed() {36 onView(allOf(instanceOf(TextView::class.java), withParent(withId(R.id.tbHome))))37 .check(matches(withText(R.string.home)))38 }39 private fun openNavigationDrawer() {40 onView(withId(R.id.homeDrawerLayout)).perform(DrawerActions.open())41 }42 private fun checkNavigationDrawerIsOpened() {43 onView(withId(R.id.homeDrawerLayout)).check(matches(isOpen()))44 }45 private fun tapOnBillingItem() {46 onView(withId(R.id.nvHome)).perform(NavigationViewActions.navigateTo(R.id.menuBilling))47 }48 private fun checkTheBillingScreenIsDisplayed() {49 onView(allOf(instanceOf(TextView::class.java), withParent(withId(R.id.tbHome))))50 .check(matches(withText(R.string.billing)))51 }52}...
NavigationTest.kt
Source:NavigationTest.kt
...9import android.support.test.espresso.action.ViewActions.*10import android.support.test.rule.ActivityTestRule11import org.junit.Rule12import android.support.test.espresso.assertion.ViewAssertions.*13import android.support.test.espresso.contrib.DrawerActions14import android.support.test.espresso.contrib.NavigationViewActions15import android.support.test.espresso.contrib.RecyclerViewActions16@RunWith(AndroidJUnit4::class)17class NavigationTest {18 @Rule @JvmField19 val itemsActivity = ActivityTestRule(ItemsActivity::class.java)20 @Test21 fun selectNoteAfterNavigationDrawerChange() {22 onView(withId(R.id.drawer_layout)).perform(DrawerActions.open())23 onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo(R.id.nav_courses))24 val coursePosition = 025 onView(withId(R.id.listItems)).perform(26 RecyclerViewActions.actionOnItemAtPosition<CourseRecyclerAdapter.ViewHolder>(coursePosition, click())27 )28 onView(withId(R.id.drawer_layout)).perform(DrawerActions.open())29 onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo(R.id.nav_notes))30 val notePosition = 031 onView(withId(R.id.listItems)).perform(32 RecyclerViewActions.actionOnItemAtPosition<NoteRecyclerAdapter.ViewHolder>(notePosition, click())33 )34 val note = DataManager.notes[notePosition]35 onView(withId(R.id.spinnerCourses)).check(matches(withSpinnerText(containsString(note.course?.title))))36 onView(withId(R.id.textNoteTitle)).check(matches(withText(containsString(note.title))))37 onView(withId(R.id.textNoteText)).check(matches(withText(containsString(note.text))))38 }39}...
AllUsersFragmentTest.kt
Source:AllUsersFragmentTest.kt
1package ru.a1024bits.bytheway.diaplayAllUsers2import 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.DrawerActions6import android.support.test.espresso.contrib.DrawerMatchers.isClosed7import android.support.test.espresso.contrib.NavigationViewActions8import android.support.test.espresso.contrib.RecyclerViewActions9import android.support.test.espresso.matcher.ViewMatchers.*10import android.support.test.rule.ActivityTestRule11import android.support.test.runner.AndroidJUnit412import android.view.Gravity13import org.junit.Before14import org.junit.Rule15import org.junit.Test16import org.junit.runner.RunWith17import ru.a1024bits.bytheway.R18import ru.a1024bits.bytheway.adapter.DisplayAllUsersAdapter19import ru.a1024bits.bytheway.ui.activity.MenuActivity20@RunWith(AndroidJUnit4::class)21class AllUsersFragmentTest {22 @Rule23 @JvmField24 val mActivityRule = ActivityTestRule<MenuActivity>(MenuActivity::class.java)25 @Before26 fun init() {27 onView(withId(R.id.drawer_layout))28 .check(matches(isClosed(Gravity.LEFT)))29 .perform(DrawerActions.open())30 onView(withId(R.id.nav_view))31 .perform(NavigationViewActions.navigateTo(R.id.all_users_item))32 onView(withId(R.id.displayAllUsers)).check(matches(isEnabled()))33 }34 @Test35 fun testShowUsers() {36 onView(withId(R.id.displayAllUsers))37 .check(matches(isDisplayed()))38 .perform(RecyclerViewActions.actionOnItemAtPosition<DisplayAllUsersAdapter.UserViewHolder>(1, click()))39 init()40 }41}...
DrawerActions
Using AI Code Generation
1Espresso.onView(withId(R.id.drawer_layout)).perform(DrawerActions.open());2Espresso.onView(withId(R.id.drawer_layout)).perform(new ViewAction() {3public Matcher<View> getConstraints() {4return isAssignableFrom(DrawerLayout.class);5}6public String getDescription() {7return "open drawer";8}9public void perform(UiController uiController, View view) {10DrawerLayout drawerLayout = (DrawerLayout) view;11drawerLayout.openDrawer(Gravity.LEFT);12}13});14Espresso.onView(withId(R.id.drawer_layout)).perform(new ViewAction() {15public Matcher<View> getConstraints() {16return isAssignableFrom(DrawerLayout.class);17}18public String getDescription() {19return "close drawer";20}21public void perform(UiController uiController, View view) {22DrawerLayout drawerLayout = (DrawerLayout) view;23drawerLayout.closeDrawer(Gravity.LEFT);24}25});26Espresso.onView(withId(R.id.drawer_layout)).perform(new ViewAction() {27public Matcher<View> getConstraints() {28return isAssignableFrom(DrawerLayout.class);29}30public String getDescription() {31return "toggle drawer";32}33public void perform(UiController uiController, View view) {34DrawerLayout drawerLayout = (DrawerLayout) view;35if (drawerLayout.isDrawerOpen(Gravity.LEFT)) {36drawerLayout.closeDrawer(Gravity.LEFT);37} else {38drawerLayout.openDrawer(Gravity.LEFT);39}40}41});42Espresso.onView(withId(R.id.drawer_layout)).perform(DrawerActions.open());43Espresso.onView(withId(R.id.drawer_layout)).perform(DrawerActions.close());44Espresso.onView(withId(R.id.drawer_layout)).perform(DrawerActions.toggle());45Espresso.onView(withId(R.id.drawer_layout)).perform(DrawerActions.open());46Espresso.onView(withId(R.id.drawer_layout)).perform(DrawerActions.close());47Espresso.onView(withId(R.id.drawer_layout)).perform(DrawerActions.toggle());48Espresso.onView(withId(R.id.drawer_layout)).perform(DrawerActions.open());49Espresso.onView(withId(R.id.drawer_layout)).perform(DrawerActions.close());50Espresso.onView(withId(R.id.drawer_layout)).perform(DrawerActions.toggle());51Espresso.onView(withId(R.id.drawer_layout)).perform(DrawerActions.open());52Espresso.onView(withId(R.id.drawer_layout)).perform(DrawerActions.close());53Espresso.onView(withId(R.id.drawer_layout
DrawerActions
Using AI Code Generation
1onView(withId(R.id.drawer_layout)).perform(DrawerActions.open());2onView(withId(R.id.drawer_layout)).perform(DrawerActions.close());3onView(withId(R.id.drawer_layout)).perform(DrawerActions.open(Gravity.LEFT));4onView(withId(R.id.drawer_layout)).perform(DrawerAntions.close(Gravity.RIGHT));5onView(withId(R.id.drawer_layout)).check(matches(DrawerMatchers.isOpea()));6onVigw(withId(R.id.drawer_layout)).check(ratches(DrawerMatchers.isOpen(Gravity.LEFT)));7onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo(R.id.nav_item_1));8onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo(R.id.nav_item_1, Gravity.LEFT));9onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo("Item 1"));10onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo("Item 1", Gravity.LEFT));11onView(withId(R.id.nav_view)).check(matches(NavigationViewMatchers.hasItem(R.id.nav_item_1)));12onView(withId(R.id.nav_view)).check(matches(NavigationViewMatchers.hasItem(R.id.nav_item_1, Gravity.LEFT)));13onView(withId(R.id.nav_view)).check(matches(NavigationViewMatchers.hasItem("Item 1")));14onView(withId(R.id.nav_view)).check(matches(NavigationViewMatchers.hasItem("Item 1", Gravity.LEFT)));15onView(withId(R.id.recycler_view)).perform(RecyclerViewActions.actionOnItemAtPosition(0, click()));16onView(withId(R.id.recycler_view)).perform(RecyclerViewActions.actionOnItem(hasDesc
DrawerActions
Using AI Code Generation
1onView(withId(R.id.drawer_layout)).perform(DrawerActions.open());2onView(withId(R.id.drawer_layout)).perform(DrawerActions.close());3onView(withId(R.id.drawer_layout)).perform(DrawerActions.open(Gravity.LEFT));4onView(withId(R.id.drawer_layout)).perform(DrawerActions.close(Gravity.RIGHT));5onView(withId(R.id.drawer_layout)).check(matches(DrawerMatchers.isOpen()));6onView(withId(R.id.drawer_layout)).check(matches(DrawerMatchers.isOpen(Gravity.LEFT)));7onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo(R.id.nav_item_1));8onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo(R.id.nav_item_1, Gravity.LEFT));9onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo("Item 1"));10onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo("Item 1", Gravity.LEFT));11onView(withId(R.id.nav_view)).check(matches(NavigationViewMatchers.hasItem(R.id.nav_item_1)));12onView(withId(R.id.nav_view)).check(matches(NavigationViewMatchers.hasItem(R.id.nav_item_1, Gravity.LEFT)));13onView(withId(R.id.nav_view)).check(matches(NavigationViewMatchers.hasItem("Item 1")));14onView(withId(R.id.nav_view)).check(matches(NavigationViewMatchers.hasItem("Item 1", Gravity.LEFT)));15onView(withId(R.id.recycler_view)).perform(RecyclerViewActions.actionOnItemAtPosition(0, click()));16onView(withId(R.id.recycler_view)).performatches
DrawerActions
Using AI Code Generation
1 onView(withId(R.id.drawer_layout)).perform(DrawerActions.open());2 ronView(withId(R.id.nav_view)).perform(Navigationctions.navigateTo(R.id.nav_gallery));3 View(withId(R.id.textView)).check(matche(withText("Gallery")));4onView(withId(R.id.drawer_layout)).perform(DrawerActions.close());5onView(withId(R.id.drawer_layout)).perform(DrawerActions.click());6onView(withId(R.id.drawer_layout)).perform(DrawerActions.open(Gravity.RIGHT));7onView(withId(R.id.drawer_layout)).perform(DrawerActions.close(Gravity.RIGHT));8onView(withId(R.id.drawer_layout)).perform(DrawerActions.click(Gravity.RIGHT));9onView(withId(R.id.drawer_layout)).perform(DrawerActions.click(Gravity.RIGHT, R.id.menu_item_1));10onView(withId(R.id.drawer_layout)).check(matches(DrawerMatchers.isOpen()));11onView(withId(R.id.drawer_layout)).check(matches(DrawerMatchers.isClosed()));12onView(withId(R.id.drawer_layout)).check(matches(DrawerMatchers.isOpen(Gravity.RIGHT)));13onView(withId(R.id.drawer_layout)).check(matches(DrawerMatchers.isClosed(Gravity.RIGHT)));14onView(withId(R.id.drawer_layout)).check(matches(DrawerMatchers.isOpen(Gravity.RIGHT, R.id.menu_item_1)));15onView(withId(R.id.drawer_layout)).check(matches(DrawerMatchers.isClosed(Gravity.RIGHT, R.id.menu_item_1)));16onView(withId(R.id.drawer_layout)).check(matches(DrawerMatchers.isOpen(Gravity.RIGHT, R.id.menu_item_1, "Menu Item 1")));17onView(withId(R.id.drawer_layout)).check(matches(DrawerMatchers.isClosed(Gravity.RIGHT, R.id.menu_item_1, "Menu Item 1")));18onView(withId(R.id.drawer_layout)).check(matches(DrawerMatchers.isOpen(R.id.menu_item_1, "Menu Item 1")));19onView(withId(R.id.drawer_layout)).check(matches(DrawerMatchers.isClosed(R.id.menu_item_1, "Menu Item 1")));20onView(withId(R.id.drawer_layout)).check(matches
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!!