How to use pressBack method of android.support.test.espresso.Espresso class

Best Appium-espresso-driver code snippet using android.support.test.espresso.Espresso.pressBack

BudionoInstrumentedTest.kt

Source:BudionoInstrumentedTest.kt Github

copy

Full Screen

...44 onView(withId(add_to_favorite_id)).check(matches(isDisplayed()))45 /* 7) memberi tindakan klik pada tombol favorite */46 onView(withId(add_to_favorite_id)).perform(click())47 /* 8) menekan tombol kembali */48 Espresso.pressBack()// pressBack()49 /* 9) memastikan sebuah 'BottomNavigationView' telah ditampilkan */50 onView(withId(bottom_navigation)).check(matches(isDisplayed()))51 /* 10) memberikan tindakan klik pada sebuah menu favorite match di 'BottomNavigationView' */52 onView(withId(R.id.favoriteButtonId)).perform(click())53 /* 11) memberikan tindakan klik pada sebuah menu previous match di 'BottomNavigationView' */54 onView(withId(previousButtonId)).perform(click())55 /* 12) memberikan tindakan klik pada sebuah menu next match di 'BottomNavigationView' */56 onView(withId(nextButtonId)).perform(click())57 /* 13) memastikan bahwa terdapat sebuah spinner yang ditampilkan */58 onView(withId(spinner2)).check(matches(isDisplayed()))59 /* 14) tindakan klik pada spinner */60 onView(withId(spinner2)).perform(click())61 /* 15) memberi tindakan klik pada spinner */62 onView(withText("Spanish La Liga")).perform(click())63 /* 16) melakukan scroll pada recyclerview sampai dengan posisi ke-5*/64 onView(withId(listEvent2)).perform(RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(5))65 /* 17) klik item di posisi 5, untuk memastikan tampilkan detail*/66 onView(withId(listEvent2)).perform(RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(5, click()))67 /* 18) memastikan tombol favorite telah ditampilkan */68 onView(withId(add_to_favorite_id)).check(matches(isDisplayed()))69 /* 19) memberi tindakan klik pada tombol favorite */70 onView(withId(add_to_favorite_id)).perform(click())71 /* 20) menekan tombol kembali */72 Espresso.pressBack()// pressBack()73 /* 21) memberikan tindakan klik pada sebuah menu favorite match di 'BottomNavigationView' */74 onView(withId(R.id.favoriteButtonId)).perform(click())75 /* menunggu sebentar, untuk melihat item view favorite */76 sleep(1000)77 }78}...

Full Screen

Full Screen

MainActivityTest.kt

Source:MainActivityTest.kt Github

copy

Full Screen

