UiAutoMator报告查看

  • 报告的简介以及查看

  • 错误的类型:

    • 断言错误:AssertionFailedError
    • 脚本错误:UiObjectNotFoundException、Java异常等
  • 报告状态:

    • 运行状态
    • 结果状态
    • 运行状态
运行状态结果状态运行信息
1运行前0Ok运行前信息
-1运行完成-1Errors 脚本错误运行中信息
-2Failures 断言错误运行后信息

b013e958225cf5638ba18a1af4756281.png

  • 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函数
      • setUp主要用于开始初始化工作
      • tearDown主要用于收尾
  • 输出信息API

    • 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);
        }
    }




  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

wjxbless

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值