Android自动化测试 Robotium(2)初识

发表于:2015-8-19 10:04

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:小毛子    来源:51Testing软件测试网采编

  花了一点时间写了一个计算标准体重的小应用,当然目的是为了测试 robotium 的使用情况。经过一段泡在robotium的API文档上,对一些基本操作也有所了解,开始了更进一步的尝试。
  robotium API:http://code.google.com/p/robotium/downloads/list
  虽然API文档已经把相关知识点解释的很全,作为学习还需不断使用理解巩固知识
  以下先简单介绍一部分API
// 单击一个单选按钮
clickOnRadioButton(int index)
index:用来标识哪个RadioButton, 只有1个RadioButton,index = 0 以此类推
// 单击一个EditText表单
clickOnEditText(int index)
index: 用来标识哪个EditText,只有1个EditText, index = 0 以此类推
// 在EditText中输入Text
enterText(int index, String text)
index: 用来标识哪个EditText
text : 输入的内容
// 单击一个按钮
clickOnButton(String name)
name : 按钮的名称
// 返回上一页
goBack()
// 清空EditText表单
clearEditText(int index)
index: 用来标识哪个EditText
package com.luwenjie.standweight.test;
import android.test.ActivityInstrumentationTestCase2;
import com.luwenjie.standweight.StandWeightActivity;
import com.jayway.android.robotium.solo.Solo;
public class weightText extends ActivityInstrumentationTestCase2<StandWeightActivity> {
private Solo solo;
public weightText() {
super("com.luwenjie.standweight", StandWeightActivity.class);
}
public void setUp() throws Exception{
solo = new Solo(getInstrumentation(), getActivity());
}
public void testUI() throws Exception {
boolean expected = true;
//验证男孩180cm的标准体重为70公斤
solo.clickOnRadioButton(0);
solo.clickOnEditText(0);
solo.enterText(0, "180");
solo.clickOnButton("计算");
boolean actual1 = solo.searchText("70.00");
assertEquals("This and/or is are not found", expected, actual1);
//返回清空editText表单
solo.goBack();
solo.clearEditText(0);
//验证女孩160cm的标准体重为70公斤
solo.clickOnRadioButton(1);
solo.clickOnEditText(0);
solo.enterText(0, "160");
solo.clickOnButton("计算");
boolean actual2 = solo.searchText("54.00");
assertEquals("This and/or is are not found", expected, actual2);
}
}
相关文章
Android自动化测试 Robotium(1)环境
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号