UiAutoMator报告查看
原创
©著作权归作者所有:来自51CTO博客作者wx5ba8dc11102bc的原创作品,请联系作者获取转载授权,否则将追究法律责任
- 断言错误:AssertionFailedError
- 脚本错误:UiObjectNotFoundException、Java异常等
运行状态
| | 结果状态
| | 运行信息
|
1
| 运行前
| 0
| Ok
| 运行前信息
|
-1
| 运行完成
| -1
| Errors 脚本错误
| 运行中信息
|
| | -2
| Failures 断言错误
| 运行后信息
|
- numtests 运行的所有用例数量
- stream 信息流与错误流
- id 运行框架
- test 用例名字
- class 用例完整类名
- current 当前运行在第几条
- CODE 状态信息
- 各种状态的报告并定位问题:
/**
* 断言失败
* @throws UiObjectNotFoundException
*/
public void testMsm() throws UiObjectNotFoundException {
UiDevice uiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
UiObject uiObject = new UiObject(new UiSelector().text("信息"));
UiObject uiObject1 = new UiObject(new UiSelector().text("无信息"));
uiObject.clickAndWaitForNewWindow();
assertTrue(!uiObject1.exists());
}
/**
* 脚本失败
* @throws UiObjectNotFoundException
*/
public void testScript() throws UiObjectNotFoundException {
UiDevice uiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
UiObject uiObject = new UiObject(new UiSelector().text("1信息"));
UiObject uiObject1 = new UiObject(new UiSelector().text("无"));
uiObject.clickAndWaitForNewWindow();
assertTrue(!uiObject1.exists());
}
- 只有断言失败表现.F, 只有脚本失败表现.E,两者都有.F.E
- 输出自己的信息到报告中:
- setUp主要用于开始初始化工作
- tearDown主要用于收尾
- Bundle
- getAutomationSupport().sendStatus(int x, Bundle bundle)
- 此处的Bundle包含很多的键值对的集合,和Android中的一致
public class SelfTest extends TestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
System.out.println("SetUp调用了");
Bundle bundle = new Bundle();
bundle.putString("key1","value1");
bundle.putString("key2","value2");
bundle.putString("key3","value3");
bundle.putString("key4","value4");
bundle.putString("key5","value5");
//发送状态,注意不能跟系统状态码一样(0,1,-1),这里我们用10
// getAutomationSupport().sendStatus(10, bundle);
}
public void testSetup(){
System.out.println("用例调用了");
Bundle bundle = new Bundle();
bundle.putString("key1","value1");
bundle.putString("key2","value2");
bundle.putString("key3","value3");
bundle.putString("key4","value4");
bundle.putString("key5","value5");
// getAutomationSupport().sendStatus(11, bundle);
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
System.out.println("tearDown用例完成了");
Bundle bundle = new Bundle();
bundle.putString("key1","value1");
bundle.putString("key2","value2");
bundle.putString("key3","value3");
bundle.putString("key4","value4");
bundle.putString("key5","value5");
// getAutomationSupport().sendStatus(12, bundle);
}
/**
* 通过-e传参拨打电话
*/
public void testCall() throws UiObjectNotFoundException {
UiDevice uiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
uiDevice.pressBack();
uiDevice.pressBack();
uiDevice.pressBack();
UiObject uiObject = new UiObject(new UiSelector().text("电话"));
uiObject.clickAndWaitForNewWindow();
//从命令行获取数据
Bundle bundle = new Bundle();
//命令行中的参数 -e key value 10010
String phone = (String)bundle.get("phone");
Scanner input = new Scanner(System.in);
System.out.println("号码");
phone = input.nextLine();
for(int i = 0;i<phone.length();i++){
String c = phone.charAt(i)+"";
UiObject phoneNum = new UiObject(new UiSelector().text(c));
phoneNum.click();
sleep(1000);
}
}