Best Appium-espresso-driver code snippet using android.support.test.espresso.matcher.RootMatchers.isPlatformPopup
Helpers.kt
Source:Helpers.kt
...74 onView(withId(R.id.edit_account_start_sum)).perform(typeText(RadisTest.ACCOUNT_START_SUM_2))75 scrollThenTypeText(R.id.edit_account_desc, RadisTest.ACCOUNT_DESC_2)76 clickOnActionItemConfirm()77 onView(allOf(withId(R.id.account_spinner), isDisplayed())).perform(click())78 onView(allOf(iz(instanceOf(ListView::class.java)), isDisplayed()) as Matcher<View>).inRoot(RootMatchers.isPlatformPopup()).check(has(2, RelativeLayout::class.java))79 onView(withText(RadisTest.ACCOUNT_NAME)).inRoot(RootMatchers.isPlatformPopup()).perform(click())80 }81 fun addAccount3() {82 callAccountCreation()83 checkTitleBarDisplayed(R.string.account_creation)84 onView(withId(R.id.edit_account_name)).perform(typeText(RadisTest.ACCOUNT_NAME_3))85 onView(withId(R.id.edit_account_start_sum)).perform(typeText(RadisTest.ACCOUNT_START_SUM))86 scrollThenTypeText(R.id.edit_account_desc, RadisTest.ACCOUNT_DESC)87 clickOnActionItemConfirm()88 onView(allOf(withId(R.id.account_spinner), isDisplayed())).perform(click())89 onView(allOf(iz(instanceOf(ListView::class.java)), isDisplayed()) as Matcher<View>).inRoot(RootMatchers.isPlatformPopup()).check(has(3, RelativeLayout::class.java))90 onView(withText(RadisTest.ACCOUNT_NAME)).inRoot(RootMatchers.isPlatformPopup()).perform(click())91 }92 fun addOp(date: DateTime, third: String = "Toto", amount: String = "-1", tag: String = "", mode: String = "", desc: String = "") {93 onView(withId(R.id.create_operation)).perform(click())94 checkTitleBarDisplayed(R.string.op_creation)95 Helpers.setDateOnPicker(R.id.op_date_btn, date)96 fillOpForm(third, amount, tag, mode, desc)97 clickOnActionItemConfirm()98 }99 fun addOp(third: String, amount: String, tag: String, mode: String, desc: String) {100 onView(withId(R.id.create_operation)).perform(click())101 checkTitleBarDisplayed(R.string.op_creation)102 fillOpForm(third, amount, tag, mode, desc)103 clickOnActionItemConfirm()104 }105 fun addManyOps() {106 addAccount()107 for (j in 0..9) {108 addOp(RadisTest.OP_TP, RadisTest.OP_AMOUNT_2, RadisTest.OP_TAG, RadisTest.OP_MODE, RadisTest.OP_DESC)109 Helpers.pauseTest(600)110 }111 onView(withText(R.string.no_operation)).check(matches(not(isDisplayed())))112 checkAccountSumIs(0.5.formatSum())113 }114 fun addOp() {115 addOp(RadisTest.OP_TP, RadisTest.OP_AMOUNT, RadisTest.OP_TAG, RadisTest.OP_MODE, RadisTest.OP_DESC)116 }117 fun setEdtPrefValue(key: Int, value: String) {118 onView(withText(key)).perform(click())119 onView(allOf(iz(instanceOf(EditText::class.java)), hasFocus()) as Matcher<View>).perform(replaceText(value))120 Espresso.closeSoftKeyboard()121 pauseTest(2000) // needed to workaround espresso 2.0 bug122 clickOnDialogButton(R.string.ok)123 }124 fun setInsertDatePref(date: DateTime) {125 setEdtPrefValue(R.string.prefs_insertion_date_label, Integer.toString(date.day))126 }127 fun setUpSchOp() {128 addAccount()129 clickInDrawer(R.string.preferences)130 setInsertDatePref(DateTime.today(TIME_ZONE).plusDays(1))131 Espresso.pressBack()132 clickInDrawer(R.string.scheduled_ops)133 onView(withText(R.string.no_operation_sch)).check(matches(isDisplayed()))134 }135 // add a sch op today, 9.50, monthly136 fun addScheduleOp(date: DateTime) {137 onView(withId(R.id.create_operation)).perform(click())138 checkTitleBarDisplayed(R.string.sch_edition)139 Helpers.setDateOnPicker(R.id.op_date_btn, date)140 fillOpForm(RadisTest.OP_TP, "9.50", RadisTest.OP_TAG, RadisTest.OP_MODE, RadisTest.OP_DESC)141 clickOnSpinner(R.id.periodicity_choice, R.array.periodicity_choices, 1)142 clickOnActionItemConfirm()143 onView(withText(R.string.no_operation_sch)).check(matches(not(isDisplayed())))144 // TODO assertEquals(1, solo!!.getCurrentViews(javaClass<ListView>()).get(0).getCount())145 Espresso.pressBack()146 // TODO assertEquals(1, solo!!.getCurrentViews(javaClass<ListView>()).get(0).getCount())147 }148 fun setupDelOccFromOps(): Int {149 setUpSchOp()150 onView(withId(R.id.create_operation)).perform(click())151 checkTitleBarDisplayed(R.string.sch_edition)152 val today = DateTime.today(TIME_ZONE)153 val schOpDate = today.minusDays(14)154 Helpers.setDateOnPicker(R.id.op_date_btn, schOpDate)155 fillOpForm(RadisTest.OP_TP, "1.00", RadisTest.OP_TAG, RadisTest.OP_MODE, RadisTest.OP_DESC)156 onView(withId(R.id.periodicity_choice)).perform(scrollTo())157 onView(withId(R.id.periodicity_choice)).perform(click())158 val strs = getContext().resources.getStringArray(R.array.periodicity_choices).get(0)159 onData(allOf(iz(instanceOf(String::class.java)), iz(equalTo(strs)))).perform(click())160 clickOnActionItemConfirm()161 Espresso.pressBack() // back to operations list162 Helpers.pauseTest(2000)163 val endOfMonth = today.endOfMonth164 val nbOp = endOfMonth.getWeekIndex(schOpDate)165 Log.d("RadisTest", "nb op inserted: $nbOp")166 checkAccountSumIs((1000.5 - nbOp).formatSum())167 return nbOp168 }169 fun swipePagerLeft() {170 onView(withId(R.id.pager)).perform(ViewActions.swipeLeft())171 Espresso.closeSoftKeyboard()172 }173 fun swipePagerRight() {174 onView(withId(R.id.pager)).perform(ViewActions.swipeRight())175 Espresso.closeSoftKeyboard()176 }177 fun pauseTest(t: Long) {178 try {179 Thread.sleep(t)180 } catch (e: Exception) {181 }182 }183 fun actionOnOpListAtPosition(pos: Int, viewAction: ViewAction) =184 actionOnItemAtPosition<OpRowHolder<Operation>>(pos, viewAction)185 fun clickOnDialogButton(textId: Int) = onView(allOf(iz(instanceOf(Button::class.java)), withText(textId),186 isDisplayed()) as Matcher<View>).perform(click())187 fun clickOnDialogButton(text: String) = onView(allOf(iz(instanceOf(Button::class.java)), withText(text),188 isDisplayed()) as Matcher<View>).perform(click())189 fun scrollRecyclerViewToPos(pos: Int) {190 onView(withId(R.id.operation_list)).perform(RecyclerViewActions.scrollToPosition<OpRowHolder<Operation>>(pos))191 }192 fun clickOnRecyclerViewAtPos(pos: Int) {193 onView(withId(R.id.operation_list)).perform(Helpers.actionOnOpListAtPosition(pos, click()))194 Helpers.pauseTest(500)195 }196 fun checkAccountSumIs(text: String) =197 onView(withId(R.id.account_sum)).check(matches(withText(containsString(text))))198 fun scrollThenTypeText(edtId: Int, str: String) {199 val v = onView(withId(edtId)).perform(scrollTo())200 Helpers.pauseTest(500)201 v.perform(replaceText("")).perform(typeText(str))202 }203 fun clickOnSpinner(spinnerId: Int, arrayResId: Int, pos: Int) {204 onView(withId(spinnerId)).perform(scrollTo())205 Helpers.pauseTest(500)206 onView(withId(spinnerId)).perform(click())207 Helpers.pauseTest(500)208 val strs = getContext().resources.getStringArray(arrayResId).get(pos)209 onData(allOf(iz(instanceOf(String::class.java)), iz(equalTo(strs)))).perform(click())210 }211 fun clickOnSpinner(spinnerId: Int, text: String) {212 onView(withId(spinnerId)).perform(scrollTo())213 Helpers.pauseTest(500)214 onView(withId(spinnerId)).perform(click())215 Helpers.pauseTest(500)216 onView(withText(equalTo(text))).perform(click())217 }218 fun clickOnAccountSpinner(accName: String) {219 onView(allOf(withId(R.id.account_spinner), isDisplayed())).perform(click())220 pauseTest(500)221 onView(withText(accName)).inRoot(RootMatchers.isPlatformPopup()).perform(click())222 }223 fun checkSelectedSumIs(text: String) =224 onView(allOf(withId(R.id.today_amount), isDisplayed(),225 withText(not(equalTo(""))))).check(matches(withText(containsString(text))))226 fun fillOpForm(third: String, amount: String, tag: String, mode: String, desc: String) {227 scrollThenTypeText(R.id.edit_op_third_party, third)228 scrollThenTypeText(R.id.edit_op_sum, amount)229 scrollThenTypeText(R.id.edit_op_tag, tag)230 scrollThenTypeText(R.id.edit_op_mode, mode)231 scrollThenTypeText(R.id.edit_op_notes, desc)232 }233 fun goToCurAccountOptionPanel() {234 Helpers.clickInDrawer(R.string.account_edit)235 Helpers.checkTitleBarDisplayed(R.string.account_edit_title)...
Builders.kt
Source:Builders.kt
...311 }312 /**313 * Matches root that is platform popup314 */315 fun isPlatformPopup() {316 rootMatchers.add(RootMatchers.isPlatformPopup())317 }318 /**319 * Matches root that is not platform popup320 */321 fun isNotPlatformPopup() {322 rootMatchers.add(Matchers.not(RootMatchers.isPlatformPopup()))323 }324 /**325 * Matches root that is touchable326 */327 fun isTouchable() {328 rootMatchers.add(RootMatchers.isTouchable())329 }330 /**331 * Matches root that is not touchable332 */333 fun isNotTouchable() {334 rootMatchers.add(Matchers.not(RootMatchers.isTouchable()))335 }336 /**...
SessionRobot.kt
Source:SessionRobot.kt
...136 fun clickTextActionMore() {137 // Since text action popup menu is control by framework and we need to click overflow button to show the target string,138 // it's not easy to find a good way to let espresso track that button. So use ImageButton class name to find the target for now.139 onView(withClassName(Matchers.containsString("ImageButton")))140 .inRoot(RootMatchers.isPlatformPopup())141 .perform(click())142 }143 fun checkSearchInRocketIsDisplayed() {144 onView(withText(R.string.text_selection_search_action))145 .inRoot(RootMatchers.isPlatformPopup())146 .check(matches(isDisplayed()))147 }148 fun goHome(activity: Activity) {149 val intent = Intent()150 intent.action = Intent.ACTION_MAIN151 intent.addCategory(Intent.CATEGORY_HOME)152 activity.startActivity(intent)153 }154 fun bringToForeground(activity: Activity) {155 val intent = Intent(activity, MainActivity::class.java)156 intent.flags = Intent.FLAG_ACTIVITY_REORDER_TO_FRONT157 activity.startActivity(intent)158 }159}...
MapActivityTest.kt
Source:MapActivityTest.kt
...23import android.support.test.espresso.Espresso.onView24import android.support.test.espresso.action.ViewActions.click25import android.support.test.espresso.action.ViewActions.typeText26import android.support.test.espresso.assertion.ViewAssertions.matches27import android.support.test.espresso.matcher.RootMatchers.isPlatformPopup28import android.support.test.espresso.matcher.ViewMatchers.*29import android.support.test.filters.LargeTest30import android.support.test.rule.ActivityTestRule31import android.support.test.rule.GrantPermissionRule32import android.support.test.runner.AndroidJUnit433import de.grobox.transportr.R34import de.grobox.transportr.ScreengrabTest35import de.grobox.transportr.data.DbTest36import de.grobox.transportr.data.locations.FavoriteLocation37import de.grobox.transportr.data.locations.FavoriteLocation.FavLocationType.FROM38import de.grobox.transportr.data.locations.FavoriteLocation.FavLocationType.TO39import de.grobox.transportr.data.locations.LocationRepository40import de.grobox.transportr.data.searches.SearchesRepository41import de.grobox.transportr.favorites.trips.FavoriteTripItem42import de.grobox.transportr.networks.TransportNetwork43import de.grobox.transportr.networks.TransportNetworkManager44import de.grobox.transportr.waitForId45import org.hamcrest.CoreMatchers.anything46import org.junit.Assert.assertEquals47import org.junit.Before48import org.junit.FixMethodOrder49import org.junit.Rule50import org.junit.Test51import org.junit.runner.RunWith52import org.junit.runners.MethodSorters53import javax.inject.Inject54@LargeTest55@RunWith(AndroidJUnit4::class)56@FixMethodOrder(MethodSorters.NAME_ASCENDING)57class MapActivityTest : ScreengrabTest() {58 @Rule59 @JvmField60 val activityRule = ActivityTestRule(MapActivity::class.java)61 @Rule62 @JvmField63 val permissionRule: GrantPermissionRule = GrantPermissionRule.grant(Manifest.permission.ACCESS_FINE_LOCATION)64 @Inject65 lateinit var manager: TransportNetworkManager66 @Inject67 lateinit var locationRepository: LocationRepository68 @Inject69 lateinit var searchesRepository: SearchesRepository70 @Before71 override fun setUp() {72 super.setUp()73 activityRule.runOnUiThread {74 component.inject(this)75 val transportNetwork: TransportNetwork = manager.getTransportNetworkByNetworkId(networkId) ?: throw RuntimeException()76 manager.setTransportNetwork(transportNetwork)77 // ensure networkId got updated before continuing78 assertEquals(networkId, DbTest.getValue(manager.networkId))79 }80 }81 @Test82 fun favoritesTest() {83 locationRepository.setHomeLocation(getFrom(0))84 locationRepository.setWorkLocation(getTo(0))85 locationRepository.addFavoriteLocation(getFrom(1), FROM)86 locationRepository.addFavoriteLocation(getTo(1), TO)87 locationRepository.addFavoriteLocation(getFrom(2), FROM)88 locationRepository.addFavoriteLocation(getTo(2), TO)89 onView(isRoot()).perform(waitForId(R.id.title))90 locationRepository.favoriteLocations.observe(activityRule.activity, Observer { this.addSavedSearches(it) })91 onView(isRoot()).perform(waitForId(R.id.fromIcon))92 sleep(2500)93 makeScreenshot("2_SavedSearches")94 }95 @Test96 fun searchLocationShowDeparturesTest() {97 // search for station98 onView(withId(R.id.location))99 .perform(typeText(departureStation))100 // click station101 onData(anything())102 .inRoot(isPlatformPopup())103 .atPosition(0)104 .perform(click())105 // assert bottom sheet is shown106 onView(withId(R.id.bottomSheet))107 .check(matches(isDisplayed()))108 onView(withId(R.id.locationName))109 .check(matches(withText(departureStation)))110 onView(withId(R.id.locationIcon))111 .check(matches(isDisplayed()))112 // expand bottom sheet113 onView(withId(R.id.locationName))114 .perform(click())115 onView(withId(R.id.departuresButton))116 .check(matches(isDisplayed()))...
UITest.kt
Source:UITest.kt
...83 onView(withId(R.id.button_pas)).perform(click())84 Thread.sleep(1000)85 //Change team(popup)86 onView(withText("OK"))87 .inRoot(RootMatchers.isPlatformPopup())88 .perform(click())89 Thread.sleep(1000)90 onView(withId(R.id.button_to_start)).perform(click())91 Thread.sleep(1000)92 onView(withId(R.id.button_guessed)).perform(click())93 Thread.sleep(1000)94 onView(withId(R.id.button_guessed)).perform(click())95 Thread.sleep(1000)96 onView(withId(R.id.button_guessed)).perform(click())97 Thread.sleep(1000)98 onView(withId(R.id.button_guessed)).perform(click())99 Thread.sleep(1000)100 //Go to Statistics101 onView(withText("СÑаÑиÑÑика"))102 .inRoot(RootMatchers.isPlatformPopup())103 .perform(click())104 Thread.sleep(2000)105 //Go to Main Activity106 onView(withId(R.id.button_go_to_main)).perform(click())107 Thread.sleep(2000)108 }109}...
ViewMatchersTest.kt
Source:ViewMatchersTest.kt
...14import android.support.test.espresso.matcher.PreferenceMatchers.withKey15import android.support.test.espresso.matcher.PreferenceMatchers.withSummaryText16import android.support.test.espresso.matcher.PreferenceMatchers.withTitle17import android.support.test.espresso.matcher.RootMatchers.isDialog18import android.support.test.espresso.matcher.RootMatchers.isPlatformPopup19import android.support.test.espresso.matcher.RootMatchers.isTouchable20import android.support.test.espresso.matcher.ViewMatchers.hasContentDescription21import android.support.test.espresso.matcher.ViewMatchers.hasDescendant22import android.support.test.espresso.matcher.ViewMatchers.hasImeAction23import android.support.test.espresso.matcher.ViewMatchers.hasSibling24import android.support.test.espresso.matcher.ViewMatchers.isAssignableFrom25import android.support.test.espresso.matcher.ViewMatchers.isChecked26import android.support.test.espresso.matcher.ViewMatchers.isDescendantOfA27import android.support.test.espresso.matcher.ViewMatchers.isDisplayed28import android.support.test.espresso.matcher.ViewMatchers.isEnabled29import android.support.test.espresso.matcher.ViewMatchers.isFocusable30import android.support.test.espresso.matcher.ViewMatchers.isSelected31import android.support.test.espresso.matcher.ViewMatchers.supportsInputMethods32import android.support.test.espresso.matcher.ViewMatchers.withChild33import android.support.test.espresso.matcher.ViewMatchers.withClassName34import android.support.test.espresso.matcher.ViewMatchers.withContentDescription35import android.support.test.espresso.matcher.ViewMatchers.withHint36import android.support.test.espresso.matcher.ViewMatchers.withId37import android.support.test.espresso.matcher.ViewMatchers.withParent38import android.support.test.espresso.matcher.ViewMatchers.withText39import org.hamcrest.CoreMatchers.allOf40import org.hamcrest.CoreMatchers.`is`41import org.hamcrest.CoreMatchers.not42/**43 * Lists all ViewMatchers. ViewMatchers here are without functional load.44 * This is done for demonstration purposes.45 */46@RunWith(AndroidJUnit4::class)47class ViewMatchersTest {48 @Test49 fun userProperties() {50 onView(withId(R.id.fab_add_task))51 onView(withText("All TO-DOs"))52 onView(withContentDescription(R.string.menu_filter))53 onView(hasContentDescription())54 onView(withHint(R.string.name_hint))55 }56 @Test57 fun uiProperties() {58 onView(isDisplayed())59 onView(isEnabled())60 onView(isChecked())61 onView(isSelected())62 }63 @Test64 fun objectMatcher() {65 onView(not<View>(isChecked()))66 onView(allOf<View>(withText("item 1"), isChecked()))67 }68 @Test69 fun hierarchy() {70 onView(withParent(withId(R.id.todo_item)))71 onView(withChild(withText("item 2")))72 onView(isDescendantOfA(withId(R.id.todo_item)))73 onView(hasDescendant(isChecked()))74 .check(matches(isDisplayed()))75 .check(matches(isFocusable()))76 onView(hasSibling(withContentDescription(R.string.menu_filter)))77 }78 @Test79 fun input() {80 onView(supportsInputMethods())81 onView(hasImeAction(EditorInfo.IME_ACTION_SEND))82 }83 @Test84 fun classMatchers() {85 onView(isAssignableFrom(CheckBox::class.java))86 onView(withClassName(`is`(FloatingActionButton::class.java.canonicalName)))87 }88 @Test89 fun rootMatchers() {90 onView(isFocusable())91 onView(withText(R.string.name_hint)).inRoot(isTouchable())92 onView(withText(R.string.name_hint)).inRoot(isDialog())93 onView(withText(R.string.name_hint)).inRoot(isPlatformPopup())94 }95 @Test96 fun preferenceMatchers() {97 onData(withSummaryText("3 days"))98 onData(withTitle(R.string.pref_title_send_notifications))99 onData(withKey("example_switch"))100 onView(isEnabled())101 }102 @Test103 fun layoutMatchers() {104 onView(hasEllipsizedText())105 onView(hasMultilineText())106 }107}...
BookmarkRobot.kt
Source:BookmarkRobot.kt
...27 fun clickListItemActionMenu(position: Int) {28 onView(withId(R.id.recyclerview)).perform(RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(position, clickChildViewWithId(R.id.history_item_btn_more)))29 }30 fun checkItemMenuEditIsDisplayed() {31 onView(withText(R.string.edit_bookmark)).inRoot(RootMatchers.isPlatformPopup()).check(matches(isDisplayed()))32 }33 fun clickItemMenuEdit() {34 onView(withText(R.string.edit_bookmark)).inRoot(RootMatchers.isPlatformPopup()).perform(click())35 }36 fun checkBookmarkUpdatedToastIsDisplayed(activity: MainActivity) = AndroidTestUtils.toastContainsText(activity, R.string.bookmark_edit_success)37}...
HistoryRobot.kt
Source:HistoryRobot.kt
...17 RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(position, clickChildViewWithId(R.id.history_item_btn_more)))18 }19 fun checkItemMenuDeleteIsDisplayed() {20 onView(withText(R.string.browsing_history_menu_delete))21 .inRoot(RootMatchers.isPlatformPopup())22 .check(matches(isDisplayed()))23 }24 fun clickItemMenuDelete() {25 onView(withText(R.string.browsing_history_menu_delete))26 .inRoot(RootMatchers.isPlatformPopup())27 .perform(click())28 }29 fun clickClearBrowsingHistory() {30 onView(withId(R.id.browsing_history_btn_clear)).perform(click())31 }32 fun checkConfirmClearDialogIsDisplayed() {33 onView(withText(R.string.browsing_history_dialog_confirm_clear_message)).check(matches(isDisplayed()))34 }35}...
isPlatformPopup
Using AI Code Generation
1onView(withId(R.id.button)).perform(click());2onView(withText(“OK”)).inRoot(isPlatformPopup()).perform(click());3onView(withId(R.id.button)).perform(click());4onView(withText(“OK”)).inRoot(not(isPlatformPopup())).perform(click());5onView(withId(R.id.button)).perform(click());6onView(withText(“OK”)).inRoot(isDialog()).perform(click());7onView(withId(R.id.button)).perform(click());8onView(withText(“OK”)).inRoot(not(isDialog())).perform(click());9onView(withId(R.id.button)).check(matches(isFocusable()));10onView(withId(R.id.button)).check(matches(not(isFocusable())));11onView(withId(R.id.button)).check(matches(isFocused()));12onView(withId(R.id.button)).check(matches(not(isFocused())));13onView(withId(R.id.button)).check(matches(isClickable()));14onView(withId(R.id.button)).check(matches(not(isClickable())));15onView(withId(R.id.button)).check(matches(isDisplayed()));
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!!