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

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

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

ViewMatchersTest.kt

Source:ViewMatchersTest.kt Github

copy

Full Screen

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

Full Screen

Full Screen

EmojiTestRecord.kt

Source:EmojiTestRecord.kt Github

copy

Full Screen

...7import android.support.test.espresso.assertion.ViewAssertions.matches8import android.support.test.espresso.matcher.ViewMatchers9import android.support.test.espresso.matcher.ViewMatchers.isDisplayed10import android.support.test.espresso.matcher.ViewMatchers.withId11import android.support.test.espresso.matcher.ViewMatchers.withParent12import android.support.test.espresso.matcher.ViewMatchers.withText13import android.support.test.rule.ActivityTestRule14import android.support.test.runner.AndroidJUnit415import android.test.suitebuilder.annotation.LargeTest16import android.view.View17import com.jakewharton.espresso.OkHttp3IdlingResource18import com.xamarin.azuredevdays.HTTP_CLIENT19import com.xamarin.azuredevdays.MainActivity20import com.xamarin.azuredevdays.R21import com.xamarin.testcloud.espresso.Factory22import com.xamarin.testcloud.espresso.ReportHelper23import org.hamcrest.CoreMatchers.allOf24import org.junit.After25import org.junit.Rule26import org.junit.Test27import org.junit.runner.RunWith28@LargeTest29@RunWith(AndroidJUnit4::class)30class EmojiTestRecord {31 @Rule @JvmField val activityTestRule = ActivityTestRule(MainActivity::class.java)32 @Rule @JvmField val reportHelper: ReportHelper = Factory.getReportHelper()33 @Test34 fun emojiTestRecord() {35 val sentimentText = onView(36 allOf<View>(37 ViewMatchers.withId(R.id.sentimentText),38 withParent(withId(R.id.backgroundLayout)),39 isDisplayed()40 )41 )42 reportHelper.label("On Main Page")43 sentimentText.perform(click())44 sentimentText.perform(replaceText("Happy"), closeSoftKeyboard())45 reportHelper.label("Text value entered:: Happy")46 val submitButton = onView(47 allOf<View>(48 withId(R.id.getSentimentButton), withText("Submit"),49 withParent(withId(R.id.backgroundLayout)),50 isDisplayed()51 )52 )53 submitButton.perform(click())54 val idlingResource = OkHttp3IdlingResource.create("okhttp", HTTP_CLIENT)55 IdlingRegistry.getInstance().register(idlingResource)56 onView(withId(R.id.emojiView)).check(matches(isDisplayed()))57 reportHelper.label("Result Emoji Loaded")58 IdlingRegistry.getInstance().unregister(idlingResource)59 }60 @After61 fun tearDown() {62 reportHelper.label("Stopping App")63 }...

Full Screen

Full Screen

DataInteractionsTest.kt

Source:DataInteractionsTest.kt Github

copy

Full Screen

...10import android.support.test.espresso.assertion.ViewAssertions.matches11import android.support.test.espresso.matcher.PreferenceMatchers.withKey12import android.support.test.espresso.matcher.ViewMatchers.isDisplayed13import android.support.test.espresso.matcher.ViewMatchers.withId14import android.support.test.espresso.matcher.ViewMatchers.withParent15import android.support.test.espresso.matcher.ViewMatchers.withText16import com.example.android.architecture.blueprints.todoapp.test.helpers.CommonElements.openDrawer17import org.hamcrest.CoreMatchers.allOf18import org.hamcrest.CoreMatchers.instanceOf19/**20 * DataInteraction samples.21 */22class DataInteractionsTest : BaseTest() {23 @Test24 fun dataInteractionSample() {25 openDrawer()26 onView(allOf<View>(withId(R.id.design_menu_item_text),27 withText(R.string.settings_title))).perform(click())28 // Start of the flow as shown on Figure 1-8.29 onData(instanceOf(PreferenceActivity.Header::class.java))30 .inAdapterView(withId(android.R.id.list))31 .atPosition(0)32 .onChildView(withId(android.R.id.title))33 .check(matches(withText("General")))34 .perform(click())35 onData(withKey("email_edit_text"))36 /*we have to point explicitly what is the parent of of the General prefs list37 because there are two {@ListView}s with the same id - android.R.id.list in the hierarchy*/38 .inAdapterView(allOf<View>(withId(android.R.id.list), withParent(withId(android.R.id.list_container))))39 .check(matches(isDisplayed()))40 .perform(click())41 onView(withId(android.R.id.edit)).perform(replaceText("sample@ema.il"))42 onView(withId(android.R.id.button1)).perform(click())43 // Verify new email is shown.44 onData(withKey("email_edit_text"))45 .inAdapterView(allOf<View>(withId(android.R.id.list), withParent(withId(android.R.id.list_container))))46 .onChildView(withId(android.R.id.summary))47 .check(matches(withText("sample@ema.il")))48 }49}...

Full Screen

Full Screen

EspressoUtils.kt

Source:EspressoUtils.kt Github

copy

Full Screen

...5import android.support.test.espresso.ViewInteraction6import android.support.test.espresso.matcher.ViewMatchers.isAssignableFrom7import android.support.test.espresso.matcher.ViewMatchers.isClickable8import android.support.test.espresso.matcher.ViewMatchers.withId9import android.support.test.espresso.matcher.ViewMatchers.withParent10import android.support.test.espresso.matcher.ViewMatchers.withText11import android.support.v7.widget.Toolbar12import android.view.View13import android.widget.ImageButton14import org.hamcrest.Matchers.allOf15/**16 * Utility class for managing Espresso views17 */18class EspressoUtils {19 companion object {20 /**21 * Retrieves the [ViewInteraction] of the up button22 *23 * @return the [ViewInteraction] instance24 */25 @JvmStatic26 fun onUpButtonView() = onView(27 allOf<View>(isAssignableFrom(ImageButton::class.java),28 withParent(isAssignableFrom(Toolbar::class.java)),29 isClickable()))30 31 /**32 * Creates a [ViewInteraction] for the view with the given resource id, if found33 *34 * @param id the views' resource id35 *36 * @return the [ViewInteraction] instance37 */38 @JvmStatic39 fun onViewWithId(@IdRes id: Int) = onView(withId(id))40 41 /**42 * Creates a [ViewInteraction] for the view that is displaying the text with the resource `id`...

Full Screen

Full Screen

MoviesRecyclerViewTest.kt

Source:MoviesRecyclerViewTest.kt Github

copy

Full Screen

...11import android.support.test.espresso.assertion.ViewAssertions.matches12import android.support.test.espresso.contrib.RecyclerViewActions.actionOnItemAtPosition13import android.support.test.espresso.matcher.ViewMatchers.isAssignableFrom14import android.support.test.espresso.matcher.ViewMatchers.withId15import android.support.test.espresso.matcher.ViewMatchers.withParent16import android.support.test.espresso.matcher.ViewMatchers.withText17import android.support.v7.widget.RecyclerView18import android.view.View19import org.hamcrest.core.AllOf.allOf20import org.hamcrest.core.IsInstanceOf.instanceOf21import org.hamcrest.core.StringStartsWith.startsWith22/**23 * Created by anh.hoang on 6/1/17.24 */25@RunWith(AndroidJUnit4::class)26class MoviesRecyclerViewTest {27 @Rule28 var mActivityTestRule = ActivityTestRule(MoviesActivity::class.java)29 @Test30 fun onItemsClick_activityChanges() {31 onView(withId(R.id.rv_movies))32 .perform(actionOnItemAtPosition<RecyclerView.ViewHolder>(0, click()))33 // On click success next screen should have title34 onView(35 allOf<View>(36 instanceOf<Any>(TextView::class.java),37 withParent(isAssignableFrom(Toolbar::class.java))))38 .check(matches(withText(startsWith(""))))39 }40}...

Full Screen

Full Screen

ViewInteractions.kt

Source:ViewInteractions.kt Github

copy

Full Screen

...17fun ViewInteraction.isNotClickable(): ViewInteraction = check(matches(not(ViewMatchers.isClickable())))18fun onTextStartingWith(text: String): ViewInteraction = onView(withText(startsWith(text)))19fun onImage(@DrawableRes imageId: Int): ViewInteraction = onView(withImage(imageId))20fun onSwitchPreference(@StringRes textId: Int): ViewInteraction = onView(allOf(21 withParent(withParent(hasDescendant(withText(textId)))),22 isAssignableFrom(Switch::class.java)))...

Full Screen

Full Screen

CommonElements.kt

Source:CommonElements.kt Github

copy

Full Screen

2import android.support.test.espresso.Espresso.onView3import android.support.test.espresso.ViewInteraction4import android.support.test.espresso.action.ViewActions.click5import android.support.test.espresso.matcher.ViewMatchers.withId6import android.support.test.espresso.matcher.ViewMatchers.withParent7import android.widget.ImageButton8import com.example.android.architecture.blueprints.todoapp.R9import org.hamcrest.CoreMatchers.instanceOf10import org.hamcrest.core.AllOf.allOf11object CommonElements {12 private val HAMBURGER_BUTTON = onView(allOf(instanceOf(ImageButton::class.java),13 withParent(withId(R.id.toolbar))))14 @JvmStatic15 fun openDrawer(): ViewInteraction {16 return HAMBURGER_BUTTON.perform(click())17 }18}...

Full Screen

Full Screen

withParent

Using AI Code Generation

copy

Full Screen

1import android.support.test.espresso.matcher.ViewMatchers.withParent;2import static android.support.test.espresso.matcher.ViewMatchers.isAssignableFrom;3import static android.support.test.espresso.matcher.ViewMatchers.withId;4import static org.hamcrest.Matchers.allOf;5import static android.support.test.espresso.Espresso.onView;6import static android.support.test.espresso.action.ViewActions.click;7import static android.support.test.espresso.assertion.ViewAssertions.matches;8import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;9import static android.support.test.espresso.matcher.ViewMatchers.withText;10import android.support.test.espresso.matcher.ViewMatchers;11import android.support.test.espresso.matcher.ViewMatchers.Visibility;12import android.support.test.espresso.matcher.BoundedMatcher;13import android.support.v7.widget.Toolbar;14import android.view.View;15import org.hamcrest.Description;16import org.hamcrest.Matcher;17import org.hamcrest.Matchers;18import android.support.test.espresso.contrib.RecyclerViewActions;19import static android.support.test.espresso.contrib.RecyclerViewActions.actionOnItemAtPosition;20import android.support.v7.widget.RecyclerView;21import android.widget.TextView;22import android.support.v7.widget.AppCompatTextView;23import android.support.v7.widget.AppCompatEditText;24import android.support.v7.widget.AppCompatButton;25import android.support.v7.widget.AppCompatImageView;26import android.support.v7.widget.AppCompatImageButton;27import android.support.v7.widget.AppCompatSpinner;28import android.support.v7.widget.AppCompatCheckBox;29import android.support.v7.widget.AppCompatRadioButton;30import android.support.v7.widget.AppCompatCheckedTextView;31import android.support.v7.widget.AppCompatMultiAutoCompleteTextView;32import android.support.v7.widget.AppCompatAutoCompleteTextView;33import android.support.v7.widget.AppCompatRatingBar;34import android.support.v7.widget.AppCompatSeekBar;35import android.support.v7.widget.AppCompatToggleButton;36import android.support.v7.widget.AppCompatTextView;37import android.support.v7.widget.AppCompatEditText;38import android.support.v7.widget.AppCompatButton;39import android.support.v7.widget.AppCompatImageView;40import android.support.v7.widget.AppCompatImageButton;41import android.support.v7.widget.AppCompatSpinner;42import android.support.v7.widget.AppCompatCheckBox;43import android.support.v7.widget.AppCompatRadioButton;44import android.support.v7.widget.AppCompatCheckedTextView;45import android.support.v7.widget.AppCompatMultiAutoCompleteTextView;46import android.support.v7.widget.AppCompatAutoCompleteTextView;47import android.support.v7.widget.AppCompatRatingBar;48import android.support.v7.widget.AppCompatSeekBar;49import android.support.v7.widget.AppCompatToggleButton;50import android.support.v7.widget.AppCompatTextView;

Full Screen

Full Screen

withParent

Using AI Code Generation

copy

Full Screen

1onView(withId(R.id.textview1)).perform(click());2onView(withText("Hello")).check(matches(isDisplayed()));3onView(withText("Hello")).check(matches(withParent(withId(R.id.textview1))));4onView(withId(R.id.textview2)).perform(click());5onView(withText("Hello")).check(matches(isDisplayed()));6onView(withText("Hello")).check(matches(withParent(withId(R.id.textview2))));7onView(withId(R.id.textview3)).perform(click());8onView(withText("Hello")).check(matches(isDisplayed()));9onView(withText("Hello")).check(matches(withParent(withId(R.id.textview3))));10onView(withId(R.id.textview4)).perform(click());11onView(withText("Hello")).check(matches(isDisplayed()));12onView(withText("Hello")).check(matches(withParent(withId(R.id.textview4))));13onView(withId(R.id.textview5)).perform(click());14onView(withText("Hello")).check(matches(isDisplayed()));15onView(withText("Hello")).check(matches(withParent(withId(R.id.textview5))));16onView(withId(R.id.textview6)).perform(click());17onView(withText("Hello")).check(matches(isDisplayed()));18onView(withText("Hello")).check(matches(withParent(withId(R.id.textview6))));19onView(withId(R.id.textview7)).perform(click());20onView(withText("Hello")).check(matches(isDisplayed()));21onView(withText("Hello")).check(matches(withParent(withId(R.id.textview7))));

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