Updating an EditText with Espresso

前端 未结 5 1526
慢半拍i
慢半拍i 2020-12-30 19:00

I\'m attempting to update an EditText as part of an Espresso test with:

onView(allOf(withClassName(endsWith(\"EditText\")), withText(is(\"Test\"         


        
5条回答
  •  一整个雨季
    2020-12-30 19:47

    Three things to try:

    1. You can run performs in succession.

    onView(...)
        .perform(clearText(), typeText("Some Text"));
    

    2. There is a recorded issue on the Espresso page which was marked as invalid (but is still very much a bug). A workaround for this is to pause the test in-between performs.

    public void test01(){
        onView(...).perform(clearText(), typeText("Some Text"));
        pauseTestFor(500);
        onView(...).perform(clearText(), typeText("Some Text"));
    }
    
    private void pauseTestFor(long milliseconds) {
        try {
            Thread.sleep(milliseconds);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    

    3. Are you absolutely sure that your EditText contains the text, "Test"?

提交回复
热议问题