Best Appium-espresso-driver code snippet using android.support.test.espresso.matcher.ViewMatchers.withInputType
ExpressoUtil.kt
Source:ExpressoUtil.kt  
...159    fun isDisabled(id: Int) {160        onView(withId(id)).check(matches(not(isEnabled())))161    }162    fun checkInputType(id: Int, inputType: Int) {163        onView(withId(id)).check(matches(allOf(withInputType(inputType))))164    }165    fun checkInputTypeIsNot(id: Int, inputType: Int) {166        onView(withId(id)).check(matches(not(allOf(withInputType(inputType)))))167    }168    fun checkToast(value: String) {169        onView(withText(value)).inRoot(170            RootMatchers.withDecorView(171                Matchers.not(172                    getCurrentActivity()!!.window.decorView173                )174            )175        ).check(176            matches(177                isDisplayed()178            )179        )180    }...PageExtensions.kt
Source:PageExtensions.kt  
...58fun BasePage.onViewWithChild(arg0: Matcher<View>): ViewInteraction = Espresso.onView(ViewMatchers.withChild(arg0))59fun BasePage.onViewWithSpinnerText(arg0: String): ViewInteraction = Espresso.onView(ViewMatchers.withSpinnerText(arg0))60fun BasePage.onViewWithSpinnerText(arg0: Matcher<String>): ViewInteraction = Espresso.onView(ViewMatchers.withSpinnerText(arg0))61fun BasePage.onViewWithSpinnerText(arg0: Int): ViewInteraction = Espresso.onView(ViewMatchers.withSpinnerText(arg0))62fun BasePage.onViewWithInputType(arg0: Int): ViewInteraction = Espresso.onView(ViewMatchers.withInputType(arg0))63fun BasePage.waitForViewWithParent(arg0: Matcher<View>): ViewInteraction = WaitForViewMatcher.waitForView(ViewMatchers.withParent(arg0))64fun BasePage.waitForViewWithText(arg0: String): ViewInteraction = WaitForViewMatcher.waitForView(ViewMatchers.withText(arg0))65fun BasePage.waitForViewWithText(arg0: Matcher<String>): ViewInteraction = WaitForViewMatcher.waitForView(ViewMatchers.withText(arg0))66fun BasePage.waitForViewWithText(arg0: Int): ViewInteraction = WaitForViewMatcher.waitForView(ViewMatchers.withText(arg0))67fun BasePage.waitForViewWithId(arg0: Int): ViewInteraction = WaitForViewMatcher.waitForView(ViewMatchers.withId(arg0))68fun BasePage.waitForViewWithId(arg0: Matcher<Int>): ViewInteraction = WaitForViewMatcher.waitForView(ViewMatchers.withId(arg0))69fun BasePage.waitForViewWithClassName(arg0: Matcher<String>): ViewInteraction = WaitForViewMatcher.waitForView(ViewMatchers.withClassName(arg0))70fun BasePage.waitForViewWithContentDescription(arg0: Int): ViewInteraction = WaitForViewMatcher.waitForView(ViewMatchers.withContentDescription(arg0))71fun BasePage.waitForViewWithContentDescription(arg0: Matcher<out CharSequence>): ViewInteraction = WaitForViewMatcher.waitForView(ViewMatchers.withContentDescription(arg0))72fun BasePage.waitForViewWithContentDescription(arg0: String): ViewInteraction = WaitForViewMatcher.waitForView(ViewMatchers.withContentDescription(arg0))73fun BasePage.waitForViewWithResourceName(arg0: String): ViewInteraction = WaitForViewMatcher.waitForView(ViewMatchers.withResourceName(arg0))74fun BasePage.waitForViewWithResourceName(arg0: Matcher<String>): ViewInteraction = WaitForViewMatcher.waitForView(ViewMatchers.withResourceName(arg0))75fun BasePage.waitForViewWithTagKey(arg0: Int, arg1: Matcher<Any>): ViewInteraction = WaitForViewMatcher.waitForView(ViewMatchers.withTagKey(arg0, arg1))76fun BasePage.waitForViewWithTagKey(arg0: Int): ViewInteraction = WaitForViewMatcher.waitForView(ViewMatchers.withTagKey(arg0))77fun BasePage.waitForViewWithTagValue(arg0: Matcher<Any>): ViewInteraction = WaitForViewMatcher.waitForView(ViewMatchers.withTagValue(arg0))78fun BasePage.waitForViewWithHint(arg0: Int): ViewInteraction = WaitForViewMatcher.waitForView(ViewMatchers.withHint(arg0))79fun BasePage.waitForViewWithHint(arg0: Matcher<String>): ViewInteraction = WaitForViewMatcher.waitForView(ViewMatchers.withHint(arg0))80fun BasePage.waitForViewWithHint(arg0: String): ViewInteraction = WaitForViewMatcher.waitForView(ViewMatchers.withHint(arg0))81fun BasePage.waitForViewWithEffectiveVisibility(arg0: ViewMatchers.Visibility): ViewInteraction = WaitForViewMatcher.waitForView(ViewMatchers.withEffectiveVisibility(arg0))82fun BasePage.waitForViewWithChild(arg0: Matcher<View>): ViewInteraction = WaitForViewMatcher.waitForView(ViewMatchers.withChild(arg0))83fun BasePage.waitForViewWithSpinnerText(arg0: String): ViewInteraction = WaitForViewMatcher.waitForView(ViewMatchers.withSpinnerText(arg0))84fun BasePage.waitForViewWithSpinnerText(arg0: Matcher<String>): ViewInteraction = WaitForViewMatcher.waitForView(ViewMatchers.withSpinnerText(arg0))85fun BasePage.waitForViewWithSpinnerText(arg0: Int): ViewInteraction = WaitForViewMatcher.waitForView(ViewMatchers.withSpinnerText(arg0))86fun BasePage.waitForViewWithInputType(arg0: Int): ViewInteraction = WaitForViewMatcher.waitForView(ViewMatchers.withInputType(arg0))87fun BasePage.getStringFromResource(stringResource: Int): String{88    val targetContext = InstrumentationRegistry.getTargetContext()89    return targetContext.resources.getString(stringResource)90}91fun BasePage.callOnClick(matcher: Matcher<View>) = ViewCallOnClick.callOnClick(matcher)92fun BasePage.scrollTo(viewId: Int) = BaristaScrollInteractions.safelyScrollTo(viewId)93fun BasePage.scrollTo(text: String) = BaristaScrollInteractions.safelyScrollTo(text)94fun BasePage.waitScrollClick(viewId: Int) {95    val view = waitForViewWithId(viewId)96    scrollTo(viewId)97    view.click()98}99fun BasePage.pause(milli: Long = 100) = BaristaSleepInteractions.sleep(milli)...DebateLoginActivityTest.kt
Source:DebateLoginActivityTest.kt  
...3import android.support.test.espresso.assertion.ViewAssertions.matches4import android.support.test.espresso.intent.Intents.intended5import android.support.test.espresso.intent.matcher.IntentMatchers.hasComponent6import android.support.test.espresso.intent.matcher.IntentMatchers.hasExtra7import android.support.test.espresso.matcher.ViewMatchers.withInputType8import android.text.InputType.TYPE_CLASS_NUMBER9import android.text.InputType.TYPE_NUMBER_VARIATION_NORMAL10import com.elpassion.android.commons.espresso.*11import com.nhaarman.mockito_kotlin.any12import com.nhaarman.mockito_kotlin.mock13import com.nhaarman.mockito_kotlin.verify14import com.nhaarman.mockito_kotlin.whenever15import io.reactivex.subjects.SingleSubject16import org.hamcrest.Matchers.allOf17import org.junit.Assert18import org.junit.Rule19import org.junit.Test20import pl.elpassion.R21import pl.elpassion.elspace.common.isDisplayedEffectively22import pl.elpassion.elspace.common.rule23import pl.elpassion.elspace.common.stubAllIntents24import pl.elpassion.elspace.dabate.details.createHttpException25import pl.elpassion.elspace.debate.DebatesRepository26import pl.elpassion.elspace.debate.DebatesRepositoryProvider27import pl.elpassion.elspace.debate.LoginCredentials28import pl.elpassion.elspace.debate.details.DebateDetailsActivity29class DebateLoginActivityTest {30    private val tokenRepo = mock<DebatesRepository>()31    private val apiSubject = SingleSubject.create<LoginCredentials>()32    private val api = mock<DebateLogin.Api>()33    @JvmField @Rule34    val intents = InitIntentsRule()35    @JvmField @Rule36    val rule = rule<DebateLoginActivity> {37        whenever(tokenRepo.hasLoginCredentials(any())).thenReturn(false)38        DebatesRepositoryProvider.override = { tokenRepo }39        DebateLogin.ApiProvider.override = { api.apply { whenever(login(any())).thenReturn(apiSubject) } }40    }41    @Test42    fun shouldShowToolbarWithCorrectTitle() {43        onId(R.id.toolbar)44                .isDisplayed()45                .hasChildWithText(R.string.debate_title)46    }47    @Test48    fun shouldShowToolbarWithBackArrow() {49        onToolbarBackArrow().isDisplayed()50    }51    @Test52    fun shouldExitScreenOnBackArrowClick() {53        onToolbarBackArrow().click()54        Assert.assertTrue(rule.activity.isFinishing)55    }56    @Test57    fun shouldHaveWelcomeString() {58        onText(R.string.debate_login_welcome).isDisplayed()59    }60    @Test61    fun shouldHaveCorrectDebateCodeInput() {62        Espresso.closeSoftKeyboard()63        onId(R.id.debateLoginPinInputText)64                .isDisplayed()65                .replaceText("123456")66                .hasText("12345")67                .check(matches(withInputType(TYPE_CLASS_NUMBER or TYPE_NUMBER_VARIATION_NORMAL)))68    }69    @Test70    fun shouldShowHintInLoginPinInputField() {71        onId(R.id.debateLoginPinInputText).textInputEditTextHasHint(R.string.debate_login_hint_pin)72    }73    @Test74    fun shouldUseCorrectDebateCodeOnLogin() {75        onId(R.id.debateLoginPinInputText)76                .click()77                .replaceText("12345")78        Espresso.closeSoftKeyboard()79        onId(R.id.debateLoginButton).click()80        verify(api).login("12345")81    }...AddNewRecordFromChartTest.kt
Source:AddNewRecordFromChartTest.kt  
...85        Thread.sleep(TestUtils.timeIntervalMillis)86        onView(withId(R.id.et_time_recordEdit))87                .inRoot(RootMatchers.isDialog())88                .perform(click())89                .check(ViewAssertions.matches(allOf(withInputType(InputType.TYPE_CLASS_NUMBER))))90        Thread.sleep(TestUtils.timeIntervalMillis)91        onView(withId(R.id.et_time_recordEdit))92                .inRoot(RootMatchers.isDialog())93                .perform(click())94                .perform(ViewActions.typeText("123456789"))95                .perform(ViewActions.pressBack())96        Thread.sleep(TestUtils.timeIntervalMillis)97        onView(withId(R.id.et_distance_recordEdit))98                .inRoot(RootMatchers.isDialog())99                .check(ViewAssertions.matches(isDisplayed()))100                .perform(click())101                .check(ViewAssertions.matches(allOf(withInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL + InputType.TYPE_CLASS_NUMBER))))102        Thread.sleep(TestUtils.timeIntervalMillis)103        onView(withId(R.id.et_distance_recordEdit))104                .inRoot(RootMatchers.isDialog())105                .check(ViewAssertions.matches(isDisplayed()))106                .perform(click())107                .perform(ViewActions.typeText("146"))108                .perform(ViewActions.pressBack())109        Thread.sleep(TestUtils.timeIntervalMillis)110        onView(withId(android.R.id.button1))111                .perform(click())112        onView(withId(R.id.charts_container))113                .check(ChartContainerCountAssertion(2))114        // record activity115        Thread.sleep(TestUtils.timeIntervalMillis)...RobotKit.kt
Source:RobotKit.kt  
...15import com.ditronic.securezipnotes.testutils.*16const val TESTPASSWORD = "testpassword"17// Main menu actions ----------------------------------------------------------------------18private fun main_typeMasterPassword(password: String = TESTPASSWORD) {19    Espresso.onView(ViewMatchers.withInputType(InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_PASSWORD))20            .inRoot(RootMatchers.isDialog()).perform(ViewActions.replaceText(password))21    //click_dialogOK()22    clickPasswordOkButton()23}24fun clickPasswordOkButton() {25    clickDialogOkWithoutEspresso(dialog = findPasswordDialog())26}27fun clickRenameOkButton() {28    clickDialogOkWithoutEspresso(dialog = findRenameDialog())29}30fun findPasswordDialog(): PwDialog {31    val activity = getCurrentActivity() as FragmentActivity32    return activity.supportFragmentManager.findFragmentByTag(PwDialog.TAG.value) as PwDialog33}...AddNewRecordFromListTest.kt
Source:AddNewRecordFromListTest.kt  
...88        Thread.sleep(TestUtils.timeIntervalMillis)89        onView(withId(R.id.et_time_recordEdit))90                .inRoot(RootMatchers.isDialog())91                .perform(click())92                .check(ViewAssertions.matches(allOf(withInputType(InputType.TYPE_CLASS_NUMBER))))93        Thread.sleep(TestUtils.timeIntervalMillis)94        onView(withId(R.id.et_time_recordEdit))95                .inRoot(RootMatchers.isDialog())96                .perform(click())97                .perform(ViewActions.typeText("123456789"))98                .perform(ViewActions.pressBack())99        Thread.sleep(TestUtils.timeIntervalMillis)100        onView(withId(R.id.et_distance_recordEdit))101                .inRoot(RootMatchers.isDialog())102                .check(ViewAssertions.matches(isDisplayed()))103                .perform(click())104                .check(ViewAssertions.matches(allOf(withInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL + InputType.TYPE_CLASS_NUMBER))))105        Thread.sleep(TestUtils.timeIntervalMillis)106        onView(withId(R.id.et_distance_recordEdit))107                .inRoot(RootMatchers.isDialog())108                .check(ViewAssertions.matches(isDisplayed()))109                .perform(click())110                .perform(ViewActions.typeText("146"))111                .perform(ViewActions.pressBack())112        Thread.sleep(TestUtils.timeIntervalMillis)113        onView(withId(android.R.id.button1))114                .perform(click())115        onView(withId(R.id.rv_recordsList))116                .check(RecyclerViewItemCountAssertion(1))117    }118}...NewRecordDialogTest.kt
Source:NewRecordDialogTest.kt  
...45        onView(withId(R.id.et_time_recordEdit))46                .inRoot(isDialog())47                .check(matches(isDisplayed()))48                .perform(click())49                .check(matches(allOf(withInputType(InputType.TYPE_CLASS_NUMBER))))50        Thread.sleep(TestUtils.timeIntervalMillis)51        onView(withId(R.id.et_time_recordEdit))52                .inRoot(isDialog())53                .check(matches(isDisplayed()))54                .perform(click())55                .perform(typeText("123456789"))56                .perform(pressBack())57        Thread.sleep(TestUtils.timeIntervalMillis)58        onView(withId(R.id.et_distance_recordEdit))59                .inRoot(isDialog())60                .check(matches(isDisplayed()))61                .perform(click())62                .check(matches(allOf(withInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL + InputType.TYPE_CLASS_NUMBER))))63        Log.d("asd", "1")64        Thread.sleep(TestUtils.timeIntervalMillis)65        onView(withId(R.id.et_distance_recordEdit))66                .inRoot(isDialog())67                .check(matches(isDisplayed()))68                .perform(click())69                .perform(typeText("146"))70                .perform(pressBack())71    }72}...ExampleLoginVCEspressoTest.kt
Source:ExampleLoginVCEspressoTest.kt  
...3import android.support.test.espresso.Espresso.onView4import android.support.test.espresso.IdlingResource5import android.support.test.espresso.action.ViewActions.click6import android.support.test.espresso.action.ViewActions.typeText7import android.support.test.espresso.matcher.ViewMatchers.withInputType8import android.support.test.espresso.matcher.ViewMatchers.withText9import android.support.test.filters.LargeTest10import android.support.test.rule.ActivityTestRule11import android.support.test.runner.AndroidJUnit412import com.lightningkite.kotlin.anko.FullInputType13import com.lightningkite.kotlin.async.Async14import org.junit.After15import org.junit.Before16import org.junit.Rule17import org.junit.Test18import org.junit.runner.RunWith19/**20 *21 * Created by joseph on 11/3/17.22 */23@RunWith(value = AndroidJUnit4::class)24@LargeTest25class ExampleLoginVCEspressoTest {26    init {27        MainActivity.main = MainVC().apply {28            stack.root()29            stack.push(ExampleLoginVC({ loginData = it; stack.pop() }))30        }31    }32    @Rule33    @JvmField34    val activityRule = ActivityTestRule(MainActivity::class.java)35    var loginData: LoginData? = null36    val asyncIdlingResource = object : IdlingResource {37        var callback: IdlingResource.ResourceCallback? = null38        override fun getName(): String = "Async"39        override fun isIdleNow(): Boolean {40            val idle = Async.threadPool.activeCount == 041            if (idle) {42                callback?.onTransitionToIdle()43            }44            return idle45        }46        override fun registerIdleTransitionCallback(callback: IdlingResource.ResourceCallback?) {47            this.callback = callback48        }49    }50    @Before51    fun before() {52        Espresso.registerIdlingResources(asyncIdlingResource)53    }54    @After55    fun after() {56        Espresso.unregisterIdlingResources(asyncIdlingResource)57    }58    @Test59    fun testLogin() {60        loginData = null61        onView(withInputType(FullInputType.EMAIL))62                .perform(click())63                .perform(typeText("test@gmail.com"))64        onView(withInputType(FullInputType.PASSWORD))65                .perform(click())66                .perform(typeText("testpass"))67        onView(withText(R.string.log_in))68                .perform(click())69        assert(MainActivity.main.stack.size == 1)70        assert(loginData != null)71    }72}...withInputType
Using AI Code Generation
1ViewInteraction appCompatEditText2 = onView(2allOf(withId(R.id.editText2), isDisplayed()));3appCompatEditText2.perform(replaceText("10"), closeSoftKeyboard());4ViewInteraction appCompatButton2 = onView(5allOf(withId(R.id.button2), withText("Add"), isDisplayed()));6appCompatButton2.perform(click());7ViewInteraction appCompatEditText3 = onView(8allOf(withId(R.id.editText3), isDisplayed()));9appCompatEditText3.perform(replaceText("20"), closeSoftKeyboard());10ViewInteraction appCompatButton3 = onView(11allOf(withId(R.id.button3), withText("Subtract"), isDisplayed()));12appCompatButton3.perform(click());13ViewInteraction appCompatEditText4 = onView(14allOf(withId(R.id.editText4), isDisplayed()));15appCompatEditText4.perform(replaceText("5"), closeSoftKeyboard());16ViewInteraction appCompatButton4 = onView(17allOf(withId(R.id.button4), withText("Multiply"), isDisplayed()));18appCompatButton4.perform(click());19ViewInteraction appCompatEditText5 = onView(20allOf(withId(R.id.editText5), isDisplayed()));21appCompatEditText5.perform(replaceText("2"), closeSoftKeyboard());22ViewInteraction appCompatButton5 = onView(23allOf(withId(R.id.button5), withText("Divide"), isDisplayed()));24appCompatButton5.perform(click());25ViewInteraction appCompatButton6 = onView(26allOf(withId(R.id.button6), withText("Clear"), isDisplayed()));27appCompatButton6.perform(click());28ViewInteraction appCompatEditText2 = onView(29allOf(withId(R.id.editText2), isDisplayed()));30appCompatEditText2.perform(replaceText("10"), closeSoftKeyboard());31ViewInteraction appCompatButton2 = onView(32allOf(withId(R.id.button2), withText("Add"), isDisplayed()));33appCompatButton2.perform(click());34ViewInteraction appCompatEditText3 = onView(35allOf(withId(R.id.editText3), isDisplayed()));36appCompatEditText3.perform(replaceText("20"), closeSoftKeyboard());37ViewInteraction appCompatButton3 = onView(38allOf(withId(R.id.button3), withText("Subtract"), isDisplayed()));39appCompatButton3.perform(click());40ViewInteraction appCompatEditText4 = onView(41allOf(withId(R.id.editText4), isDisplayed()));42appCompatEditText4.perform(replaceText("5"), closeSoftKeyboard());withInputType
Using AI Code Generation
1@Rule public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule(MainActivity.class); @Test public void testWithInputType() { onView(withId(R.id.editText)).perform(typeText("Hello")).check(matches(withInputType(InputType.TYPE_CLASS_TEXT))); }2@Rule public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule(MainActivity.class); @Test public void testWithInputType() { onView(withId(R.id.editText)).perform(typeText("Hello")).check(matches(withInputType(InputType.TYPE_CLASS_TEXT))); }3@Rule public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule(MainActivity.class); @Test public void testWithInputType() { onView(withId(R.id.editText)).perform(typeText("Hello")).check(matches(withInputType(InputType.TYPE_CLASS_TEXT))); }4@Rule public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule(MainActivity.class); @Test public void testWithInputType() { onView(withId(R.id.editText)).perform(typeText("Hello")).check(matches(withInputType(InputType.TYPE_CLASS_TEXT))); }5@Rule public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule(MainActivity.class); @Test public void testWithInputType() { onView(withId(R.id.editText)).perform(typeText("Hello")).check(matches(withInputType(InputType.TYPE_CLASS_TEXT))); }6@Rule public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule(MainActivity.class); @Test public void testWithInputType() { onView(withId(R.id.editText)).perform(typeText("Hello")).check(matches(withInputType(InputType.TYPE_CLASS_TEXT))); }7@Rule public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule(MainActivity.class); @Test public void testWithInputType() { onView(withId(R.id.editText)).perform(typeText("Hello")).check(matches(withInputType(InputType.TYPE_CLASS_TEXT))); }withInputType
Using AI Code Generation
1onView(withId(R.id.editText)).perform(typeText("text"), closeSoftKeyboard());2onView(withId(R.id.editText)).perform(typeText("text"), closeSoftKeyboard());3onView(withId(R.id.editText)).perform(typeText("text"), closeSoftKeyboard());4onView(withId(R.id.editText)).perform(typeText("text"), closeSoftKeyboard());5onView(withId(R.id.editText)).perform(typeText("text"), closeSoftKeyboard());6onView(withId(R.id.editText)).perform(typeText("text"), closeSoftKeyboard());7onView(withId(R.id.editText)).perform(typeText("text"), closeSoftKeyboard());8onView(withId(R.id.editText)).perform(typeText("text"), closeSoftKeyboard());9onView(withId(R.id.editText)).perform(typeText("text"), closeSoftKeyboard());10onView(withId(R.id.editText)).perform(typeText("text"), closeSoftKeyboard());11onView(withId(R.id.editText)).perform(typeText("text"), closeSoftKeyboard());12onView(withId(R.id.editText)).perform(typeText("text"), closeSoftKeyboard());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!!
