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

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

EspressoDsl.kt

Source: EspressoDsl.kt Github

copy

Full Screen

...36/​**37 * ViewInteraction extensions38 */​39fun ViewInteraction.checkHasChildByText(text: String): ViewInteraction =40 check(ViewAssertions.matches(ViewMatchers.withChild(ViewMatchers.withText(text))))41fun ViewInteraction.checkHasChildByText(id: Int): ViewInteraction =42 check(ViewAssertions.matches(ViewMatchers.withChild(ViewMatchers.withText(id))))43fun ViewInteraction.checkHasChildById(id: Int): ViewInteraction =44 check(ViewAssertions.matches(ViewMatchers.withChild(ViewMatchers.withId(id))))45fun ViewInteraction.checkDisplayed(): ViewInteraction =46 check(ViewAssertions.matches(ViewMatchers.isDisplayed()))47fun ViewInteraction.checkNotDisplayed(): ViewInteraction =48 check(ViewAssertions.matches(not(ViewMatchers.isDisplayed())))49fun ViewInteraction.checkDoesNotExist(): ViewInteraction =50 check(ViewAssertions.doesNotExist())51fun ViewInteraction.checkMatches(matcher: Matcher<View>): ViewInteraction =52 check(ViewAssertions.matches(matcher))53fun ViewInteraction.clickTodoCheckBoxWithTitle(text: String): ViewInteraction =54 perform(CustomRecyclerViewActions.ClickTodoCheckBoxWithTitleViewAction.clickTodoCheckBoxWithTitle(text))55fun ViewInteraction.scrollToLastItem(): ViewInteraction =56 perform(CustomRecyclerViewActions.ScrollToLastHolder.scrollToLastHolder())57fun ViewInteraction.pressEspressoBack() = Espresso.pressBack()58/​**...

Full Screen

Full Screen

RemoveSportTest.kt

Source: RemoveSportTest.kt Github

copy

Full Screen

...58 .perform(ViewActions.click())59 Espresso.onView(ViewMatchers.withId(R.id.rv_usersList))60 .check(RecyclerViewItemCountAssertion(1))61 Espresso.onView(Matchers.allOf(ViewMatchers.withId(R.id.rv_usersList), ViewMatchers.isDisplayed()))62 .perform(RecyclerViewActions.actionOnItem<UsersListAdapter.ViewHolder>(ViewMatchers.withChild(ViewMatchers.withText(TestUtils.userName)), ViewActions.click()))63 /​/​sportActivity64 Thread.sleep(TestUtils.timeIntervalMillis)65 Espresso.onView(ViewMatchers.withId(R.id.rv_sportsList))66 .check(RecyclerViewItemCountAssertion(0))67 Thread.sleep(TestUtils.timeIntervalMillis)68 Espresso.onView(ViewMatchers.withId(R.id.fab)).perform(ViewActions.click())69 Thread.sleep(TestUtils.timeIntervalMillis)70 Espresso.onView(ViewMatchers.withId(R.id.tv_input_sport))71 .inRoot(RootMatchers.isDialog())72 .perform(ViewActions.click())73 .perform(ViewActions.typeTextIntoFocusedView(TestUtils.sportName))74 Thread.sleep(TestUtils.timeIntervalMillis)75 Espresso.onView(ViewMatchers.withId(android.R.id.button1))76 .perform(ViewActions.click())...

Full Screen

Full Screen

ViewMatchersTest.kt

Source: ViewMatchersTest.kt Github

copy

Full Screen

...28import 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))...

Full Screen

Full Screen

AddNewSportTest.kt

Source: AddNewSportTest.kt Github

copy

Full Screen

