雾山的Robotium学习笔记---CheckBox,RadioGroup&RadioButton的测试方法及结果判定 .

在Android中,CheckBox和RadioButton是很常见的控件,那怎样用Robotium对该空间进行测试呢;

我们在Robotium的API文档的solo类中可以看到以下两种方法,通过CheckBox和RadioButton的index值来找到该控件

  1. public void clickOnCheckBox(int index)  
  2. Clicks a CheckBox matching the specified index.  
  3. Parameters:  
  4. index - the index of the CheckBox to click. 0 if only one is available  
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
  1. public void clickOnRadioButton(int index)  
  2. Clicks a RadioButton matching the specified index.  
  3. Parameters:  
  4. index - the index of the RadioButton 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的子类):

  1. public void clickOnButton(String text)  
  2. Clicks a Button displaying the specified text. Will automatically scroll when needed.  
  3. Parameters:  
  4. text - the text displayed by the Button. The parameter will be interpreted as a regular expression  
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()


下面是代码:

  1. package com.tangbc.choosedemo.test;  
  2.   
  3. import org.junit.Test;  
  4.   
  5. import android.test.ActivityInstrumentationTestCase2;  
  6.   
  7. import com.robotium.solo.Solo;  
  8. import com.tangbc.choosedemo.MainActivity;  
  9.   
  10. public class ChooseTest extends ActivityInstrumentationTestCase2{  
  11.     private Solo solo;  
  12.   
  13.     public ChooseTest() {  
  14.         super(MainActivity.class);  
  15.     }  
  16.   
  17.     @Override  
  18.     protected void setUp() throws Exception {  
  19.         solo = new Solo(getInstrumentation(), getActivity());  
  20.     }  
  21.   
  22.     @Override  
  23.     protected void tearDown() throws Exception {  
  24.         solo.finishOpenedActivities();  
  25.     }  
  26.   
  27.     @Test  
  28.     public void test() {  
  29.         //直接调用名称或CheckBox的index都可以找到该控件   
  30.         solo.clickOnButton("WOW");  
  31.         //调用isCheckBoxChecked(int index)方法,判断WOW按钮有没有被选中   
  32.         boolean expected = true;  
  33.         boolean actual = solo.isCheckBoxChecked(0);  
  34.         assertEquals("WOW没有被选中", expected, actual);  
  35.   
  36.           
  37.         for(int i = 0; i < 10; i++){  
  38.             solo.clickOnCheckBox(1);  
  39.             solo.clickOnCheckBox(1);  
  40.             solo.takeScreenshot();  
  41.             solo.sleep(2000);  
  42.         }  
  43.     }  
  44.       
  45.     public void test1(){  
  46.         //直接调用clickOnButton的名称或clickOnRadioButton的index都可以找到该控件   
  47.         solo.clickOnRadioButton(0);  
  48.         //调用isRadioButtonChecked(int index)方法,判断boy按钮有没有被选中   
  49.         boolean BoyExpected = true;  
  50.         boolean BoyActual = solo.isRadioButtonChecked(0);  
  51.         assertEquals("boy没被选中", BoyExpected, BoyActual);  
  52.           
  53.         solo.clickOnButton("girl");  
  54.         boolean GirlExpected = true;  
  55.         boolean GirlActual = solo.isRadioButtonChecked(1);  
  56.         System.out.println(GirlActual);  
  57.         assertEquals("girl没被选中", GirlExpected, GirlActual);  
  58.           
  59.         solo.takeScreenshot();  
  60.         solo.sleep(2000);  
  61.     }  
  62.   
  63. }  
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);
	}

}

点我下载源码
【从高压输电线的架空地线中汲取电能】一个25千瓦受控电源从735千伏线路的架空地线中汲取电能的SimPowerSystems模型(Simulink仿真实现)内容概要:本文介绍了一个基于SimPowerSystems的Simulink仿真模型,用于模拟从735千伏高压输电线的架空地线中汲取25千瓦电能的受控电源系统。该模型聚焦于高压输电线路中架空地线的能量回收技术,通过仿真手段实现对电能采集过程的建模与控制策略验证,体现了电力系统中新型能源获取方式的技术可行性与工程应用潜力。文中还提及该资源属于一系列电力系统仿真研究的一部分,涵盖微电网、储能优化、碳流追踪、鲁棒调度等多个前沿方向,配套提供Matlab/Simulink代码及网盘资料链接,便于科研人员复现与拓展研究。; 适合人群:具备电力系统基础知识、熟悉Matlab/Simulink仿真环境,从事电力工程、能源回收或智能电网相关研究的科研人员及研究生;有一定编程与建模仿真经验的高年级本科生或工程技术人员。; 使用场景及目标:①研究高压输电线路中架空地线的能量回收机制与建模方法;②掌握基于Simulink的电力系统仿真技术,特别是受控电源与电网交互的动态特性分析;③为开展能源 harvesting、分布式供能、电力电子变换器控制等相关课题提供参考模型与技术支撑; 阅读建议:建议结合提供的仿真模型文件进行实操演练,重点理解系统结构设计、参数设置与控制逻辑实现;同时可延伸学习文档中提到的其他电力系统优化与仿真案例,以拓宽研究视野技术积累。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值