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

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

Assertions.kt

Source:Assertions.kt Github

copy

Full Screen

...80 }81 /**82 * Checks if the view is selected83 */84 fun isSelected() {85 view.check(ViewAssertions.matches(86 ViewMatchers.isSelected()))87 }88 /**89 * Checks if the view is not selected90 */91 fun isNotSelected() {92 view.check(ViewAssertions.matches(93 Matchers.not(ViewMatchers.isSelected())))94 }95 /**96 * Checks if the view is focused97 */98 fun isFocused() {99 view.check(ViewAssertions.matches(100 ViewMatchers.hasFocus()))101 }102 /**103 * Checks if the view is not focused104 */105 fun isNotFocused() {106 view.check(ViewAssertions.matches(107 Matchers.not(ViewMatchers.hasFocus())))...

Full Screen

Full Screen

TestUtils.kt

Source:TestUtils.kt Github

copy

Full Screen

...78 }79 fun assertPositionIsSelected(recyclerViewId: Int, position: Int, shouldBeSelected: Boolean) {80 onView(withId(recyclerViewId))81 .perform(RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(position))82 var assertion = matches(not<View>(ViewMatchers.isSelected()))83 if (shouldBeSelected) {84 assertion = matches(ViewMatchers.isSelected())85 }86 onView(withRecyclerView(recyclerViewId).atPosition(position))87 .check(assertion)88 }89 fun assertThatViewHasDescendantWithText(viewId: Int, expectedText: String) {90 onView(withId(viewId)).check(matches(hasDescendant(withText(expectedText))))91 }92 fun assertSingleSelection(recyclerViewId: Int, mFakeList: List<*>) {93 for (i in mFakeList.indices) {94 TestUtils.performClickAtPosition(recyclerViewId, i)95 TestUtils.assertPositionIsSelected(recyclerViewId, i, true)96 if (i == 0) {97 //click again in order to deselect item98 TestUtils.performClickAtPosition(recyclerViewId, i)99 TestUtils.assertPositionIsSelected(recyclerViewId, i, false)100 }101 }102 for (j in mFakeList.indices) {103 var isSelected = false104 if (j == mFakeList.size - 1) {105 isSelected = true106 }107 TestUtils.assertPositionIsSelected(recyclerViewId, j, isSelected)108 }109 }110}...

Full Screen

Full Screen

ViewMatchersTest.kt

Source:ViewMatchersTest.kt Github

copy

Full Screen

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

Full Screen

Full Screen

HistoryTester.kt

Source:HistoryTester.kt Github

copy

Full Screen

...7import android.support.test.espresso.contrib.RecyclerViewActions.actionOnItemAtPosition8import android.support.test.espresso.contrib.RecyclerViewActions.scrollToPosition9import android.support.test.espresso.matcher.ViewMatchers.hasSibling10import android.support.test.espresso.matcher.ViewMatchers.isDisplayed11import android.support.test.espresso.matcher.ViewMatchers.isSelected12import android.support.test.espresso.matcher.ViewMatchers.withId13import android.support.test.espresso.matcher.ViewMatchers.withText14import android.support.v7.widget.RecyclerView15import org.hamcrest.Matchers.allOf16import org.hamcrest.Matchers.not17import pl.srw.billcalculator.R18internal class HistoryTester internal constructor(parent: AppTester) : Tester() {19 private val billTester: BillTester = BillTester(parent)20 private var lastPosition: Int = 021 fun openBillWithReadings(from: String, to: String): BillTester {22 clickText("$from - $to")23 return billTester24 }25 fun openBillAtPosition(position: Int): BillTester {26 onView(withId(R.id.bill_list))27 .perform(actionOnItemAtPosition<RecyclerView.ViewHolder>(position, click()))28 return billTester29 }30 fun changeItemSelectionAtPosition(position: Int): HistoryTester {31 scrollToIndex(position)32 onView(withId(R.id.bill_list))33 .perform(actionOnItemAtPosition<RecyclerView.ViewHolder>(position, longClick()))34 return this35 }36 fun changeItemSelectionWithReadings(from: String, to: String): HistoryTester {37 onView(allOf(withId(R.id.history_item_logo), hasSibling(withText("$from - $to"))))38 .perform(click())39 return this40 }41 fun deleteBillWithReadings(from: String, to: String): HistoryTester {42 onView(withText("$from - $to"))43 .perform(swipeAwayRight())44 return this45 }46 fun deleteSelected(): HistoryTester {47 clickView(R.id.action_delete)48 return this49 }50 fun undoDelete(): HistoryTester {51 clickText(R.string.action_undo_delete)52 return this53 }54 fun checkEmptyHistoryIsShown(): HistoryTester {55 onView(withText(R.string.empty_history))56 .check(matches(isDisplayed()))57 return this58 }59 fun checkEmptyHistoryIsNotShown(): HistoryTester {60 onView(withText(R.string.empty_history))61 .check(matches(not(isDisplayed())))62 return this63 }64 fun checkUndoMessageIsShown(): HistoryTester {65 onView(withText(R.string.bill_deleted))66 .check(matches(isDisplayed()))67 return this68 }69 fun checkItemSelected(position: Int): HistoryTester {70 scrollToIndex(position)71 onRecyclerViewItem(withId(R.id.bill_list), position)72 .checkView(R.id.history_item_logo, matches(isSelected()))73 return this74 }75 fun checkItemNotSelected(position: Int): HistoryTester {76 scrollToIndex(position)77 onRecyclerViewItem(withId(R.id.bill_list), position)78 .checkView(R.id.history_item_logo, matches(not(isSelected())))79 return this80 }81 fun checkNoSelection(): HistoryTester {82 onView(isSelected())83 .check(doesNotExist())84 return this85 }86 fun checkDeleteButtonShown(): HistoryTester {87 onView(withId(R.id.action_delete))88 .check(matches(isDisplayed()))89 return this90 }91 fun checkDeleteButtonHidden(): HistoryTester {92 onView(withId(R.id.action_delete))93 .check(doesNotExist())94 return this95 }96 fun checkItemReadings(position: Int, firstLine: String, secondLine: String) {...

Full Screen

Full Screen

ActivityMainTest.kt

Source:ActivityMainTest.kt Github

copy

Full Screen

...32 return mActivityRule.activity33 .findViewById<RecyclerView>(R.id.recyclerView)34 .getChildAt(id)35 }36 private fun validateSelection(index: Int, text: String, isSelected: Boolean) {37 assertEquals(38 text,39 atIndex(index).findViewById<TextView>(R.id.title).text40 )41 assertEquals(42 isSelected,43 atIndex(index).getTag(R.id.isSelected)44 )45 }46 private fun assertList(vararg expectedItems: Pair<String, Boolean>) {47 for (i in expectedItems.indices) {48 validateSelection(i, expectedItems[i].first, expectedItems[i].second)49 }50 }51 private fun selectTwo() {52 onView(nthChildOf(withId(R.id.recyclerView), 0)).perform(longClick())53 onView(nthChildOf(withId(R.id.recyclerView), 1)).perform(click())54 }55 @Test56 fun longClickingOneAndClickingAnother_shouldSelectTwoItems() {57 selectTwo()...

Full Screen

Full Screen

ViewMatchers.kt

Source:ViewMatchers.kt Github

copy

Full Screen

...9import androidx.test.espresso.matcher.ViewMatchers.hasFocus as espressoHasFocus10import androidx.test.espresso.matcher.ViewMatchers.isChecked as espressoIsChecked11import androidx.test.espresso.matcher.ViewMatchers.isDisplayed as espressoIsDisplayed12import androidx.test.espresso.matcher.ViewMatchers.isEnabled as espressoIsEnabled13import androidx.test.espresso.matcher.ViewMatchers.isSelected as espressoIsSelected14// These functions are defined at the top-level so they appear in autocomplete, like the static methods on15// Android's [ViewMatchers] class.16/**17 * The existing [espressoHasFocus] function but uses a boolean to invert rather than requiring the [not] matcher.18 */19fun hasFocus(hasFocus: Boolean): Matcher<View> = maybeInvertMatcher(espressoHasFocus(), hasFocus)20/**21 * The existing [espressoIsChecked] function but uses a boolean to invert rather than requiring the [not] matcher.22 */23fun isChecked(isChecked: Boolean): Matcher<View> = maybeInvertMatcher(espressoIsChecked(), isChecked)24/**25 * The existing [espressoIsDisplayed] function but uses a boolean to invert rather than requiring the [not] matcher.26 */27fun isDisplayed(isDisplayed: Boolean): Matcher<View> = maybeInvertMatcher(espressoIsDisplayed(), isDisplayed)28/**29 * The existing [espressoIsEnabled] function but uses a boolean to invert rather than requiring the [not] matcher.30 */31fun isEnabled(isEnabled: Boolean): Matcher<View> = maybeInvertMatcher(espressoIsEnabled(), isEnabled)32/**33 * The existing [espressoIsSelected] function but uses a boolean to invert rather than requiring the [not] matcher.34 */35fun isSelected(isSelected: Boolean): Matcher<View> = maybeInvertMatcher(espressoIsSelected(), isSelected)...

Full Screen

Full Screen

OpenPullRequestsTest.kt

Source:OpenPullRequestsTest.kt Github

copy

Full Screen

...29 onView(withText("JAVA")).check(matches(isDisplayed()))30 onView(withText("JAVASCRIPT")).check(matches(isDisplayed()))31 onView(withText("NODE.JS")).check(matches(isDisplayed()))32 onView(withText("JAVASCRIPT")).perform(click())33 onView(withText("JAVASCRIPT")).check(matches(isSelected()))34 onView(withText("NODE.JS")).perform(click())35 onView(withText("NODE.JS")).check(matches(isSelected()))36 onView(withText("JAVA")).perform(click())37 onView(withText("JAVA")).check(matches(isSelected()))38 onView(allOf(withId(R.id.rv_list), isDisplayed())).perform(39 RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(0, click()))40 }41}...

Full Screen

Full Screen

ViewMatchersKtTest.kt

Source:ViewMatchersKtTest.kt Github

copy

Full Screen

...12 ::hasFocus to ViewMatchers.hasFocus(),13 ::isChecked to ViewMatchers.isChecked(),14 ::isDisplayed to ViewMatchers.isDisplayed(),15 ::isEnabled to ViewMatchers.isEnabled(),16 ::isSelected to ViewMatchers.isSelected()17)18class ViewMatchersKtTest {19 @Test20 fun `WHEN checking the unmodified ViewMatcher THEN it equals the underlying ViewMatcher`() {21 BOOLEAN_VIEW_MATCHER_TO_UNDERLYING_MATCHER.forEach { (input, expected) ->22 assertEqualsMatchers(expected, input(true))23 }24 }25 @Test26 fun `WHEN checking the modified ViewMatcher tHEN it equals the inversion of the underlying ViewMatcher`() {27 BOOLEAN_VIEW_MATCHER_TO_UNDERLYING_MATCHER.forEach { (input, inversionOfExpected) ->28 assertEqualsMatchers(not(inversionOfExpected), input(false))29 }30 }...

Full Screen

Full Screen

isSelected

Using AI Code Generation

copy

Full Screen

1ViewInteraction appCompatRadioButton = onView( allOf( withId( R.id.radio_button ), withText( "Option 2" ), isDisplayed()));2appCompatRadioButton.perform( click());3ViewInteraction appCompatRadioButton2 = onView( allOf( withId( R.id.radio_button ), withText( "Option 2" ), isDisplayed()));4appCompatRadioButton2.check( matches( isSelected()));5ViewInteraction appCompatRadioButton3 = onView( allOf( withId( R.id.radio_button ), withText( "Option 3" ), isDisplayed()));6appCompatRadioButton3.perform( click());7ViewInteraction appCompatRadioButton4 = onView( allOf( withId( R.id.radio_button ), withText( "Option 3" ), isDisplayed()));8appCompatRadioButton4.check( matches( isSelected()));9ViewInteraction appCompatRadioButton5 = onView( allOf( withId( R.id.radio_button ), withText( "Option 2" ), isDisplayed()));10appCompatRadioButton5.perform( click());11ViewInteraction appCompatRadioButton6 = onView( allOf( withId( R.id.radio_button ), withText( "Option 2" ), isDisplayed()));12appCompatRadioButton6.check( matches( isChecked()));13ViewInteraction appCompatRadioButton7 = onView( allOf( withId( R.id.radio_button ), withText( "Option 3" ), isDisplayed()));14appCompatRadioButton7.perform( click());15ViewInteraction appCompatRadioButton8 = onView( allOf( withId( R.id.radio_button ), withText( "Option 3" ), isDisplayed()));16appCompatRadioButton8.check( matches( isChecked()));17}18}

Full Screen

Full Screen

isSelected

Using AI Code Generation

copy

Full Screen

1ViewInteraction appCompatCheckBox = onView( allOf(withId(R.id.checkbox), withText("Checkbox 1"), isDisplayed())); appCompatCheckBox.perform(click()); appCompatCheckBox.check(matches(isChecked()));2ViewInteraction appCompatEditText = onView( allOf(withId(R.id.edittext), isDisplayed())); appCompatEditText.perform(replaceText("test"), closeSoftKeyboard()); appCompatEditText.check(matches(hasErrorText("error")));3ViewInteraction appCompatEditText = onView( allOf(withId(R.id.edittext), isDisplayed())); appCompatEditText.perform(replaceText("test"), closeSoftKeyboard()); appCompatEditText.check(matches(hasErrorText("error")));4ViewInteraction textView = onView( allOf(withId(R.id.textview), withText("Text View"), isDisplayed())); textView.check(matches(hasTextColor(Color.BLUE)));5ViewInteraction textView = onView( allOf(withId(R.id.textview), withText("Text View"), isDisplayed())); textView.check(matches(hasTextColor(Color.BLUE)));6ViewInteraction textView = onView( allOf(withId(R.id.textview), withText("Text View"), isDisplayed())); textView.check(matches(hasTextColor(Color.BLUE)));

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