...58 .perform(ViewActions.click())59 Espresso.onView(ViewMatchers.withId(R.id.rv_usersList))60 .check(RecyclerViewItemCountAssertion(1))61 Espresso.onView(Matchers.allOf(ViewMatchers.withId(R.id.rv_usersList), ViewMatchers.isDisplayed()))62 .perform(RecyclerViewActions.actionOnItem<UsersListAdapter.ViewHolder>(ViewMatchers.withChild(ViewMatchers.withText(TestUtils.userName)), ViewActions.click()))63 /​/​sportActivity64 Thread.sleep(TestUtils.timeIntervalMillis)65 Espresso.onView(ViewMatchers.withId(R.id.rv_sportsList))66 .check(RecyclerViewItemCountAssertion(0))67 Thread.sleep(TestUtils.timeIntervalMillis)68 Espresso.onView(ViewMatchers.withId(R.id.fab)).perform(ViewActions.click())69 Thread.sleep(TestUtils.timeIntervalMillis)70 Espresso.onView(ViewMatchers.withId(R.id.tv_input_sport))71 .inRoot(RootMatchers.isDialog())72 .perform(ViewActions.click())73 .perform(ViewActions.typeTextIntoFocusedView(TestUtils.sportName))74 Thread.sleep(TestUtils.timeIntervalMillis)75 Espresso.onView(ViewMatchers.withId(android.R.id.button1))76 .perform(ViewActions.click())...

Full Screen

Full Screen

SettingsActivityTest.kt

Source: SettingsActivityTest.kt Github

copy

Full Screen

...24import androidx.test.espresso.intent.Intents25import androidx.test.espresso.intent.Intents.intended26import androidx.test.espresso.intent.Intents.intending27import androidx.test.espresso.intent.matcher.IntentMatchers.*28import androidx.test.espresso.matcher.ViewMatchers.withChild29import androidx.test.espresso.matcher.ViewMatchers.withText30import androidx.test.ext.junit.rules.activityScenarioRule31import androidx.test.ext.junit.runners.AndroidJUnit432import androidx.test.filters.LargeTest33import org.junit.Rule34import org.junit.Test35import org.junit.runner.RunWith36@LargeTest37@RunWith(AndroidJUnit4::class)38class SettingsActivityTest {39 @get:Rule40 val activityScenarioRule = activityScenarioRule<SettingsActivity>()41 @Test42 fun supportPreferenceClickStartsEmail() {43 Intents.init()44 intending(hasAction(Intent.ACTION_SENDTO))45 .respondWith(Instrumentation.ActivityResult(Activity.RESULT_OK, Intent()))46 onView(withChild(withText(R.string.pref_support_title)))47 .perform(click())48 intended(hasAction(Intent.ACTION_SENDTO))49 val subject = "Direct Call Widget ${BuildConfig.VERSION_NAME}"50 intended(hasData("mailto:blax.software@gmail.com?subject=$subject"))51 intended(hasExtra(Intent.EXTRA_SUBJECT, subject))52 Intents.release()53 }54 @Test55 fun joinBetaPreferenceClickSendsToProperLink() {56 Intents.init()57 intending(hasAction(Intent.ACTION_VIEW))58 .respondWith(Instrumentation.ActivityResult(Activity.RESULT_OK, Intent()))59 onView(withChild(withText(R.string.pref_become_btester_title)))60 .perform(click())61 intended(hasAction(Intent.ACTION_VIEW))62 intended(hasData("https:/​/​play.google.com/​apps/​testing/​com.blaxsoftware.directcallwidget"))63 Intents.release()64 }65 @Test66 fun contributePreferenceClickOpensGitHub() {67 Intents.init()68 intending(hasAction(Intent.ACTION_VIEW))69 .respondWith(Instrumentation.ActivityResult(Activity.RESULT_OK, Intent()))70 onView(withChild(withText(R.string.pref_contribute_title)))71 .perform(click())72 intended(hasAction(Intent.ACTION_VIEW))73 intended(hasData("https:/​/​github.com/​fpalonso/​direct-call-widget"))74 Intents.release()75 }76}...

Full Screen

Full Screen

AccessibilityTest.kt

Source: AccessibilityTest.kt Github

copy

Full Screen

...51 AccessibilityChecks.enable()52 .setRunChecksFromRootView(true)53 .setSuppressingResultMatcher(matchesViews(anyOf(54 hasSibling(withId(R.id.menu_filter)),55 withChild(withChild(withId(R.id.snackbar_text))))))56 .setThrowExceptionForErrors(false)57 }58 }59}...

