I wrote an Espresso test that writes some text to a TextView, performs an action and then checks whether the text in the TextView is still the same.
The test fails on one of the test devices (Huawei P20, Android 8.1.0) because the entered text is auto-corrected (from 1234 5678
to 12th 5678
). And this fails my test. The text is not auto-corrected when I manually enter the same numbers.
This is how I input the text in my Espresso test:
onView(withId(R.id.reference_value))
.perform(scrollTo(), click())
.check(matches(isDisplayed()))
.perform(typeText("1234 5678"));
closeSoftKeyboard();
I know I could just change the input text to something that won't be auto-corrected. But I would like to have a solution that generally makes sure that the entered text is not modified to something else. Ideally without having to manually change the configuration of my test device.
Do any of you guys have an idea how I could accomplish this?
One way that works for me is to use replaceText()
instead, although this still seems to be a bit of a hack.
Another option may be to disable autocorrect through some Android API call or manually through the UI like for animations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With