1package com.tooqy.football_api.Event2import android.support.test.espresso.Espresso3import android.support.test.espresso.action.ViewActions4import android.support.test.espresso.action.ViewActions.click5import android.support.test.espresso.action.ViewActions.pressBack6import android.support.test.espresso.assertion.ViewAssertions7import android.support.test.espresso.contrib.RecyclerViewActions8import android.support.test.espresso.matcher.ViewMatchers9import android.support.test.rule.ActivityTestRule10import android.support.test.runner.AndroidJUnit411import android.support.v7.widget.RecyclerView12import com.tooqy.football_api.MainActivity13import com.tooqy.football_api.R.id.*14import org.junit.Rule15import org.junit.Test16import org.junit.runner.RunWith17@RunWith(AndroidJUnit4::class)18class MainActivityTest {19 @Rule20 @JvmField21 var activityRule = ActivityTestRule(MainActivity::class.java)22 @Test23 fun testRecyclerViewBehaviour() {24 sleep_for_awhile()25 Espresso.onView(ViewMatchers.withId(main_list_view_last))26 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))27 sleep_for_awhile()28 Espresso.onView(ViewMatchers.withId(main_list_view_last)).perform(29 RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(3))30 Espresso.onView(ViewMatchers.withId(main_list_view_last)).perform(31 RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(3, click()))32 sleep_for_awhile(3000)33 pressBack()34 }35 @Test36 fun testAppBehaviour() {37 // Click Prev. Match38 Espresso.onView(ViewMatchers.withId(nav_last_match))39 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))40 Espresso.onView(ViewMatchers.withId(nav_last_match)).perform(click())41 sleep_for_awhile()42 // Cek Tab Next Match43 Espresso.onView(ViewMatchers.withId(nav_next_match))44 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))45 Espresso.onView(ViewMatchers.withId(nav_next_match)).perform(click())46 sleep_for_awhile()47 // Cek Tab Favorite48 Espresso.onView(ViewMatchers.withId(nav_favorite))49 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))50 Espresso.onView(ViewMatchers.withId(nav_favorite)).perform(click())51 sleep_for_awhile()52 pressBack()53 sleep_for_awhile()54 }55 @Test56 fun testAppFavorite() {57 // Cek Tab Next Match58 Espresso.onView(ViewMatchers.withId(nav_last_match))59 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))60 Espresso.onView(ViewMatchers.withId(nav_last_match)).perform(click())61 sleep_for_awhile(1000)62 // Display List Last Match63 Espresso.onView(ViewMatchers.withId(main_list_view_last)).perform(64 RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(4))65 Espresso.onView(ViewMatchers.withId(main_list_view_last)).perform(66 RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(4, click()))67 sleep_for_awhile()68 // Click Favorite Star69 Espresso.onView(ViewMatchers.withId(add_to_favorite))70 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))71 Espresso.onView(ViewMatchers.withId(add_to_favorite)).perform(ViewActions.click())72 sleep_for_awhile()73 // Back to main page74 Espresso.pressBack()75 sleep_for_awhile()76 // Cek / Display Tab Favorite77 Espresso.onView(ViewMatchers.withId(nav_favorite))78 .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))79 Espresso.onView(ViewMatchers.withId(nav_favorite)).perform(click())80 sleep_for_awhile()81 pressBack()82 }83 private fun sleep_for_awhile(timetosleep: Long = 2000) {84 try {85 Thread.sleep(timetosleep)86 } catch (e: InterruptedException) {87 e.printStackTrace()88 }89 }90}...

Full Screen

Full Screen

NavigationTest.kt

Source:NavigationTest.kt Github

copy

Full Screen

1package me.uport.sdk.demoapp2import android.support.test.espresso.Espresso.onData3import android.support.test.espresso.Espresso.onView4import android.support.test.espresso.Espresso.pressBack5import android.support.test.espresso.action.ViewActions.click6import android.support.test.espresso.assertion.ViewAssertions7import android.support.test.espresso.intent.Intents.intended8import android.support.test.espresso.intent.matcher.IntentMatchers.hasComponent9import android.support.test.espresso.intent.rule.IntentsTestRule10import android.support.test.espresso.matcher.ViewMatchers.isDisplayed11import android.support.test.espresso.matcher.ViewMatchers.withId12import me.uport.sdk.demoapp.key_protection.FingerPrintProtectionActivity13import me.uport.sdk.demoapp.key_protection.KeyGuardProtectionActivity14import me.uport.sdk.demoapp.key_protection.KeyProtectionListActivity15import me.uport.sdk.demoapp.managing_jwt.SignJWTKeyPairSignerActivity16import me.uport.sdk.demoapp.managing_jwt.SignJWTListActivity17import me.uport.sdk.demoapp.managing_jwt.SignJWTUportHDSignerActivity18import org.hamcrest.CoreMatchers.anything19import org.junit.Rule20import org.junit.Test21class NavigationTest {22 @get:Rule23 val activityRule = IntentsTestRule(MainListActivity::class.java)24 @Test25 fun listIsDisplayed() {26 onView(withId(me.uport.sdk.demoapp.R.id.item_list)).check(ViewAssertions.matches(isDisplayed()))27 }28 @Test29 fun navigateAllActivities() {30 // check if CreateAccountActivity is launched31 onData(anything()).inAdapterView(withId(R.id.item_list)).atPosition(0).perform(click())32 intended(hasComponent(CreateAccountActivity::class.java.name))33 pressBack()34 // check if CreateKeyActivity is launched35 onData(anything()).inAdapterView(withId(R.id.item_list)).atPosition(1).perform(click())36 intended(hasComponent(CreateKeyActivity::class.java.name))37 pressBack()38 // check if ImportKeyActivity is launched39 onData(anything()).inAdapterView(withId(R.id.item_list)).atPosition(2).perform(click())40 intended(hasComponent(ImportKeyActivity::class.java.name))41 pressBack()42 // check if KeyProtectionListActivity is launched43 onData(anything()).inAdapterView(withId(R.id.item_list)).atPosition(3).perform(click())44 intended(hasComponent(KeyProtectionListActivity::class.java.name))45 // check if KeyGuardProtectionActivity is launched46 onData(anything()).inAdapterView(withId(R.id.item_list)).atPosition(0).perform(click())47 intended(hasComponent(KeyGuardProtectionActivity::class.java.name))48 pressBack()49 // check if FingerPrintProtectionActivity is launched50 onData(anything()).inAdapterView(withId(R.id.item_list)).atPosition(1).perform(click())51 intended(hasComponent(FingerPrintProtectionActivity::class.java.name))52 pressBack()53 // back to MainListActivity54 pressBack()55 // check if SignJWTListActivity is launched56 onData(anything()).inAdapterView(withId(R.id.item_list)).atPosition(4).perform(click())57 intended(hasComponent(SignJWTListActivity::class.java.name))58 // check if SignJWTKeyPairSignerActivity is launched59 onData(anything()).inAdapterView(withId(R.id.item_list)).atPosition(0).perform(click())60 intended(hasComponent(SignJWTKeyPairSignerActivity::class.java.name))61 pressBack()62 // check if SignJWTUportHDSignerActivity is launched63 onData(anything()).inAdapterView(withId(R.id.item_list)).atPosition(1).perform(click())64 intended(hasComponent(SignJWTUportHDSignerActivity::class.java.name))65 pressBack()66 // back to MainListActivity67 pressBack()68 }69}...

Full Screen

Full Screen

ConfirmCloseDialogTest.kt

Source:ConfirmCloseDialogTest.kt Github

copy

Full Screen

1package com.tpb.brainfuck.runner2import android.content.Intent3import android.support.test.espresso.Espresso.onView4import android.support.test.espresso.Espresso.pressBack5import android.support.test.espresso.action.ViewActions.click6import android.support.test.espresso.assertion.ViewAssertions7import android.support.test.espresso.matcher.ViewMatchers.*8import android.support.test.rule.ActivityTestRule9import android.support.test.runner.AndroidJUnit410import android.view.View11import com.tpb.brainfuck.R12import com.tpb.brainfuck.db.Program13import org.hamcrest.Matchers.allOf14import org.junit.Assert.assertFalse15import org.junit.Assert.assertTrue16import org.junit.Rule17import org.junit.Test18import org.junit.runner.RunWith19@RunWith(AndroidJUnit4::class)20class ConfirmCloseDialogTest {21 @JvmField @Rule22 var activityTestRule = ActivityTestRule(Runner::class.java, true, false)23 val program = Program(source = ">++++++++++>>>+>+[>>>+[-[<<<<<[+<<<<<]>>[[-]>[<<+>+>-]<[>+<-]<[>+<-[>+<-[>\n" +24 "+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>[-]>>>>+>+<<<<<<-[>+<-]]]]]]]]]]]>[<+>-\n" +25 "]+>>>>>]<<<<<[<<<<<]>>>>>>>[>>>>>]++[-<<<<<]>>>>>>-]+>>>>>]<[>++<-]<<<<[<[\n" +26 ">+<-]<<<<]>>[->[-]++++++[<++++++++>-]>>>>]<<<<<[<[>+>+<<-]>.<<<<<]>.>>>>]"27 ) //Non-ending program28 val intent: Intent = Intent()29 init {30 intent.putExtra("parcel_program", program)31 }32 @Test fun testConfirmCloseDialogShown() {33 activityTestRule.launchActivity(intent)34 onView(allOf<View>(withId(R.id.play_pause_button), isDisplayed()))35 .perform(click())36 .perform(click())37 pressBack()38 onView(withText("Confirm")).check(ViewAssertions.matches(isDisplayed()))39 }40 @Test fun testConfirmCloseDialogCancel() {41 activityTestRule.launchActivity(intent)42 onView(allOf<View>(withId(R.id.play_pause_button), isDisplayed()))43 .perform(click())44 .perform(click())45 pressBack()46 onView(withText("Confirm")).check(ViewAssertions.matches(isDisplayed()))47 onView(withText("Cancel")).perform(click())48 assertFalse(activityTestRule.activity.isFinishing)49 }50 @Test fun testConfirmCloseDialogOK() {51 activityTestRule.launchActivity(intent)52 onView(allOf<View>(withId(R.id.play_pause_button), isDisplayed()))53 .perform(click())54 .perform(click())55 pressBack()56 onView(withText("Confirm")).check(ViewAssertions.matches(isDisplayed()))57 onView(withText("OK")).perform(click())58 assertTrue(activityTestRule.activity.isFinishing)59 }60}...

Full Screen

Full Screen

MapsActivityTest.kt

Source:MapsActivityTest.kt Github

copy

Full Screen

...35 onView(withId(R.id.viewPager)).perform(swipeDown())36 onView(allOf(withId(R.id.pubDescription), isDescendantOfA(nthChildOf(withId(R.id.viewPager), 0)))).check(matches(not(isDisplayed())))37 onView(allOf(withId(R.id.pubLogo), isDisplayed())).perform(click())38 onView(allOf(withId(R.id.pubDescription), isDisplayed()))39 Espresso.pressBack()40 onView(allOf(withId(R.id.pubDescription), isDescendantOfA(nthChildOf(withId(R.id.viewPager), 0)))).check(matches(not(isDisplayed())))41 Espresso.pressBack()42 onView(allOf(withId(R.id.pubLogo), isDescendantOfA(nthChildOf(withId(R.id.viewPager), 0)))).check(matches(not(isDisplayed())))43 }44}...

Full Screen

Full Screen

MapsActivityTest2.kt

Source:MapsActivityTest2.kt Github

copy

Full Screen

...31 pubLogo.descendantOf(viewPager).checkIsDisplayed()32 viewPager.performSwipeDown()33 pubDescription.descendantOf(viewPager).checkIsNotDisplayed()34 pubLogo.descendantOf(viewPager).performClick()35 Espresso.pressBack()36 pubDescription.descendantOf(viewPager).checkIsNotDisplayed()37 Espresso.pressBack()38 pubLogo.descendantOf(viewPager).checkIsNotDisplayed()39 }40}41fun Int.descendantOf(parentId: Int, position: Int = 0) =42 onView(descendantOfMatcher(parentId, position))!!43fun Int.descendantOfMatcher(parentId: Int, position: Int = 0) =44 allOf(withId(this), isDescendantOfA(nthChildOf(withId(parentId), position)))!!...

