Best Appium-espresso-driver code snippet using android.support.test.espresso.contrib.DrawerActions.close
NavigationScreenTest.kt
Source:NavigationScreenTest.kt
...89 )90 textView.check(matches(withText("Notifications")))91 val materialButton = onView(92 allOf(93 withId(R.id.btn_close),94 childAtPosition(95 childAtPosition(96 withClassName(`is`("androidx.appcompat.widget.LinearLayoutCompat")),97 098 ),99 1100 ),101 isDisplayed()102 )103 )104 materialButton.perform(click())105 onView(withId(R.id.drawer_container_home))106 .perform(DrawerActions.open());107 Thread.sleep(1500)...
Actions.kt
Source:Actions.kt
...39 }40 /**41 * Closes soft keyboard, if opened42 */43 fun closeSoftKeyboard() {44 view.perform(ViewActions.closeSoftKeyboard())45 }46 /**47 * Idles for given amount of time48 *49 * @param duration Time to idle in milliseconds (1 second by default)50 */51 fun idle(duration: Long = 1000L) {52 view.perform(object : ViewAction {53 override fun getDescription() = "Idle for $duration milliseconds"54 override fun getConstraints() = ViewMatchers.isAssignableFrom(View::class.java)55 override fun perform(uiController: UiController?, view: View?) {56 uiController?.loopMainThreadForAtLeast(duration)57 }58 })59 }60}61/**62 * Base interface for performing actions on view63 *64 * Provides a lot of basic action methods, such as click(), scrollTo(), etc.65 *66 * @see EditableActions67 * @see SwipeableActions68 * @see ScrollableActions69 * @see CheckableActions70 */71interface BaseActions {72 val view: ViewInteraction73 /**74 * Performs click on view75 *76 * @param location Location of view where it should be clicked (VISIBLE_CENTER by default)77 */78 fun click(location: GeneralLocation = GeneralLocation.VISIBLE_CENTER) {79 view.perform(GeneralClickAction(Tap.SINGLE, location, Press.FINGER,80 InputDevice.SOURCE_UNKNOWN, MotionEvent.BUTTON_PRIMARY))81 }82 /**83 * Performs double click on view84 *85 * @param location Location of view where it should be clicked (VISIBLE_CENTER by default)86 */87 fun doubleClick(location: GeneralLocation = GeneralLocation.VISIBLE_CENTER) {88 view.perform(GeneralClickAction(Tap.DOUBLE, location, Press.FINGER,89 InputDevice.SOURCE_UNKNOWN, MotionEvent.BUTTON_PRIMARY))90 }91 /**92 * Performs long click on view93 *94 * @param location Location of view where it should be clicked (VISIBLE_CENTER by default)95 */96 fun longClick(location: GeneralLocation = GeneralLocation.VISIBLE_CENTER) {97 view.perform(GeneralClickAction(Tap.LONG, location, Press.FINGER,98 InputDevice.SOURCE_UNKNOWN, MotionEvent.BUTTON_PRIMARY))99 }100 /**101 * Scrolls to the view, if possible102 */103 fun scrollTo() {104 view.perform(ViewActions.scrollTo())105 }106 /**107 * Performs custom action on a view108 *109 * @param function Lambda that must return ViewAction which will be performed110 */111 fun act(function: () -> ViewAction) {112 view.perform(function.invoke())113 }114 /**115 * Adds failure handler to the view116 *117 * @param function Lambda that handles this view's errors118 */119 fun onFailure(function: (error: Throwable, matcher: Matcher<View>) -> Unit) {120 view.withFailureHandler(function)121 }122}123/**124 * Provides editable actions for views125 */126interface EditableActions : BaseActions {127 /**128 * Types the given text into the view129 *130 * @param text Text to input131 */132 fun typeText(text: String) {133 view.perform(ViewActions.typeText(text))134 }135 /**136 * Replaces the current view text with given137 *138 * @param text Text to input instead of current139 */140 fun replaceText(text: String) {141 view.perform(ViewActions.replaceText(text))142 }143 /**144 * Clears current text in the view145 */146 fun clearText() {147 replaceText("")148 }149}150/**151 * Provides swipe actions for views152 */153interface SwipeableActions : BaseActions {154 /**155 * Swipes left on the view156 */157 fun swipeLeft() {158 view.perform(ViewActions.swipeLeft())159 }160 /**161 * Swipes right on the view162 */163 fun swipeRight() {164 view.perform(ViewActions.swipeRight())165 }166 /**167 * Swipes up on the view168 */169 fun swipeUp() {170 view.perform(ViewActions.swipeUp())171 }172 /**173 * Swipes down on the view174 */175 fun swipeDown() {176 view.perform(ViewActions.swipeDown())177 }178}179/**180 * Provides scrolling actions for view181 *182 * Important: does not hold any implementation183 *184 * @see RecyclerActions185 * @see ScrollViewActions186 */187interface ScrollableActions : BaseActions {188 /**189 * Scrolls to the starting position of the view190 */191 fun scrollToStart()192 /**193 * Scrolls to the last position of the view194 */195 fun scrollToEnd()196 /**197 * Scrolls to the specific position of the view198 *199 * @param position Scrolling destination200 */201 fun scrollTo(position: Int)202}203/**204 * Provides ScrollableActions implementation for RecyclerView205 *206 * @see ScrollableActions207 * @see RecyclerView208 */209interface RecyclerActions : ScrollableActions {210 override fun scrollToStart() {211 view.perform(RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(0))212 }213 override fun scrollToEnd() {214 view.perform(object : ViewAction {215 override fun getDescription() = "Scroll RecyclerView to the bottom"216 override fun getConstraints() = ViewMatchers.isAssignableFrom(RecyclerView::class.java)217 override fun perform(controller: UiController, view: View) {218 if (view is RecyclerView) {219 val position = view.adapter.itemCount - 1220 view.scrollToPosition(position)221 controller.loopMainThreadUntilIdle()222 val lastView = view.findViewHolderForLayoutPosition(position).itemView223 view.scrollBy(0, lastView.height)224 controller.loopMainThreadUntilIdle()225 }226 }227 })228 }229 override fun scrollTo(position: Int) {230 view.perform(RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(position))231 }232 /**233 * Scrolls to specific view holder that matches given matcher234 *235 * @param matcher Matcher for view holder, which is scroll destination236 */237 fun scrollTo(matcher: Matcher<View>) {238 view.perform(RecyclerViewActions.scrollTo<RecyclerView.ViewHolder>(matcher))239 }240 /**241 * Scrolls to specific view holder that matches given matcher242 *243 * @param viewBuilder Builder that will be used to match view to scroll244 */245 fun scrollTo(viewBuilder: ViewBuilder.() -> Unit) {246 scrollTo(ViewBuilder().apply(viewBuilder).getViewMatcher())247 }248 /**249 * Returns the size of RecyclerView250 *251 * @return size of adapter252 *253 * @see RecyclerView254 */255 fun getSize(): Int {256 var size = 0257 view.perform(object : ViewAction {258 override fun getDescription() = "Get RecyclerView adapter size"259 override fun getConstraints() = Matchers.allOf(ViewMatchers260 .isAssignableFrom(RecyclerView::class.java), ViewMatchers.isDisplayed())261 override fun perform(uiController: UiController?, view: View?) {262 if (view is RecyclerView) {263 size = view.adapter?.itemCount!!264 }265 }266 })267 return size268 }269}270/**271 * Provides ScrollableActions implementation for ScrollView272 *273 * @see ScrollableActions274 * @see ScrollView275 */276interface ScrollViewActions : ScrollableActions {277 override fun scrollToStart() {278 view.perform(object : ViewAction {279 override fun getDescription() = "Scroll ScrollView to start"280 override fun getConstraints() = Matchers.allOf(ViewMatchers281 .isAssignableFrom(ScrollView::class.java), ViewMatchers.isDisplayed())282 override fun perform(uiController: UiController?, view: View?) {283 if (view is ScrollView) {284 view.fullScroll(View.FOCUS_UP)285 }286 }287 })288 }289 override fun scrollToEnd() {290 view.perform(object : ViewAction {291 override fun getDescription() = "Scroll ScrollView to end"292 override fun getConstraints() = Matchers.allOf(ViewMatchers293 .isAssignableFrom(ScrollView::class.java), ViewMatchers.isDisplayed())294 override fun perform(uiController: UiController?, view: View?) {295 if (view is ScrollView) {296 view.fullScroll(View.FOCUS_DOWN)297 }298 }299 })300 }301 override fun scrollTo(position: Int) {302 view.perform(object : ViewAction {303 override fun getDescription() = "Scroll ScrollView to $position Y position"304 override fun getConstraints() = Matchers.allOf(ViewMatchers305 .isAssignableFrom(ScrollView::class.java), ViewMatchers.isDisplayed())306 override fun perform(uiController: UiController?, view: View?) {307 if (view is ScrollView) {308 view.scrollTo(0, position)309 }310 }311 })312 }313 /**314 * Returns the size of ScrollView315 *316 * @return size of adapter317 *318 * @see ScrollView319 * @see AdapterView320 */321 fun getSize(): Int {322 var size = 0323 view.perform(object : ViewAction {324 override fun getDescription() = "Get AdapterView adapter size"325 override fun getConstraints() = Matchers.allOf(ViewMatchers326 .isAssignableFrom(AdapterView::class.java), ViewMatchers.isDisplayed())327 override fun perform(uiController: UiController?, view: View?) {328 if (view is AdapterView<*>) {329 size = view.count330 }331 }332 })333 return size334 }335}336/**337 * Provides action for checking views338 */339interface CheckableActions : BaseActions {340 /**341 * Sets checked state of the view342 *343 * @param checked True if checked, false otherwise344 */345 fun setChecked(checked: Boolean) {346 view.perform(object : ViewAction {347 override fun getDescription() = "performing CheckableViewAction: $checked"348 override fun getConstraints() = Matchers.allOf(ViewMatchers.isAssignableFrom(View::class.java),349 object : TypeSafeMatcher<View>() {350 override fun describeTo(description: Description) {351 description.appendText("is assignable from class: " + Checkable::class.java)352 }353 override fun matchesSafely(view: View) = Checkable::class.java.isAssignableFrom(view.javaClass)354 })355 override fun perform(uiController: UiController, view: View) {356 if (view is Checkable) view.isChecked = checked357 }358 })359 }360}361/**362 * Provides actions for navigation drawer363 */364interface DrawerActions : BaseActions {365 /**366 * Opens the navigation drawer367 *368 * @param gravity Gravity to use (Gravity.START by default)369 * @see Gravity.START370 */371 fun open(gravity: Int = Gravity.START) {372 view.perform(DrawerActions.open(gravity))373 }374 /**375 * Closes the navigation drawer376 *377 * @param gravity Gravity to use (Gravity.START by default)378 * @see Gravity.START379 */380 fun close(gravity: Int = Gravity.START) {381 view.perform(DrawerActions.close(gravity))382 }383}384/**385 * Provides action for interacting with WebViews386 *387 * @see WebView388 */389interface WebActions {390 val web: Web.WebInteraction<*>391 val ref: Atom<ElementReference>392 /**393 * Clicks on element394 */395 fun click() {...
MainScreenTest.kt
Source:MainScreenTest.kt
...71 onView(withId(R.id.flashcardEditCategory))72 .perform(typeText(MockTestData.FLASHCARD_1.category))73 onView(withId(R.id.flashcardEditFront)).perform(typeText(MockTestData.FLASHCARD_1.front))74 onView(withId(R.id.flashcardEditBack))75 .perform(typeText(MockTestData.FLASHCARD_1.back), closeSoftKeyboard())76 // Save flashcard77 onView(withId(R.id.saveFlashcardButton)).perform(click())78 // Move to list view79 onView(withId(R.id.drawerLayout)).perform(DrawerActions.open())80 onView(withId(R.id.navDrawer)).perform(navigateTo(R.id.navList))81 // Click edit on first view pager item (should be first item from initial data)82 // Need double click to set focus first83 onView(withId(R.id.editFlashcardButton)).perform(click())84 // Edit view shows correct fields85 onView(withId(R.id.flashcardEditCategory))86 .check(matches(withText(MockTestData.FLASHCARD_1.category)))87 onView(withId(R.id.flashcardEditFront))88 .check(matches(withText(MockTestData.FLASHCARD_1.front)))89 onView(withId(R.id.flashcardEditBack))...
DrawerTest.kt
Source:DrawerTest.kt
...96 .perform(navigateTo(R.id.nav_sign_out))97 onView(withId(R.id.sign_in_btn))98 .check(matches(ViewMatchers.isDisplayed()))99 activityScenario.moveToState(Lifecycle.State.DESTROYED)100 activityScenario.close()101 }102}...
MainActivityTest.kt
Source:MainActivityTest.kt
...68 @Test69 fun checkOnBackPressed_WhenDrawerIsOpen() {70 onView(withId(R.id.main_drawer_layout)).perform(DrawerActions.open())71 Espresso.pressBack()72 // Drawer must be close73 assertFalse(rule.activity.main_drawer_layout.isDrawerOpen(Gravity.START))74 assertFalse(rule.activity.isFinishing)75 }76 @Test77 fun checkOnBackPressed_WhenDrawerIsClose() {78 onView(withId(R.id.main_drawer_layout)).perform(DrawerActions.close())79 try {80 Espresso.pressBack()81 assertTrue(rule.activity.isFinishing)82 fail("Activity didn't closed.")83 } catch (e: NoActivityResumedException) {84 // Test passed85 }86 }87 @Test88 fun checkDrawerToggleButton() {89 onView(withId(R.id.main_drawer_layout)).perform(DrawerActions.close())90 // Open the drawer91 onView(withContentDescription(R.string.abc_action_bar_up_description)).perform(click())92 assertTrue(rule.activity.main_drawer_layout.isDrawerOpen(Gravity.START))93 }94}...
ContainerActivityInstrumentedTest.kt
Source:ContainerActivityInstrumentedTest.kt
1package alison.fivethingskotlin2import android.support.test.InstrumentationRegistry3import android.support.test.runner.AndroidJUnit44import android.support.test.espresso.Espresso.onView5import 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
1/*******************************************************************************2 * Copyright 2016 Allan Yoshio Hasegawa3 *4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 ******************************************************************************/16package com.hasegawa.diapp17import 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}...
StepDetailScreenTest.kt
Source:StepDetailScreenTest.kt
1/*******************************************************************************2 * Copyright 2016 Allan Yoshio Hasegawa3 *4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 ******************************************************************************/16package com.hasegawa.diapp17import android.support.test.espresso.Espresso18import android.support.test.espresso.Espresso.onView19import 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 StepDetailScreenTest : BaseTest() {33 @Test34 fun checkIfActionBarnHasUpArrow() {35 phoneMode()36 onView(allOf(withText(`is`("title3")), withId(R.id.step_title_tv)))37 .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(allOf(withText(`is`("title3")), withId(R.id.step_title_tv)))45 .perform(ViewActions.click())46 onView(withId(R.id.drawer_layout)).perform(DrawerActions.open())47 Espresso.pressBack()48 onView(withId(R.id.detail_toolbar)).check(matches(isDisplayed()))49 }50 @Test51 fun goToStepsList() {52 phoneMode()53 onView(allOf(withText(`is`("title3")), withId(R.id.step_title_tv)))54 .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 goToNewsList() {62 phoneMode()63 onView(allOf(withText(`is`("title3")), withId(R.id.step_title_tv)))64 .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(withText("ntitle1")).check(matches(isDisplayed()))68 }69}...
close
Using AI Code Generation
1import android.support.test.espresso.contrib.DrawerActions;2import android.support.test.espresso.contrib.DrawerMatchers;3import android.support.test.espresso.contrib.NavigationViewActions;4import android.support.test.espresso.contrib.RecyclerViewActions;5import android.support.test.rule.ActivityTestRule;6import android.support.v4.widget.DrawerLayout;7import android.support.v7.widget.RecyclerView;8import android.view.Gravity;9import org.hamcrest.core.AllOf;10import org.junit.Rule;11import org.junit.Test;12import static android.support.test.espresso.Espresso.onView;13import static android.support.test.espresso.action.ViewActions.click;14import static android.support.test.espresso.assertion.ViewAssertions.matches;15import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;16import static android.support.test.espresso.matcher.ViewMatchers.withId;17import static android.support.test.espresso.matcher.ViewMatchers.withText;18public class MainActivityTest {19 public ActivityTestRule<MainActivity> activityTestRule = new ActivityTestRule<>(MainActivity.class);20 public void testNavigationDrawer() {21 onView(withId(R.id.drawer_layout)).perform(DrawerActions.open(Gravity.LEFT));22 onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo(R.id.nav_share));23 onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo(R.id.nav_send));24 onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo(R.id.nav_slideshow));25 onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo(R.id.nav_manage));26 onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo(R.id.nav_gallery));27 onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo(R.id.nav_camera));28 onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo(R.id.nav_share));29 onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo(R.id.nav_send));30 onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo(R.id.nav_slideshow));31 onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo(R.id.nav_manage));32 onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo(R.id.nav_gallery));33 onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo(R.id.nav_camera));34 onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo(R.id.nav_share));35 onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo(R.id.nav_send
close
Using AI Code Generation
1public static void closeDrawer(int gravity) {2onView(isRoot()).perform(DrawerActions.close(gravity));3}4public static void openDrawer(int gravity) {5onView(isRoot()).perform(DrawerActions.open(gravity));6}7public static void swipeDownDrawer(int gravity) {8onView(isRoot()).perform(DrawerActions.swipeDown(gravity));9}10public static void swipeUpDrawer(int gravity) {11onView(isRoot()).perform(DrawerActions.swipeUp(gravity));12}13public static void swipeLeftDrawer(int gravity) {14onView(isRoot()).perform(DrawerActions.swipeLeft(gravity));15}16public static void swipeRightDrawer(int gravity) {17onView(isRoot()).perform(DrawerActions.swipeRight(gravity));18}19public static void swipeRightDrawer(int gravity) {20onView(isRoot()).perform(DrawerActions.swipeRight(gravity));21}22public static void swipeRightDrawer(int gravity) {23onView(isRoot()).perform(DrawerActions.swipeRight(gravity));24}25public static void swipeRightDrawer(int gravity) {26onView(isRoot()).perform(DrawerActions.swipeRight(gravity));27}28public static void swipeRightDrawer(int gravity) {29onView(isRoot()).perform(DrawerActions.swipeRight(gravity));30}31public static void swipeRightDrawer(int gravity) {32onView(isRoot()).perform(DrawerActions.swipeRight(gravity));33}34public static void swipeRightDrawer(int gravity) {35onView(isRoot()).perform(DrawerActions.swipe
close
Using AI Code Generation
1public static void closeDrawer() {2ViewInteraction appCompatImageButton = onView(3allOf(withContentDescription("Open navigation drawer"),4childAtPosition(5allOf(withId(R.id.toolbar),6childAtPosition(7withClassName(is("android.support.design.widget.AppBarLayout")),8isDisplayed()));9appCompatImageButton.perform(click());10}11public static void openDrawer() {12ViewInteraction appCompatImageButton = onView(13allOf(withContentDescription("Open navigation drawer"),14childAtPosition(15allOf(withId(R.id.toolbar),16childAtPosition(17withClassName(is("android.support.design.widget.AppBarLayout")),18isDisplayed()));19appCompatImageButton.perform(click());20}21public static void clickDrawerItem(String item) {22ViewInteraction navigationMenuItemView = onView(23allOf(childAtPosition(24allOf(withId(R.id.design_navigation_view),25childAtPosition(26withId(R.id.nav_view),27isDisplayed()));28navigationMenuItemView.perform(click());29}30public static void clickDrawerItem(int item) {31ViewInteraction navigationMenuItemView = onView(32allOf(childAtPosition(33allOf(withId(R.id.design_navigation_view),34childAtPosition(35withId(R.id.nav_view),36isDisplayed()));37navigationMenuItemView.perform(click());38}39public static void clickDrawerItem(int item, int item2) {40ViewInteraction navigationMenuItemView = onView(41allOf(childAtPosition(42allOf(withId(R.id.design_navigation_view),43childAtPosition(44withId(R.id.nav_view),45isDisplayed()));46navigationMenuItemView.perform(click());47ViewInteraction navigationMenuItemView2 = onView(48allOf(childAtPosition(49allOf(withId(R.id.design_navigation_view),50childAtPosition(51withId(R.id.nav_view),52isDisplayed()));53navigationMenuItemView2.perform(click());54}55public static void clickDrawerItem(int item, int item2, int item3) {56ViewInteraction navigationMenuItemView = onView(57allOf(childAtPosition(58allOf(withId(R.id.design_navigation_view),59childAtPosition(
close
Using AI Code Generation
1open() method2open(int gravity)3openDrawer() method4openDrawer(int gravity)5openDrawerWithGravity() method6openDrawerWithGravity(int gravity)
close
Using AI Code Generation
1onView(withId(R.id.drawer_layout)).perform(DrawerActions.close());2dependencies {3 androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {4 })5 androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.2', {6 })7 androidTestCompile('com.android.support.test.espresso:espresso-idling-resource:2.2.2', {8 })9 androidTestCompile('com.android.support.test:runner:0.5')10 androidTestCompile('com.android.support.test:rules:0.5')11 androidTestCompile('com.android.support.test.espresso:espresso-intents:2.2.2', {12 })13}14dependencies {15 androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {16 })17 androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.2', {18 })19 androidTestCompile('com.android.support.test.espresso:espresso-idling-resource:2.2.2', {20 })21 androidTestCompile('com.android.support.test:runner:0.5')22 androidTestCompile('com.android.support.test:rules:0.5')23 androidTestCompile('com.android.support.test.espresso:espresso-intents:2.2.2', {24 })25}
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!!