雾山的Robotium学习笔记---CheckBox,RadioGroup&RadioButton的测试方法及结果判定
2014-05-19 16:10
459 查看
在Android中,CheckBox和RadioButton是很常见的控件,那怎样用Robotium对该空间进行测试呢;
我们在Robotium的API文档的solo类中可以看到以下两种方法,通过CheckBox和RadioButton的index值来找到该控件:
当然也可以通过button的text值来直接调用。(CheckBox和RadioButton都是Button的子类):
而判定按钮有没有选择可以调用以下的方法:
isCheckBoxChecked()和isRadioButtonChecked()
下面是代码:
点我下载源码
我们在Robotium的API文档的solo类中可以看到以下两种方法,通过CheckBox和RadioButton的index值来找到该控件:
public void clickOnCheckBox(int index) Clicks a CheckBox matching the specified index. Parameters: index - the index of the CheckBox to click. 0 if only one is available
public void clickOnRadioButton(int index) Clicks a RadioButton matching the specified index. Parameters: index - the index of the RadioButton to click. 0 if only one is available
当然也可以通过button的text值来直接调用。(CheckBox和RadioButton都是Button的子类):
public void clickOnButton(String text) Clicks a Button displaying the specified text. Will automatically scroll when needed. Parameters: text - the text displayed by the Button. The parameter will be interpreted as a regular expression
而判定按钮有没有选择可以调用以下的方法:
isCheckBoxChecked()和isRadioButtonChecked()
下面是代码:
package com.tangbc.choosedemo.test; import org.junit.Test; import android.test.ActivityInstrumentationTestCase2; import com.robotium.solo.Solo; import com.tangbc.choosedemo.MainActivity; public class ChooseTest extends ActivityInstrumentationTestCase2{ private Solo solo; public ChooseTest() { super(MainActivity.class); } @Override protected void setUp() throws Exception { solo = new Solo(getInstrumentation(), getActivity()); } @Override protected void tearDown() throws Exception { solo.finishOpenedActivities(); } @Test public void test() { //直接调用名称或CheckBox的index都可以找到该控件 solo.clickOnButton("WOW"); //调用isCheckBoxChecked(int index)方法,判断WOW按钮有没有被选中 boolean expected = true; boolean actual = solo.isCheckBoxChecked(0); assertEquals("WOW没有被选中", expected, actual); for(int i = 0; i < 10; i++){ solo.clickOnCheckBox(1); solo.clickOnCheckBox(1); solo.takeScreenshot(); solo.sleep(2000); } } public void test1(){ //直接调用clickOnButton的名称或clickOnRadioButton的index都可以找到该控件 solo.clickOnRadioButton(0); //调用isRadioButtonChecked(int index)方法,判断boy按钮有没有被选中 boolean BoyExpected = true; boolean BoyActual = solo.isRadioButtonChecked(0); assertEquals("boy没被选中", BoyExpected, BoyActual); solo.clickOnButton("girl"); boolean GirlExpected = true; boolean GirlActual = solo.isRadioButtonChecked(1); System.out.println(GirlActual); assertEquals("girl没被选中", GirlExpected, GirlActual); solo.takeScreenshot(); solo.sleep(2000); } }
点我下载源码
相关文章推荐
- 雾山的Robotium学习笔记---CheckBox,RadioGroup&RadioButton的测试方法及结果判定 .
- 雾山的Anrdoid学习笔记---CheckBox,RadioGroup&RadioButton
- 雾山的Anrdoid学习笔记---CheckBox,RadioGroup&RadioButton .
- 【Android学习笔记】RadioGroup,RadioButton的使用&CheckBox的使用
- flex 入门学习笔记3 之RadioButton和RadioButtonGroup
- 雾山的Robotium学习笔记---使用junitreport导出测试报告
- android开发学习笔记——稍复杂控件 RadioGroup,CheckBox,Toast
- 雾山的Robotium学习笔记---Robotium针对apk包的测试
- 【幻化万千戏红尘】qianfeng-Android-Day03-RadioButton及RadioGroup的用法、CheckBox、ProgressBar基础学习:
- RadioGroup、RadioButton以及Spinner学习笔记
- 雾山的Robotium学习笔记---Robotium针对apk包的测试
- RadioGroup、RadioButton(单选按钮)、CheckBox(多选按钮)和Toast的使用方法
- RadioGroup的RadioButton简单用法——学习笔记
- RadioButton和CheckBox的区别,RadioButton&RadioGroup
- Android开发学习笔记:RadioButton和CheckBox浅析
- 持续集成学习笔记-入门篇(9)团队管理:成员&权限设置、成果追踪与结果通知
- Android自动化测试框架Robotium学习笔记
- Android开发--控件之RadioGroup、RadioButton、CheckBox、Toast
- Android学习指南之九:Button、TextView、EditView、CheckBox、RadioGroup、ImageView、ImageButton
- Android 应用开发笔记 - 单项选择(RadioGroup, RadioButton)