Full Screen

Full Screen

TestUtils.kt

Source: TestUtils.kt Github

copy

Full Screen

...28 return false29 }30 val holder = item.findViewHolderForAdapterPosition(position)31 return holder != null &&32 ViewMatchers.withChild(ViewMatchers.withText(text)).matches(holder.itemView)33 }34 }35 fun recyclerViewScrollToAndVerifyPosition(recyclerViewId: Int, position: Int, text: String) {36 Espresso.onView(ViewMatchers.withId(recyclerViewId))37 .perform(RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(position))38 .check(ViewAssertions.matches(hasTextForPosition(position, text)))39 }40}...

Full Screen

Full Screen

ExploreRobot.kt

Source: ExploreRobot.kt Github

copy

Full Screen

...11 * Created by imozerov on 15.06.16.12 */​13class ExploreRobot {14 fun openMap() {15 onView(withChild(withText(R.string.map_fragment_pager_label))).perform(click())16 }17 fun openArtList() {18 onView(withChild(withText(R.string.list_fragment_pager_label))).perform(click())19 }20 fun openFavourites() {21 onView(withChild(withText(R.string.favourites_fragment_pager_label))).perform(click())22 }23 fun toggleSort() {24 val sortButton = onView(25 allOf(withId(R.id.action_sort), isDisplayed()))26 sortButton.perform(click())27 }28}...

Full Screen

Full Screen

withChild

Using AI Code Generation

copy

Full Screen

1import android.support.test.espresso.matcher.ViewMatchers.withChild;2import android.support.test.espresso.matcher.ViewMatchers.withId;3import android.support.test.espresso.matcher.ViewMatchers.withText;4import android.support.test.espresso.matcher.ViewMatchers.withParent;5import android.support.test.espresso.matcher.ViewMatchers.isDisplayed;6import android.support.test.espresso.matcher.ViewMatchers.isAssignableFrom;7import org.hamcrest.Matchers.allOf;8import org.hamcrest.Matchers.anyOf;9import org.hamcrest.Matchers.instanceOf;10import org.hamcrest.Matchers.is;11import org.hamcrest.Matchers.not;12import android.support.test.espresso.matcher.ViewMatchers.withContentDescription;13import android.support.test.espresso.matcher.ViewMatchers.withClassName;14import android.support.test.espresso.matcher.ViewMatchers.withEffectiveVisibility;15import android.support.test.espresso.matcher.ViewMatchers.withId;16import android.support.test.espresso.matcher.ViewMatchers.withParent;17import android.support.test.espresso.matcher.ViewMatchers.withText;18import android.support.test.espresso.matcher.ViewMatchers.isAssignableFrom;19import org.hamcrest.Matchers.allOf;20import org.hamcrest.Matchers.anyOf;

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

Why does DevOps recommend shift-left testing principles?

Companies are using DevOps to quickly respond to changing market dynamics and customer requirements.

Running Tests In Cypress With GitHub Actions [Complete Guide]

In today’s tech world, where speed is the key to modern software development, we should aim to get quick feedback on the impact of any change, and that is where CI/CD comes in place.

Nov’22 Updates: Live With Automation Testing On OTT Streaming Devices, Test On Samsung Galaxy Z Fold4, Galaxy Z Flip4, &#038; More

Hola Testers! Hope you all had a great Thanksgiving weekend! To make this time more memorable, we at LambdaTest have something to offer you as a token of appreciation.

How To Create Custom Menus with CSS Select

When it comes to UI components, there are two versatile methods that we can use to build it for your website: either we can use prebuilt components from a well-known library or framework, or we can develop our UI components from scratch.

Getting Rid of Technical Debt in Agile Projects

Technical debt was originally defined as code restructuring, but in today’s fast-paced software delivery environment, it has evolved. Technical debt may be anything that the software development team puts off for later, such as ineffective code, unfixed defects, lacking unit tests, excessive manual tests, or missing automated tests. And, like financial debt, it is challenging to pay back.

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