How to use withClassName method of android.support.test.espresso.matcher.ViewMatchers class

Best Appium-espresso-driver code snippet using android.support.test.espresso.matcher.ViewMatchers.withClassName

ActivityAddEditEmployeeTest.kt

Source:ActivityAddEditEmployeeTest.kt Github

copy

Full Screen

...62 childAtPosition(63 Matchers.allOf(64 ViewMatchers.withId(R.id.const_layout_emp_list),65 childAtPosition(66 ViewMatchers.withClassName(Matchers.`is`("android.widget.ScrollView")),67 068 )69 ),70 271 )72 )73 )74 employeeIdEditText.perform(scrollTo(), replaceText("480819"), closeSoftKeyboard())75 val employeeNameEditText = Espresso.onView(76 Matchers.allOf(77 ViewMatchers.withId(R.id.etv_add_emp_name),78 childAtPosition(79 Matchers.allOf(80 ViewMatchers.withId(R.id.const_layout_emp_list),81 childAtPosition(82 ViewMatchers.withClassName(Matchers.`is`("android.widget.ScrollView")),83 084 )85 ),86 387 )88 )89 )90 employeeNameEditText.perform(scrollTo(), replaceText("pooja patil "), closeSoftKeyboard())91 val bandEditText = Espresso.onView(92 Matchers.allOf(93 ViewMatchers.withId(R.id.etv_add_emp_band),94 childAtPosition(95 Matchers.allOf(96 ViewMatchers.withId(R.id.const_layout_emp_list),97 childAtPosition(98 ViewMatchers.withClassName(Matchers.`is`("android.widget.ScrollView")),99 0100 )101 ),102 4103 )104 )105 )106 bandEditText.perform(scrollTo(), replaceText("u4"), closeSoftKeyboard())107 val designationEditText = Espresso.onView(108 Matchers.allOf(109 ViewMatchers.withId(R.id.etv_add_emp_designation),110 childAtPosition(111 Matchers.allOf(112 ViewMatchers.withId(R.id.const_layout_emp_list),113 childAtPosition(114 ViewMatchers.withClassName(Matchers.`is`("android.widget.ScrollView")),115 0116 )117 ),118 5119 )120 )121 )122 designationEditText.perform(scrollTo(), replaceText("project manager "), closeSoftKeyboard())123 val competencyRadioButton = Espresso.onView(124 Matchers.allOf(125 ViewMatchers.withId(R.id.radio_tester), ViewMatchers.withText("Tester"),126 childAtPosition(127 Matchers.allOf(128 ViewMatchers.withId(R.id.rg_emp_competency),129 childAtPosition(130 ViewMatchers.withId(R.id.const_layout_emp_list),131 7132 )133 ),134 3135 )136 )137 )138 competencyRadioButton.perform(scrollTo(), click())139 val addProjectImageButton = Espresso.onView(140 Matchers.allOf(141 ViewMatchers.withId(R.id.img_btn_add_project),142 childAtPosition(143 Matchers.allOf(144 ViewMatchers.withId(R.id.const_layout_emp_list),145 childAtPosition(146 ViewMatchers.withClassName(Matchers.`is`("android.widget.ScrollView")),147 0148 )149 ),150 10151 )152 )153 )154 addProjectImageButton.perform(scrollTo(), click())155 val projectEditText = Espresso.onView(156 Matchers.allOf(157 ViewMatchers.withId(R.id.editTextProjectNam), ViewMatchers.withText("Enter Project"),158 childAtPosition(159 childAtPosition(160 IsInstanceOf.instanceOf(LinearLayout::class.java),161 0162 ),163 0164 ),165 ViewMatchers.isDisplayed()166 )167 )168 projectEditText.check(ViewAssertions.matches(ViewMatchers.withText("Enter Project")))169 val projectNameTextView = Espresso.onView(170 Matchers.allOf(171 ViewMatchers.withId(R.id.textViewProjectInfo), ViewMatchers.withText("ATT"),172 childAtPosition(173 childAtPosition(174 ViewMatchers.withId(R.id.projectInfoList),175 0176 ),177 0178 ),179 ViewMatchers.isDisplayed()180 )181 )182 projectNameTextView.check(ViewAssertions.matches(ViewMatchers.withText("ATT")))183 val projectAddButton = Espresso.onView(184 Matchers.allOf(185 ViewMatchers.withId(R.id.buttonProjectAdd),186 childAtPosition(187 childAtPosition(188 IsInstanceOf.instanceOf(LinearLayout::class.java),189 0190 ),191 1192 ),193 ViewMatchers.isDisplayed()194 )195 )196 projectAddButton.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))197 val idEditText = Espresso.onView(198 Matchers.allOf(199 ViewMatchers.withId(R.id.etv_add_emp_id), ViewMatchers.withText("ID"),200 childAtPosition(201 Matchers.allOf(202 ViewMatchers.withId(R.id.const_layout_emp_list),203 childAtPosition(204 IsInstanceOf.instanceOf(ScrollView::class.java),205 0206 )207 ),208 0209 ),210 ViewMatchers.isDisplayed()211 )212 )213 idEditText.check(matches(withText("ID")))214 val empIdEditText = Espresso.onView(215 Matchers.allOf(216 ViewMatchers.withId(R.id.etv_add_emp_id),217 ViewMatchers.withText("Please enter your employee id"),218 childAtPosition(219 Matchers.allOf(220 ViewMatchers.withId(R.id.const_layout_emp_list),221 childAtPosition(222 IsInstanceOf.instanceOf(ScrollView::class.java),223 0224 )225 ),226 1227 ),228 ViewMatchers.isDisplayed()229 )230 )231 empIdEditText.check(matches(withText("Please enter your employee id")))232 val empNameEditText = Espresso.onView(233 Matchers.allOf(234 ViewMatchers.withId(R.id.etv_add_emp_name),235 ViewMatchers.withText("Please enter your full name"),236 childAtPosition(237 Matchers.allOf(238 ViewMatchers.withId(R.id.const_layout_emp_list),239 childAtPosition(240 IsInstanceOf.instanceOf(ScrollView::class.java),241 0242 )243 ),244 2245 ),246 ViewMatchers.isDisplayed()247 )248 )249 empNameEditText.check(matches(withText("Please enter your full name")))250 val bandEditTextDisplay = Espresso.onView(251 Matchers.allOf(252 ViewMatchers.withId(R.id.etv_add_emp_band),253 ViewMatchers.withText("Please enter your band"),254 childAtPosition(255 Matchers.allOf(256 ViewMatchers.withId(R.id.const_layout_emp_list),257 childAtPosition(258 IsInstanceOf.instanceOf(ScrollView::class.java),259 0260 )261 ),262 3263 ),264 ViewMatchers.isDisplayed()265 )266 )267 bandEditTextDisplay.check(matches(withText("Please enter your band")))268 val designationEditTextDisplay = Espresso.onView(269 Matchers.allOf(270 ViewMatchers.withId(R.id.etv_add_emp_designation),271 ViewMatchers.withText("Please enter your designation"),272 childAtPosition(273 Matchers.allOf(274 ViewMatchers.withId(R.id.const_layout_emp_list),275 childAtPosition(276 IsInstanceOf.instanceOf(ScrollView::class.java),277 0278 )279 ),280 4281 ),282 ViewMatchers.isDisplayed()283 )284 )285 designationEditTextDisplay.check(matches(withText("Please enter your designation")))286 val competencyRadioButtonDisplay = Espresso.onView(287 Matchers.allOf(288 ViewMatchers.withId(R.id.radio_android),289 childAtPosition(290 Matchers.allOf(291 ViewMatchers.withId(R.id.rg_emp_competency),292 childAtPosition(293 ViewMatchers.withId(R.id.const_layout_emp_list),294 6295 )296 ),297 0298 ),299 ViewMatchers.isDisplayed()300 )301 )302 competencyRadioButtonDisplay.check(matches(isDisplayed()))303 val androidRadioButton = Espresso.onView(304 Matchers.allOf(305 ViewMatchers.withId(R.id.radio_tester),306 childAtPosition(307 Matchers.allOf(308 ViewMatchers.withId(R.id.rg_emp_competency),309 childAtPosition(310 ViewMatchers.withId(R.id.const_layout_emp_list),311 6312 )313 ),314 3315 ),316 ViewMatchers.isDisplayed()317 )318 )319 androidRadioButton.check(matches(isDisplayed()))320 val projectLabelTextView = Espresso.onView(321 Matchers.allOf(322 ViewMatchers.withId(R.id.tv_emp_project_label), ViewMatchers.withText("Project :"),323 childAtPosition(324 Matchers.allOf(325 ViewMatchers.withId(R.id.const_layout_emp_list),326 childAtPosition(327 IsInstanceOf.instanceOf(ScrollView::class.java),328 0329 )330 ),331 7332 ),333 ViewMatchers.isDisplayed()334 )335 )336 projectLabelTextView.check(matches(withText("Project :")))337 val projectAddImageButtonDisplay = Espresso.onView(338 Matchers.allOf(339 ViewMatchers.withId(R.id.img_btn_add_project),340 childAtPosition(341 Matchers.allOf(342 ViewMatchers.withId(R.id.const_layout_emp_list),343 childAtPosition(344 IsInstanceOf.instanceOf(ScrollView::class.java),345 0346 )347 ),348 8349 ),350 ViewMatchers.isDisplayed()351 )352 )353 projectAddImageButtonDisplay.check(matches(isDisplayed()))354 val projectListSpinner = Espresso.onView(355 Matchers.allOf(356 ViewMatchers.withId(R.id.spinner_emp_project),357 childAtPosition(358 Matchers.allOf(359 ViewMatchers.withId(R.id.const_layout_emp_list),360 childAtPosition(361 IsInstanceOf.instanceOf(ScrollView::class.java),362 0363 )364 ),365 9366 ),367 ViewMatchers.isDisplayed()368 )369 )370 projectListSpinner.check(matches(isDisplayed()))371 val activityTitleTextView = Espresso.onView(372 Matchers.allOf(373 ViewMatchers.withText("Add Employee"),374 childAtPosition(375 Matchers.allOf(376 ViewMatchers.withId(R.id.action_bar),377 childAtPosition(378 ViewMatchers.withId(R.id.action_bar_container),379 0380 )381 ),382 0383 ),384 ViewMatchers.isDisplayed()385 )386 )387 activityTitleTextView.check(matches(withText("Add Employee")))388 val employeeIdEditTextTextReplace = Espresso.onView(389 Matchers.allOf(390 ViewMatchers.withId(R.id.etv_add_emp_id),391 childAtPosition(392 Matchers.allOf(393 ViewMatchers.withId(R.id.const_layout_emp_list),394 childAtPosition(395 ViewMatchers.withClassName(Matchers.`is`("android.widget.ScrollView")),396 0397 )398 ),399 2400 )401 )402 )403 employeeIdEditTextTextReplace.perform(scrollTo(), replaceText("Poonam Rao "), closeSoftKeyboard())404 val employeeIdEditTextContainerItemClick = Espresso.onView(405 Matchers.allOf(406 ViewMatchers.withId(R.id.etv_add_emp_id),407 childAtPosition(408 Matchers.allOf(409 ViewMatchers.withId(R.id.const_layout_emp_list),410 childAtPosition(411 ViewMatchers.withClassName(Matchers.`is`("android.widget.ScrollView")),412 0413 )414 ),415 2416 )417 )418 )419 employeeIdEditTextContainerItemClick.perform(scrollTo(), click())420 val projectListSpiinerOnClick = Espresso.onView(421 Matchers.allOf(422 ViewMatchers.withId(R.id.spinner_emp_project),423 childAtPosition(424 Matchers.allOf(425 ViewMatchers.withId(R.id.const_layout_emp_list),426 childAtPosition(427 ViewMatchers.withClassName(Matchers.`is`("android.widget.ScrollView")),428 0429 )430 ),431 9432 )433 )434 )435 projectListSpiinerOnClick.perform(scrollTo(), click())436 // Added a sleep statement to match the app's execution delay.437 // The recommended way to handle such scenarios is to use Espresso idling resources:438 // https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html439 Thread.sleep(700)440 val submitButtonClick = Espresso.onView(441 Matchers.allOf(442 ViewMatchers.withId(R.id.btn_add_emp_submit), ViewMatchers.withText("Submit"),443 childAtPosition(444 Matchers.allOf(445 ViewMatchers.withId(R.id.const_layout_emp_list),446 childAtPosition(447 ViewMatchers.withClassName(Matchers.`is`("android.widget.ScrollView")),448 0449 )450 ),451 12452 )453 )454 )455 submitButtonClick.perform(scrollTo(), click())456 }457 private fun childAtPosition(458 parentMatcher: Matcher<View>, position: Int459 ): Matcher<View> {460 return object : TypeSafeMatcher<View>() {461 override fun describeTo(description: Description) {...

