您的位置:首页 > 其它

雾山的Robotium学习笔记---通过Id寻找控件 .

2014-07-04 14:48 423 查看
在自动化测试中,UI上经常有一些控件是没有名称的,那么此时,就可以通过id来找到这些控件

直接上案例:

这是对两个EditText进行测试

[java]
view plaincopyprint?





package com.tangbc.tedit.test; import org.junit.After; import org.junit.Before; import org.junit.Test; import android.test.ActivityInstrumentationTestCase2; import android.view.View; import android.widget.EditText; import com.robotium.solo.Solo; import com.tangbc.tedit.MainActivity; import com.tangbc.tedit.R; public class EditTest extends ActivityInstrumentationTestCase2{ private Solo solo; public EditTest() { super(MainActivity.class); } @Before public void setUp() throws Exception { solo = new Solo(getInstrumentation(), getActivity()); } @After public void tearDown() throws Exception { solo.finishOpenedActivities(); } @Test public void test() { EditText enter = (EditText)solo.getView(R.id.enterText); solo.enterText(enter, "this is enter text"); solo.sleep(2000); int typeId = solo.getCurrentActivity().getResources().getIdentifier("typeText", "id", "com.tangbc.tedit"); View typeView = solo.getView(typeId); solo.typeText((EditText)typeView, "this is type text"); solo.sleep(2000); } }
package com.tangbc.tedit.test;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import android.test.ActivityInstrumentationTestCase2;
import android.view.View;
import android.widget.EditText;

import com.robotium.solo.Solo;
import com.tangbc.tedit.MainActivity;
import com.tangbc.tedit.R;

public class EditTest extends ActivityInstrumentationTestCase2{
private Solo solo;

public EditTest() {
super(MainActivity.class);
}

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

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

@Test
public void test() {
EditText enter = (EditText)solo.getView(R.id.enterText);
solo.enterText(enter, "this is enter text");
solo.sleep(2000);

int typeId = solo.getCurrentActivity().getResources().getIdentifier("typeText", "id", "com.tangbc.tedit");
View typeView = solo.getView(typeId);
solo.typeText((EditText)typeView, "this is type text");
solo.sleep(2000);
}

}


点我下载源码
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: