Best Appium-espresso-driver code snippet using android.support.test.espresso.matcher.ViewMatchers.isClickable
Assertions.kt
Source:Assertions.kt
...122 }123 /**124 * Checks if the view is clickable125 */126 fun isClickable() {127 view.check(ViewAssertions.matches(128 ViewMatchers.isClickable()))129 }130 /**131 * Checks if the view is not clickable132 */133 fun isNotClickable() {134 view.check(ViewAssertions.matches(135 Matchers.not(ViewMatchers.isClickable())))136 }137 /**138 * Checks if the view is enabled139 */140 fun isEnabled() {141 view.check(ViewAssertions.matches(142 ViewMatchers.isEnabled()))143 }144 /**145 * Checks if the view is disabled146 */147 fun isDisabled() {148 view.check(ViewAssertions.matches(149 Matchers.not(ViewMatchers.isEnabled())))...
SignInActivityTest.kt
Source:SignInActivityTest.kt
...22import android.support.test.espresso.action.ViewActions.closeSoftKeyboard23import android.support.test.espresso.action.ViewActions.typeText24import android.support.test.espresso.assertion.ViewAssertions.matches25import android.support.test.espresso.matcher.ViewMatchers.isChecked26import android.support.test.espresso.matcher.ViewMatchers.isClickable27import 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.withId31import android.support.test.espresso.matcher.ViewMatchers.withText32import android.support.test.filters.LargeTest33import android.support.test.rule.ActivityTestRule34import android.support.test.runner.AndroidJUnit435import android.view.View36import com.google.samples.apps.topeka.base.R37import com.google.samples.apps.topeka.TestLogin38import com.google.samples.apps.topeka.helper.login39import com.google.samples.apps.topeka.helper.logout40import com.google.samples.apps.topeka.model.Avatar41import com.google.samples.apps.topeka.model.TEST_AVATAR42import com.google.samples.apps.topeka.model.TEST_FIRST_NAME43import com.google.samples.apps.topeka.model.TEST_LAST_INITIAL44import org.hamcrest.Matcher45import org.hamcrest.Matchers.equalTo46import org.hamcrest.Matchers.isEmptyOrNullString47import org.hamcrest.Matchers.not48import org.junit.Before49import org.junit.Rule50import org.junit.Test51import org.junit.runner.RunWith52@RunWith(AndroidJUnit4::class)53@LargeTest54class SignInActivityTest {55 @Suppress("unused") // actually used by Espresso56 val rule57 @Rule get() = object :58 ActivityTestRule<SignInActivity>(SignInActivity::class.java) {59 override fun beforeActivityLaunched() {60 InstrumentationRegistry.getTargetContext().logout()61 login = TestLogin62 }63 override fun getActivityIntent(): Intent {64 val targetContext = InstrumentationRegistry.getTargetContext()65 return Intent(targetContext, SignInActivity::class.java).putExtra("EDIT", true)66 }67 }68 @Before fun clearPreferences() {69 InstrumentationRegistry.getTargetContext().logout()70 }71 @Test fun checkFab_initiallyNotDisplayed() {72 onView(withId(R.id.done)).check(matches(not(isDisplayed())))73 }74 @Test fun signIn_withoutFirstNameFailed() {75 inputData(null, TEST_LAST_INITIAL, TEST_AVATAR)76 onDoneView().check(matches(not(isDisplayed())))77 }78 @Test fun signIn_withoutLastInitialFailed() {79 inputData(TEST_FIRST_NAME, null, TEST_AVATAR)80 onDoneView().check(matches(not(isDisplayed())))81 }82 @Test fun signIn_withoutAvatarFailed() {83 inputData(TEST_FIRST_NAME, TEST_LAST_INITIAL, null)84 onDoneView().check(matches(not(isDisplayed())))85 }86 @Test fun signIn_withAllPlayerPreferencesSuccessfully() {87 inputData(TEST_FIRST_NAME, TEST_LAST_INITIAL, TEST_AVATAR)88 onDoneView().check(matches(isDisplayed()))89 }90 /* TODO Debug: Espresso does currently not continue after this test. Commenting to keep pace.91 @Test fun signIn_performSignIn() {92 inputData(TEST_FIRST_NAME, TEST_LAST_INITIAL, TEST_AVATAR)93 onDoneView().perform(click())94 assertThat(InstrumentationRegistry.getTargetContext().isLoggedIn(), `is`(true))95 }96 */97 private fun onDoneView() = onView(withId(R.id.done))98 @Test fun signIn_withLongLastName() {99 typeAndHideKeyboard(R.id.last_initial, TEST_FIRST_NAME)100 val expectedValue = TEST_FIRST_NAME[0].toString()101 onView(withId(R.id.last_initial)).check(matches(withText(expectedValue)))102 }103 private fun inputData(firstName: String?, lastInitial: String?, avatar: Avatar?) {104 if (firstName != null) typeAndHideKeyboard(R.id.first_name, firstName)105 if (lastInitial != null) typeAndHideKeyboard(R.id.last_initial, lastInitial)106 if (avatar != null) clickAvatar(avatar)107 }108 private fun typeAndHideKeyboard(targetViewId: Int, text: String) {109 onView(withId(targetViewId)).perform(typeText(text), closeSoftKeyboard())110 }111 private fun clickAvatar(avatar: Avatar) {112 onData(equalTo(avatar))113 .inAdapterView(withId(R.id.avatars))114 .perform(click())115 }116 @Test fun firstName_isInitiallyEmpty() = editTextIsEmpty(R.id.first_name)117 @Test fun lastInitial_isInitiallyEmpty() = editTextIsEmpty(R.id.last_initial)118 private fun editTextIsEmpty(id: Int) {119 onView(withId(id)).check(matches(withText(isEmptyOrNullString())))120 }121 @Test fun avatar_allDisplayed() = checkOnAvatar(isDisplayed())122 @Test fun avatar_isEnabled() = checkOnAvatar(isEnabled())123 @Test fun avatar_notFocusable() = checkOnAvatar(not(isFocusable()))124 @Test fun avatar_notClickable() = checkOnAvatar(not(isClickable()))125 @Test fun avatar_noneChecked() = checkOnAvatar(not(isChecked()))126 private fun checkOnAvatar(matcher: Matcher<View>) {127 (0 until Avatar.values().size).forEach {128 onData(equalTo(Avatar.values()[it]))129 .inAdapterView(withId(R.id.avatars))130 .check(matches(matcher))131 }132 }133}...
EspressoUtils.kt
Source:EspressoUtils.kt
...3import android.support.annotation.StringRes4import android.support.test.espresso.Espresso.onView5import 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`43 *...
DashboardActivityTest.kt
Source:DashboardActivityTest.kt
...3import android.support.test.espresso.action.ViewActions.click4import android.support.test.espresso.assertion.ViewAssertions.matches5import android.support.test.espresso.intent.rule.IntentsTestRule6import android.support.test.espresso.matcher.ViewMatchers7import android.support.test.espresso.matcher.ViewMatchers.isClickable8import android.support.test.espresso.matcher.ViewMatchers.withId9import android.support.test.runner.AndroidJUnit410import id.anhs.footballapps.R.id.*11import id.anhs.footballapps.ui.activity.dashboard.DashboardActivity12import org.junit.Rule13import org.junit.Test14import org.junit.runner.RunWith15@RunWith(AndroidJUnit4::class)16class DashboardActivityTest {17 @Rule18 @JvmField19 val mainRule = IntentsTestRule(DashboardActivity::class.java)20 @Test21 fun testOnClickBottomNavigation() {22 onView(withId(dashboard_bot_nav_matches)).check(matches(isClickable()))23 onView(withId(dashboard_bot_nav_teams)).check(matches(isClickable()))24 onView(withId(dashboard_bot_nav_favorites)).check(matches(isClickable()))25 }26 @Test27 fun testIsMatchesPageDisplayed() {28 onView(withId(dashboard_bot_nav_matches)).perform(click())29 onView(withId(matches_home_linear_main_layout)).check(matches(ViewMatchers.isDisplayed()))30 }31 @Test32 fun testIsTeamsPageDisplayed() {33 onView(withId(dashboard_bot_nav_teams)).perform(click())34 onView(withId(teams_home_coordinator_main_layout)).check(matches(ViewMatchers.isDisplayed()))35 }36 @Test37 fun testIsFavoritesPageDisplayed() {38 onView(withId(dashboard_bot_nav_favorites)).perform(click())...
MainActivityTest.kt
Source:MainActivityTest.kt
1package com.neobyte.footbalschedule2import android.support.test.espresso.Espresso.onView3import android.support.test.espresso.action.ViewActions.click4import android.support.test.espresso.assertion.ViewAssertions.matches5import android.support.test.espresso.matcher.ViewMatchers.isClickable6import android.support.test.espresso.matcher.ViewMatchers.isDisplayed7import android.support.test.espresso.matcher.ViewMatchers.withId8import android.support.test.filters.LargeTest9import android.support.test.rule.ActivityTestRule10import android.support.test.runner.AndroidJUnit411import org.junit.Rule12import org.junit.Test13import org.junit.runner.RunWith14@RunWith(AndroidJUnit4::class)15@LargeTest16class MainActivityTest {17 @Rule18 @JvmField19 val mActivityRule: ActivityTestRule<MainActivity> = ActivityTestRule(MainActivity::class.java)20 @Test21 fun testAllBottomMenuIsClickable() {22 onView(withId(R.id.action_prev)).check(matches(isClickable()))23 onView(withId(R.id.action_next)).check(matches(isClickable()))24 onView(withId(R.id.action_favorite)).check(matches(isClickable()))25 }26 @Test27 fun testNextMatchIsDisplayed() {28 onView(withId(R.id.action_next)).perform(click())29 onView(withId(R.id.next_match_layout)).check(matches(isDisplayed()))30 }31 @Test32 fun testPrevMatchIsDisplayed() {33 onView(withId(R.id.action_prev)).perform(click())34 onView(withId(R.id.prev_match_layout)).check(matches(isDisplayed()))35 }36 @Test37 fun testFavMatchIsDisplayed() {38 onView(withId(R.id.action_favorite)).perform(click())...
TabletNotSupportedRobot.kt
Source:TabletNotSupportedRobot.kt
...3 */4package uk.nhs.nhsx.sonar.android.app.testhelpers.robots5import androidx.test.espresso.Espresso.onView6import androidx.test.espresso.assertion.ViewAssertions.matches7import androidx.test.espresso.matcher.ViewMatchers.isClickable8import androidx.test.espresso.matcher.ViewMatchers.isDisplayed9import androidx.test.espresso.matcher.ViewMatchers.withId10import uk.nhs.nhsx.sonar.android.app.R11import uk.nhs.nhsx.sonar.android.app.testhelpers.checkViewHasText12class TabletNotSupportedRobot {13 fun checkScreenIsDisplayed() {14 checkToolbar()15 checkTitle()16 checkDescription()17 checkBottomUrlIsDisplayed()18 }19 private fun checkToolbar() {20 onView(withId(R.id.nhsLogo)).check(matches(isDisplayed()))21 checkViewHasText(R.id.nhsLogoName, R.string.app_title)22 }23 private fun checkTitle() {24 checkViewHasText(R.id.edgeCaseTitle, R.string.tablet_support_title)25 }26 private fun checkDescription() {27 checkViewHasText(R.id.edgeCaseText, R.string.tablet_support_description)28 }29 private fun checkBottomUrlIsDisplayed() {30 checkViewHasText(R.id.tabletInformationUrl, R.string.tablet_information_url)31 onView(withId(R.id.tabletInformationUrl)).check(matches(isClickable()))32 }33}...
ViewInteractions.kt
Source:ViewInteractions.kt
...12import org.hamcrest.Matchers.startsWith13import org.hamcrest.core.IsNot.not14fun ViewInteraction.isDisplayedEffectively(): ViewInteraction =15 check(matches(withEffectiveVisibility(Visibility.VISIBLE)))16fun ViewInteraction.isClickable(): ViewInteraction = check(matches(ViewMatchers.isClickable()))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)))...
EspressoTest.kt
Source:EspressoTest.kt
1package pl.droidsonroids.clicktest.clicktest2import android.support.test.espresso.Espresso.onView3import android.support.test.espresso.action.ViewActions.click4import android.support.test.espresso.assertion.ViewAssertions.matches5import android.support.test.espresso.matcher.ViewMatchers.isClickable6import android.support.test.espresso.matcher.ViewMatchers.withContentDescription7import android.support.test.rule.ActivityTestRule8import android.support.test.runner.AndroidJUnit49import org.junit.Rule10import org.junit.Test11import org.junit.runner.RunWith12@RunWith(AndroidJUnit4::class)13class EspressoTest {14 @get:Rule15 public val rule = ActivityTestRule<MainActivity>(MainActivity::class.java, true, true)16 @Test17 fun shouldNotPerformClick() {18 onView(withContentDescription("test")).perform(click()).check(matches(isClickable()))19 }20}...
isClickable
Using AI Code Generation
1Espresso.onView(ViewMatchers.withId(R.id.button)).check(ViewAssertions.matches(ViewMatchers.isClickable()));2Espresso.onView(ViewMatchers.withId(R.id.button)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()));3Espresso.onView(ViewMatchers.withId(R.id.button)).check(ViewAssertions.matches(ViewMatchers.isEnabled()));4Espresso.onView(ViewMatchers.withId(R.id.button)).check(ViewAssertions.matches(ViewMatchers.isFocusable()));5Espresso.onView(ViewMatchers.withId(R.id.button)).check(ViewAssertions.matches(ViewMatchers.isFocused()));6Espresso.onView(ViewMatchers.withId(R.id.button)).check(ViewAssertions.matches(ViewMatchers.isNotChecked()));7Espresso.onView(ViewMatchers.withId(R.id.button)).check(ViewAssertions.matches(ViewMatchers.isNotChecked()));8Espresso.onView(ViewMatchers.withId(R.id.button)).check(ViewAssertions.matches(ViewMatchers.isSelected()));9Espresso.onView(ViewMatchers.withId(R.id.button)).check(ViewAssertions.matches(ViewMatchers.isClickable()));10Espresso.onView(ViewMatchers.withId(R.id.button)).check(ViewAssertions.matches(ViewMatchers.isClickable()));11Espresso.onView(ViewMatchers.withId(R.id.button)).check(ViewAssertions.matches(ViewMatchers.isClickable()));12Espresso.onView(ViewMatchers.withId(R.id.button)).check(ViewAssertions.matches(ViewMatchers.isClickable()));13Espresso.onView(ViewMatchers.withId(R.id.button)).check(ViewAssertions.matches(ViewMatchers.isClickable()));14Espresso.onView(ViewMatchers.withId(R.id.button)).check(ViewAssertions.matches
isClickable
Using AI Code Generation
1ViewInteraction view = onView( allOf( withId(R.id.text1), withText("text1") ) );2view.perform( click() );3view.check( matches( isClickable() ) );4ViewInteraction view = onView( allOf( withId(R.id.text1), withText("text1") ) );5view.perform( click() );6view.check( matches( isEnabled() ) );7ViewInteraction view = onView( allOf( withId(R.id.text1), withText("text1") ) );8view.perform( click() );9view.check( matches( isFocusable() ) );10ViewInteraction view = onView( allOf( withId(R.id.text1), withText("text1") ) );11view.perform( click() );12view.check( matches( isSelected() ) );13ViewInteraction view = onView( allOf( withId(R.id.text1), withText("text1") ) );14view.perform( click() );15view.check( matches( isDisplayed() ) );16ViewInteraction view = onView( allOf( withId(R.id.text1), withText("text1") ) );17view.perform( click() );18view.check( matches( isCompletelyDisplayed() ) );19ViewInteraction view = onView( allOf( withId(R.id.text1), withText("text1") ) );20view.perform( click() );21view.check( matches( withEffectiveVisibility( ViewMatchers.Visibility.VISIBLE ) ) );22ViewInteraction view = onView( allOf( withId(R.id.text1), withText("text1") ) );23view.perform( click() );24view.check( matches( withEffectiveVisibility( ViewMatchers.Visibility.VISIBLE ) ) );25ViewInteraction view = onView( allOf( withId(R.id.text1), withText("text1") ) );
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!!