Full Screen

Full Screen

MainActivityTest2.kt

Source:MainActivityTest2.kt Github

copy

Full Screen

...78 Matchers.allOf(ViewMatchers.withContentDescription("Open navigation drawer"),79 childAtPosition(80 Matchers.allOf(ViewMatchers.withId(R.id.toolbar),81 childAtPosition(82 ViewMatchers.withClassName(Matchers.`is`("android.support.design.widget.AppBarLayout")),83 0)),84 1),85 ViewMatchers.isDisplayed()))86 appCompatImageButton.perform(ViewActions.click())87 val navigationMenuItemView = Espresso.onView(88 Matchers.allOf(childAtPosition(89 Matchers.allOf(ViewMatchers.withId(R.id.design_navigation_view),90 childAtPosition(91 ViewMatchers.withId(R.id.nav_view),92 0)),93 1),94 ViewMatchers.isDisplayed()))95 navigationMenuItemView.perform(ViewActions.click())96 val appCompatImageButton2 = Espresso.onView(97 Matchers.allOf(ViewMatchers.withContentDescription("Open navigation drawer"),98 childAtPosition(99 Matchers.allOf(ViewMatchers.withId(R.id.toolbar),100 childAtPosition(101 ViewMatchers.withClassName(Matchers.`is`("android.support.design.widget.AppBarLayout")),102 0)),103 1),104 ViewMatchers.isDisplayed()))105 appCompatImageButton2.perform(ViewActions.click())106 val navigationMenuItemView2 = Espresso.onView(107 Matchers.allOf(childAtPosition(108 Matchers.allOf(ViewMatchers.withId(R.id.design_navigation_view),109 childAtPosition(110 ViewMatchers.withId(R.id.nav_view),111 0)),112 3),113 ViewMatchers.isDisplayed()))114 navigationMenuItemView2.perform(ViewActions.click())115 val appCompatImageButton3 = Espresso.onView(116 Matchers.allOf(ViewMatchers.withContentDescription("Open navigation drawer"),117 childAtPosition(118 Matchers.allOf(ViewMatchers.withId(R.id.toolbar),119 childAtPosition(120 ViewMatchers.withClassName(Matchers.`is`("android.support.design.widget.AppBarLayout")),121 0)),122 1),123 ViewMatchers.isDisplayed()))124 appCompatImageButton3.perform(ViewActions.click())125 val navigationMenuItemView3 = Espresso.onView(126 Matchers.allOf(childAtPosition(127 Matchers.allOf(ViewMatchers.withId(R.id.design_navigation_view),128 childAtPosition(129 ViewMatchers.withId(R.id.nav_view),130 0)),131 2),132 ViewMatchers.isDisplayed()))133 navigationMenuItemView3.perform(ViewActions.click())134 val appCompatImageButton1 = Espresso.onView(135 Matchers.allOf(ViewMatchers.withContentDescription("Open navigation drawer"),136 childAtPosition(137 Matchers.allOf(ViewMatchers.withId(R.id.toolbar),138 childAtPosition(139 ViewMatchers.withClassName(Matchers.`is`("android.support.design.widget.AppBarLayout")),140 0)),141 1),142 ViewMatchers.isDisplayed()))143 appCompatImageButton1.perform(ViewActions.click())144 Espresso.pressBack()145 }146 companion object {147 private fun childAtPosition(148 parentMatcher: Matcher<View>, position: Int): Matcher<View> {149 return object : TypeSafeMatcher<View>() {150 override fun describeTo(description: Description) {151 description.appendText("Child at position $position in parent ")152 parentMatcher.describeTo(description)153 }...

Full Screen

Full Screen

MainActivityInstrumentationTest.kt

Source:MainActivityInstrumentationTest.kt Github

copy

Full Screen

...27 Espresso.onView(withId(R.id.menu_getData)).check(ViewAssertions.matches(not(isDisplayed())))28 }29 @Test30 fun fabMenu_open_and_close(){31 Espresso.onView(allOf(withParent(withId(R.id.menu)), withClassName(endsWith("ImageView")), isDisplayed()))32 .perform(click())33 Espresso.onView(withId(R.id.menu_fb)).check(ViewAssertions.matches(isDisplayed()))34 Espresso.onView(withId(R.id.menu_getData)).check(ViewAssertions.matches(isDisplayed()))35 Espresso.onView(withId(R.id.menu)).check(ViewAssertions.matches(isDisplayed()))36 Espresso.onView(allOf(withParent(withId(R.id.menu)), withClassName(endsWith("ImageView")), isDisplayed()))37 .perform(click())38 Espresso.onView(withId(R.id.menu_fb)).check(ViewAssertions.matches(not(isDisplayed())))39 Espresso.onView(withId(R.id.menu_getData)).check(ViewAssertions.matches(not(isDisplayed())))40 Espresso.onView(withId(R.id.menu)).check(ViewAssertions.matches(isDisplayed()))41 }42 @Test43 fun logo_fragment_should_be_visible_in_start(){44 Espresso.onView(withId(R.id.main_page_fragment)).check(ViewAssertions.matches(isDisplayed()))45 Espresso.onView(withId(R.id.logo_image)).check(ViewAssertions.matches(isDisplayed()))46 Espresso.onView(withId(R.id.logo_name)).check(ViewAssertions.matches(isDisplayed()))47 }48 @Test49 fun get_data_from_api_and_display_it(){50 Espresso.onView(allOf(withParent(withId(R.id.menu)), withClassName(endsWith("ImageView")), isDisplayed()))51 .perform(click())52 Espresso.onView(withId(R.id.menu_getData)).perform(click())53 Espresso.onView(withId(R.id.images)).check(ViewAssertions54 .matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))55 .check(ViewAssertions.matches(withText(containsString("Images:"))))56 Espresso.onView(withId(R.id.recipe_fragment)).check(ViewAssertions.matches(isDisplayed()))57 .check(ViewAssertions.matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))58 Espresso.onView(withId(R.id.name)).check(ViewAssertions.matches(isDisplayed()))59 .check(ViewAssertions.matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))60 Espresso.onView(withId(R.id.Ingredients)).check(ViewAssertions.matches(isDisplayed()))61 .check(ViewAssertions.matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))62 .check(ViewAssertions.matches(withText(containsString("Ingredients:"))))63 Espresso.onView(withId(R.id.Preparing)).check(ViewAssertions.matches(isDisplayed()))64 .check(ViewAssertions.matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))65 .check(ViewAssertions.matches(withText(containsString("Preparing:"))))66 Espresso.onView(withId(R.id.description))67 .check(ViewAssertions.matches(isDisplayed()))68 .check(ViewAssertions.matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))69 Espresso.onView(withId(R.id.ingredients))70 .check(ViewAssertions.matches(isDisplayed()))71 .check(ViewAssertions.matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))72 }73 @Test74 fun show_dialog_after_click_on_image_to_save(){75 Espresso.onView(allOf(withParent(withId(R.id.menu)), withClassName(endsWith("ImageView")), isDisplayed()))76 .perform(click())77 Espresso.onView(withId(R.id.menu_getData)).perform(click())78 Espresso.onView(withId(R.id.flexboxImages))79 .perform(scrollTo())80 Espresso.onView(81 withTagValue(`is`("Image0" as Object))82 ).perform(click())83 Espresso.onView(withText("Save image")).check(ViewAssertions.matches(isDisplayed()))84 }85 @Test86 fun show_toast_after_save_file_correct(){87 Espresso.onView(allOf(withParent(withId(R.id.menu)), withClassName(endsWith("ImageView")), isDisplayed()))88 .perform(click())89 Espresso.onView(withId(R.id.menu_getData)).perform(click())90 Espresso.onView(withId(R.id.flexboxImages))91 .perform(scrollTo())92 Espresso.onView(93 withTagValue(`is`("Image0" as Object))94 ).perform(click())95 Espresso.onView(withId(android.R.id.button1)).perform(click())96 Espresso.onView(withText("Image saved!")).inRoot(withDecorView(not(`is`(activityRule.activity.window.decorView)))).97 check(ViewAssertions.matches(isDisplayed()))98 }99 @Test100 fun snackbar_should_be_displayed_after_login(){101 activityRule.activity.setIsLog(true)102 activityRule.activity.setUser("test test")103 Espresso.onView(allOf(withParent(withId(R.id.menu)), withClassName(endsWith("ImageView")), isDisplayed()))104 .perform(click())105 Espresso.onView(withId(R.id.menu_getData)).perform(click())106 Espresso.onView(withText("Logged as test test")).check(ViewAssertions.matches(isDisplayed()))107 }108 @Test109 fun show_dialog_when_user_wants_logout(){110 activityRule.activity.setIsLog(true)111 activityRule.activity.setUser("test test")112 Espresso.onView(allOf(withParent(withId(R.id.menu)), withClassName(endsWith("ImageView")), isDisplayed()))113 .perform(click())114 Espresso.onView(withId(R.id.menu_fb)).perform(click())115 Espresso.onView(withText("Logged in as: test test")).inRoot(withDecorView(not(`is`(activityRule.activity.window.decorView)))).116 check(ViewAssertions.matches(isDisplayed()))117 }118 @Test119 fun show_toast_after_logout(){120 activityRule.activity.setIsLog(true)121 activityRule.activity.setUser("test test")122 Espresso.onView(allOf(withParent(withId(R.id.menu)), withClassName(endsWith("ImageView")), isDisplayed()))123 .perform(click())124 Espresso.onView(withId(R.id.menu_fb)).perform(click())125 Espresso.onView(withId(android.R.id.button1)).perform(click())126 Espresso.onView(withText("You have been logged out.")).inRoot(withDecorView(not(`is`(activityRule.activity.window.decorView)))).127 check(ViewAssertions.matches(isDisplayed()))128 }129}...

Full Screen

Full Screen

PersmisionsTest.kt

Source:PersmisionsTest.kt Github

copy

Full Screen

...5import androidx.test.espresso.Espresso.pressBack6import androidx.test.espresso.action.ViewActions.click7import androidx.test.espresso.action.ViewActions.longClick8import androidx.test.espresso.action.ViewActions.scrollTo9import androidx.test.espresso.matcher.ViewMatchers.withClassName10import androidx.test.espresso.matcher.ViewMatchers.withContentDescription11import androidx.test.espresso.matcher.ViewMatchers.withId12import androidx.test.espresso.matcher.ViewMatchers.withText13import androidx.test.filters.LargeTest14import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner15import androidx.test.rule.ActivityTestRule16import androidx.test.rule.GrantPermissionRule17import com.github.jameshnsears.brexitsoundboard.ActivityBrexitSoundboard18import com.github.jameshnsears.brexitsoundboard.R19import org.hamcrest.Description20import org.hamcrest.Matcher21import org.hamcrest.Matchers.`is`22import org.hamcrest.Matchers.allOf23import org.hamcrest.TypeSafeMatcher24import org.junit.Rule25import org.junit.Test26import org.junit.runner.RunWith27@LargeTest28@RunWith(AndroidJUnit4ClassRunner::class)29class PersmisionsTest {30 @Rule31 @JvmField32 var mActivityTestRule = ActivityTestRule(ActivityBrexitSoundboard::class.java)33 @Rule34 @JvmField35 var mGrantPermissionRule =36 GrantPermissionRule.grant(37 "android.permission.READ_EXTERNAL_STORAGE",38 "android.permission.WRITE_EXTERNAL_STORAGE"39 )40 @Test41 fun persmisionsTest() {42 // Added a sleep statement to match the app's execution delay.43 // The recommended way to handle such scenarios is to use Espresso idling resources:44 // https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html45 Thread.sleep(1000)46 val switch_ = onView(47 allOf(48 withId(R.id.installSound),49 withText("Enable Media Library integration?"),50 childAtPosition(51 allOf(52 withId(R.id.linearLayout),53 childAtPosition(54 withId(R.id.scrollView),55 056 )57 ),58 059 )60 )61 )62 switch_.perform(scrollTo(), click())63 // Added a sleep statement to match the app's execution delay.64 // The recommended way to handle such scenarios is to use Espresso idling resources:65 // https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html66 Thread.sleep(1000)67 // Added a sleep statement to match the app's execution delay.68 // The recommended way to handle such scenarios is to use Espresso idling resources:69 // https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html70 Thread.sleep(1000)71 val appCompatImageButton = onView(72 allOf(73 withId(R.id.imageButtonBoris01),74 withContentDescription("Alexander Boris de Pfeffel Johnson"),75 childAtPosition(76 childAtPosition(77 withId(R.id.linearLayout),78 179 ),80 181 )82 )83 )84 appCompatImageButton.perform(scrollTo(), click())85 // Added a sleep statement to match the app's execution delay.86 // The recommended way to handle such scenarios is to use Espresso idling resources:87 // https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html88 Thread.sleep(1000)89 val appCompatButton = onView(90 allOf(91 withId(R.id.buttonBoris350MillionPoundsAWeek),92 withText("350 Million Pounds A Week"),93 childAtPosition(94 childAtPosition(95 withClassName(`is`("android.widget.ScrollView")),96 097 ),98 099 )100 )101 )102 appCompatButton.perform(scrollTo(), longClick())103// not working in CI!104// Thread.sleep(1000)105//106// val textView = onView(107// allOf(108// withId(android.R.id.title),109// withText("Alarm"),110// childAtPosition(111// childAtPosition(112// withClassName(`is`("com.android.internal.view.menu.ListMenuItemView")),113// 0114// ),115// 0116// ),117// isDisplayed()118// )119// )120// textView.perform(click())121//122// // Added a sleep statement to match the app's execution delay.123// // The recommended way to handle such scenarios is to use Espresso idling resources:124// // https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html125// Thread.sleep(1000)126 pressBack()...

Full Screen

Full Screen

MainActivityTest.kt

Source:MainActivityTest.kt Github

copy

Full Screen

...17import android.support.test.espresso.action.ViewActions.click18import android.support.test.espresso.assertion.ViewAssertions.matches19import android.support.test.espresso.contrib.RecyclerViewActions20import android.support.test.espresso.matcher.ViewMatchers.isDisplayed21import android.support.test.espresso.matcher.ViewMatchers.withClassName22import android.support.test.espresso.matcher.ViewMatchers.withContentDescription23import android.support.test.espresso.matcher.ViewMatchers.withId24import android.support.test.espresso.matcher.ViewMatchers.withText25import android.support.v7.widget.RecyclerView26import org.hamcrest.Matchers.allOf27import org.hamcrest.Matchers.`is`28@LargeTest29@RunWith(AndroidJUnit4::class)30class MainActivityTest {31 @Rule32 @JvmField33 var mActivityTestRule = ActivityTestRule(MainActivity::class.java)34 @Test35 fun mainActivityTest() {36 val bottomNavigationItemView = onView(37 allOf(withId(R.id.menu_next_event),38 childAtPosition(39 childAtPosition(40 withId(R.id.navigation),41 0),42 1),43 isDisplayed()))44 bottomNavigationItemView.perform(click())45 Thread.sleep(3000)46 val cardView = onView(47 allOf(childAtPosition(48 childAtPosition(49 withClassName(`is`("org.jetbrains.anko._RelativeLayout")),50 0),51 1),52 isDisplayed()))53 cardView.perform(click())54 Thread.sleep(3000)55 val textView = onView(56 allOf(withId(R.id.home_team_name), withText("West Ham"),57 childAtPosition(58 childAtPosition(59 IsInstanceOf.instanceOf(android.widget.LinearLayout::class.java),60 0),61 1),62 isDisplayed()))63 textView.check(matches(withText("West Ham")))...

Full Screen

Full Screen

MainActivityTest3.kt

Source:MainActivityTest3.kt Github

copy

Full Screen

...6import androidx.test.espresso.action.ViewActions.click7import androidx.test.espresso.action.ViewActions.pressBack8import androidx.test.espresso.contrib.RecyclerViewActions.actionOnItemAtPosition9import androidx.test.espresso.matcher.ViewMatchers.isDisplayed10import androidx.test.espresso.matcher.ViewMatchers.withClassName11import androidx.test.espresso.matcher.ViewMatchers.withContentDescription12import androidx.test.espresso.matcher.ViewMatchers.withId13import androidx.test.ext.junit.runners.AndroidJUnit414import androidx.test.filters.LargeTest15import androidx.test.platform.app.InstrumentationRegistry16import androidx.test.rule.ActivityTestRule17import org.hamcrest.Description18import org.hamcrest.Matcher19import org.hamcrest.Matchers.`is`20import org.hamcrest.Matchers.allOf21import org.hamcrest.TypeSafeMatcher22import org.junit.Rule23import org.junit.Test24import org.junit.runner.RunWith25import tech.thdev.flickr.R26@LargeTest27@RunWith(AndroidJUnit4::class)28class MainActivityTest3 {29 @Rule30 @JvmField31 var mActivityTestRule = ActivityTestRule(MainActivity::class.java)32 private val instrumentation = InstrumentationRegistry.getInstrumentation()33 @Test34 fun mainActivityTest3() {35 instrumentation.waitForIdleSync()36 val recyclerView = onView(37 allOf(38 withId(R.id.recycler_view),39 childAtPosition(40 withClassName(`is`("android.support.constraint.ConstraintLayout")),41 042 )43 )44 )45 recyclerView.perform(actionOnItemAtPosition<RecyclerView.ViewHolder>(36, click()))46 val appCompatImageView = onView(47 allOf(48 withId(R.id.iv_thumbnail_large),49 childAtPosition(50 childAtPosition(51 withId(android.R.id.content),52 053 ),54 055 ),56 isDisplayed()57 )58 )59 appCompatImageView.perform(click())60 val appCompatImageButton = onView(61 allOf(62 withContentDescription("Navigate up"),63 childAtPosition(64 allOf(65 withId(R.id.toolbar),66 childAtPosition(67 withClassName(`is`("android.support.design.widget.CoordinatorLayout")),68 269 )70 ),71 172 ),73 isDisplayed()74 )75 )76 appCompatImageButton.perform(click())77 val recyclerView2 = onView(78 allOf(79 withId(R.id.recycler_view),80 childAtPosition(81 withClassName(`is`("android.support.constraint.ConstraintLayout")),82 083 )84 )85 )86 recyclerView2.perform(actionOnItemAtPosition<RecyclerView.ViewHolder>(1, click()))87 val appCompatImageView2 = onView(88 allOf(89 withId(R.id.iv_thumbnail_large),90 childAtPosition(91 childAtPosition(92 withId(android.R.id.content),93 094 ),95 0...

Full Screen

Full Screen

exampleTest.kt

Source:exampleTest.kt Github

copy

Full Screen

...21import org.hamcrest.core.AllOf.allOf22import org.junit.Assert.*23import org.junit.Test24import org.junit.runner.RunWith25import androidx.test.espresso.matcher.ViewMatchers.withClassName26import com.example.android.riprovatesting.MainActivity3Test27import org.hamcrest.core.Is.`is`28/*29 E' STATO AGGIUNTO IL DATABINDING E QUINDI CONVIENE TOGLIERLO PER SIMULARE CHE VENGA MESSO30 SE COMPARE IL MESSAGGIO DI ERRORE 'META INF-ALL'31 https://www.codegrepper.com/code-examples/java/More+than+one+file+was+found+with+OS+independent+path+%27META-INF%2FAL2.0%27.+when+running+android+test32 SE COMPARE UN MESSAGGIO DI ERRORE NO STATIC METHOD33 https://stackoverflow.com/questions/67358179/android-espresso-test-error-no-static-method-loadsingleserviceornull34 TOAST IN A FRAGMENT35 http://5.9.10.113/66823421/how-to-test-a-toast-in-a-fragment36 PER VEDERE ESEMPI DI UTILIZZO DI "WITHCLASSNAME"37 https://www.tabnine.com/code/java/methods/android.support.test.espresso.matcher.ViewMatchers/withClassName38 CHE SONO MOLTO INTERESSANTI!!!!39 ESEMPI DI TABNINE!!!!40 ISASSIGNABLEFROM:41 https://www.tabnine.com/code/java/methods/android.support.test.espresso.matcher.ViewMatchers/isAssignableFrom42 SI POSSONO COMPIERE TEST COMBINATI (anche con try catch) che fondono test singoli43 -TEST SUITES:44 https://stackoverflow.com/questions/46878733/android-espresso-how-to-create-test-suite-which-may-launch-separate-test-classe45 https://medium.com/mesmerhq/accelerate-your-android-espresso-testing-by-grouping-relevant-tests-f492d4ff880946 */47@MediumTest48@RunWith(AndroidJUnit4::class)49class exampleTest{50 //verifica il DataBinding su fragment o abilitazione51 //verifica la creazione del fragment52 @Test53 fun fragmentInUi() {54 launchFragmentInContainer<example>()55 }56 //testare la presenza di un frammento dentro una attività - SPOSTATO AD UN FILE A PARTE - MODO PIù CORRETTO57 //il fragment è testato isolatamente58 //verifica i componenti UI in fragment59 @Test60 fun TextInFragment(){61 val scenario = launchFragmentInContainer<example>()62 onView(withId(R.id.testo_frammento)).check(matches(isDisplayed()))63 onView(withText("Hello Fragment!!")).check(matches(isDisplayed()))64 onView(withId(R.id.testo_frammento)).check(matches(withText("Hello Fragment!!")))65 }66 //con utilizzo di isAssignablefrom e matcher multipli67 @Test68 fun ElementoTextviewDiscendenteDirettoDiFrameLayout_VerificaTesto(){69 val scenario = launchFragmentInContainer<example>()70 onView(allOf(withId(R.id.testo_frammento), withText("Hello Fragment!!"))).check(matches(isDisplayed()))71 //verifica che la TextView con un certo ID ha come contenuto un certo testo72 onView(allOf(isAssignableFrom(TextView::class.java), withId(R.id.testo_frammento))).check(matches(withText("Hello Fragment!!")))73 onView(allOf(isAssignableFrom(TextView::class.java), withId(R.id.testo_frammento), isDescendantOfA(withClassName(`is`("android.widget.FrameLayout"))))).check(matches(withText("Hello Fragment!!")))74 //riprova: il seguente fallisce perchè la classe non è corretta75 //onView(allOf(isAssignableFrom(Button::class.java), withId(R.id.testo_frammento), isDescendantOfA(withClassName(`is`("android.widget.FrameLayout"))))).check(matches(withText("Hello Fragment!!")))76 //oppure il genitore non è del tipo giusto77 //onView(allOf(isAssignableFrom(TextView::class.java), withId(R.id.testo_frammento), isDescendantOfA(withClassName(`is`("android.widget.ConstraintLayout"))))).check(matches(withText("Hello Fragment!!")))78 }79 //verifica animazioni fragment80}

Full Screen

Full Screen

ViewMatchersTest.kt

Source:ViewMatchersTest.kt Github

copy

Full Screen

...29import 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())...

Full Screen

Full Screen

withClassName

Using AI Code Generation

copy

Full Screen

1android.support.test.espresso.matcher.ViewMatchers.withClassName(Matchers.equalTo("android.widget.Button"))2android.support.test.espresso.matcher.ViewMatchers.withId(R.id.button)3android.support.test.espresso.matcher.ViewMatchers.withText("Click Me")4android.support.test.espresso.matcher.ViewMatchers.withContentDescription("Click Me")5android.support.test.espresso.matcher.ViewMatchers.withTagValue(Matchers.is("Click Me"))6android.support.test.espresso.matcher.ViewMatchers.withHint("Click Me")7android.support.test.espresso.matcher.ViewMatchers.withParent(android.support.test.espresso.matcher.ViewMatchers.withId(R.id.button))8android.support.test.espresso.matcher.ViewMatchers.withChild(android.support.test.espresso.matcher.ViewMatchers.withId(R.id.button))9android.support.test.espresso.matcher.ViewMatchers.withText(Matchers.containsString("Click Me"))10android.support.test.espresso.matcher.ViewMatchers.withText(Matchers.startsWith("Click Me"))11android.support.test.espresso.matcher.ViewMatchers.withText(Matchers.endsWith("Click Me"))12android.support.test.espresso.matcher.ViewMatchers.withText(Matchers.anyOf(Matchers.equalTo("Click Me"), Matchers.equalTo("Click Me")))13android.support.test.espresso.matcher.ViewMatchers.withText(Matchers.allOf(Matchers.containsString("Click Me"), Matchers.startsWith("Click Me")))14android.support.test.espresso.matcher.ViewMatchers.withText(Matchers.not(Matchers.equalTo("Click Me")))

Full Screen

Full Screen

withClassName

Using AI Code Generation

copy

Full Screen

1onView ( withClassName ( Matchers . equalTo ( "android.widget.TextView" ))) . check ( matches ( withText ( "Hello World!" )));2onView ( withClassName ( Matchers . startsWith ( "android.widget.TextView" ))) . check ( matches ( withText ( "Hello World!" )));3onView ( withClassName ( Matchers . endsWith ( "TextView" ))) . check ( matches ( withText ( "Hello World!" )));4onView ( withClassName ( Matchers . containsString ( "widget.Text" ))) . check ( matches ( withText ( "Hello World!" )));5onView ( withClassName ( Matchers . containsString ( "widget.Tex" ))) . check ( matches ( withText ( "Hello World!" )));6onView ( withClassName ( Matchers . containsString ( "widget.Te" ))) . check ( matches ( withText ( "Hello World!" )));7onView ( withClassName ( Matchers . containsString ( "widget.T" ))) . check ( matches ( withText ( "Hello World!" )));8onView ( withClassName ( Matchers . containsString ( "widget." ))) . check ( matches ( withText ( "Hello World!" )));9onView ( withClassName ( Matchers . containsString ( "widget" ))) . check ( matches ( withText ( "Hello World!" )));10onView ( withClassName ( Matchers . containsString ( "idget.Text" ))) . check ( matches ( withText ( "Hello World!" )));11onView ( withClassName ( Matchers . containsString ( "idget.Tex" ))) . check ( matches ( withText ( "Hello World!"

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful