Espresso - typeText not working

前端 未结 10 1063
名媛妹妹
名媛妹妹 2021-02-13 22:20

I\'m trying to type some text inside an EditText:


    public void testSearch() {
          onView(withId(R.id.titleInput)).perform(typeText(\"Engineer\"));
          


        
相关标签:
10条回答
  • 2021-02-13 22:37

    Had the same issue using Espresso 2. As a workaround I'm using replaceText instead of typeText.

    public void testSearch() {
          onView(withId(R.id.titleInput)).perform(click(), replaceText("Engineer"));
          onView(withId(R.id.titleInput)).check(matches(withText("Engineer")));
    }
    
    0 讨论(0)
  • 2021-02-13 22:42

    You can bypass the problem by calling setText on the EditText.

       final EditText titleInput = (EditText) activity.findViewById(R.id.titleInput);
       getInstrumentation().runOnMainSync(new Runnable() {
            public void run() {
                titleInput.setText("Engineer");
            }
        });
    
    0 讨论(0)
  • 2021-02-13 22:43

    You can include it with in the code like this,

    onView(withId(R.id.titleInput))
         .perform(click(), replaceText("Engineer"), closeSoftKeyboard());
    
    0 讨论(0)
  • 2021-02-13 22:49

    for me I was annotated my test method with @UiThreadTest. I removed that and it solved.

    0 讨论(0)
提交回复
热议问题