雾山的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); } }
点我下载源码
直接上案例:
这是对两个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); } }
点我下载源码
相关文章推荐
- 雾山的Robotium学习笔记---通过Id寻找控件
- Robotium--通过Id寻找控件
- 雾山的Robotium学习笔记---typeText与enterText的区别
- 雾山的Robotium学习笔记---环境搭建及入门示例
- 雾山的Robotium学习笔记---环境搭建及入门示例
- 雾山的Robotium学习笔记---CheckBox,RadioGroup&RadioButton的测试方法及结果判定
- 雾山的Robotium学习笔记---CheckBox,RadioGroup&RadioButton的测试方法及结果判定 .
- 雾山的Robotium学习笔记---scroll
- 雾山的Robotium学习笔记---scroll .
- 雾山的Robotium学习笔记---使用junitreport导出测试报告
- MFC中资源ID和具体控件之间的关系问题【学习笔记】
- 雾山的Robotium学习笔记---Ant 构建脚本
- 学习笔记找到多个具有相同 ID“_header”的控件,FindControl 要求控件具有唯一的 ID.
- 雾山的Robotium学习笔记----源码的导入 .
- Sharepoint学习笔记—ECMAScript对象模型系列-- 12、通过邮件发送带有Unique DocumentID的文档链接
- mybatis学习笔记 一对一 和一对多 以及 如何通过框架直接返回主键id
- 雾山的Robotium学习笔记---Robotium针对apk包的测试
- 雾山的Robotium学习笔记---Robotium针对apk包的测试
- 雾山的Robotium学习笔记----源码的导入
- 雾山的Anrdoid学习笔记---CheckBox,RadioGroup&RadioButton