Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable auto-correct functionality in Espresso test

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?

like image 682
arne.z Avatar asked Aug 24 '18 14:08

arne.z


1 Answers

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.

like image 159
Lee Kang Avatar answered Oct 15 '22 11:10

Lee Kang