Getting started with Robotium. EditText not found

坚强是说给别人听的谎言 提交于 2019-12-20 05:30:10

问题


I just getting started with Robotium, writing my first test and I'm getting this weird error:

junit.framework.AssertionFailedError: 2131165500 EditTexts are not found!

This is my my test case

public class TestRegistrationActivity extends ActivityInstrumentationTestCase2<RegistrationActivity>{

    private Solo solo;

    public TestRegistrationActivity() {
        super(RegistrationActivity.class);
    }

    public void setUp() throws Exception {
        solo = new Solo(getInstrumentation(), getActivity());
    }


    @Override
    public void tearDown() throws Exception {
        solo.finishOpenedActivities();
    }

    @UiThreadTest
    public void testSomeStuff(){
        for (View v : solo.getCurrentViews()) {
            Log.d(v.getClass().getSimpleName()+": "+v.getId());             
        }

        solo.getEditText(R.id.txtCountryCode);
    }
}

And this is the log:

03-13 17:06:18.318: D/DEBUG(7907): EditText: 2131165500  
03-13 17:06:18.322: D/DEBUG(7907): PhoneEditText: 2131165501

As you can see:

  1. The solo.getCurrentViews() does indeed recognize that the view with id 2131165500 exists.
  2. The solo.getEditText(R.id.txtCountryCode) line always fails.

What could be wrong?


回答1:


Fixed.

The problem was that I thought solo.getEditText(int) took a View id as parameter. Instead it took the view's index.



来源:https://stackoverflow.com/questions/22392654/getting-started-with-robotium-edittext-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!