Full Screen

Full Screen

SimpleMathTest.kt

Source:SimpleMathTest.kt Github

copy

Full Screen

...25 fun testButtonSum() {26 Thread.sleep(1000)27 onView(withId(R.id.button_sum)).perform(click())28 Thread.sleep(1000)29 Espresso.pressBack()30 }31 @Test32 fun testButtonMulty() {33 Thread.sleep(1000)34 onView(withId(R.id.button_multiply)).perform(click())35 Thread.sleep(1000)36 Espresso.pressBack()37 }38 @Test39 fun testButtonFib() {40 Thread.sleep(1000)41 onView(withId(R.id.button_fibo)).perform(click())42 Thread.sleep(1000)43 Espresso.pressBack()44 }45 @Test46 fun testButtonPrime() {47 Thread.sleep(1000)48 onView(withId(R.id.button_prime)).perform(click())49 Thread.sleep(1000)50 Espresso.pressBack()51 }52}...

Full Screen

Full Screen

HelpUITest.kt

Source:HelpUITest.kt Github

copy

Full Screen

1package de.qabel.qabelbox.ui2import android.support.test.espresso.Espresso.onView3import android.support.test.espresso.Espresso.pressBack4import android.support.test.espresso.action.ViewActions.click5import android.support.test.espresso.matcher.ViewMatchers.withText6import de.qabel.qabelbox.R7import de.qabel.qabelbox.ui.matcher.ToolbarMatcher8import org.junit.Ignore9import org.junit.Test10class HelpUITest : AbstractUITest(){11 @Ignore("Drawer layout rebuild")12 @Test13 fun testShowHelp() {14 launchActivity(null)15 //DrawerActions.openDrawer(R.id.drawer_layout)16 onView(withText(R.string.help)).perform(click())17 ToolbarMatcher.matchToolbarTitle(mActivity.getString(R.string.headline_main_help))18 val headers = mActivity.resources.getStringArray(R.array.help_headlines);19 onView(withText(R.string.help_main_headline_data_policy)).perform(click());20 ToolbarMatcher.matchToolbarTitle(headers[0]);21 pressBack();22 onView(withText(R.string.help_main_headline_tou)).perform(click());23 ToolbarMatcher.matchToolbarTitle(headers[1]);24 pressBack();25 onView(withText(R.string.help_main_headline_about_us)).perform(click());26 ToolbarMatcher.matchToolbarTitle(headers[2]);27 pressBack();28 ToolbarMatcher.matchToolbarTitle(mActivity.getString(R.string.headline_main_help))29 }30}...

Full Screen

Full Screen

pressBack

Using AI Code Generation

copy

Full Screen

1Espresso.pressBack();2Espresso.pressBackUnconditionally();3EspressopressKey(KeyEvent event);4Espresso.pressMenuKey();5Espresso.pressMenuItemId(int id);6Espresso.pressBack();7Espresso.pressBackUnconditionally();8Espresso.pressKey(KeyEvent event);9Espresso.pressMenuKey();10Espresso.pressMenuItemId(int id);11Espresso.pressBack();12Espresso.pressBackUnconditionally();13Espresso.pressKey(KeyEvent event);14Espresso.pressMenuKey();15Espresso.pressMenuItemId(int id);16Espresso.pressBack();17Espresso.pressBackUnconditionally();18Espresso.pressKey(KeyEvent event);19Espresso.pressMenuKey();20Espresso.pressMenuItemId(int id);21Espresso.pressBack();

Full Screen

Full Screen

pressBack

Using AI Code Generation

copy

Full Screen

1Espresso.pressBack();2Espresso.pressBackUnconditionally();3Espresso.pressKey(KeyEvent event);4Espresso.pressMenuKey();5Espresso.pressMenuItemId(int id);6Espresso.pressBack();7Espresso.pressBackUnconditionally();

Full Screen

Full Screen

pressBack

Using AI Code Generation

copy

Full Screen

1Espresso.pressMenuKey();2Espresso.pressMenuItemId(int id);3Espresso.pressBack();4Espresso.pressBackUnconditionally();5Espresso.pressKey(KeyEvent event);6Espresso.pressMenuKey();7Espresso.pressMenuItemId(int id);8Espresso.pressBack();9Espresso.pressBackUnconditionally();10Espresso.pressKey(KeyEvent event);11Espresso.pressMenuKey();12Espresso.pressMenuItemId(int id);13Espresso.pressBack();

Full Screen

Full Screen

Automation Testing Tutorials

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

LambdaTest Learning Hubs:

YouTube

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

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

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful