ITPub博客

首页 > 数据库 > 数据库开发技术 > android UiAutomator控制多台手机同时运行用例的方法

android UiAutomator控制多台手机同时运行用例的方法

原创 数据库开发技术 作者:FunTester 时间:2019-09-27 09:43:31 0 删除 编辑

本人在使用android UiAutomator的时候,有个问题一直困扰着我,使用调试类做测试,电脑只能插上一台手机,前些天偶然发现了adb命令里面有一个 -s 的参数可以区分不同的手机设备,故修改了一下快速调试类的方法,使得能够同时连上两台手机做测试了,下面分享一下主要的代码,共大家参考。

下面这个是快速调试类的运行方法,多加一个参数就可以了:

 1    public UiAutomatorHelper(String jarName, String testClass, String testName, String androidId, String devicesId) {
2        System.out.println("-----------start--uiautomator--debug-------------");
3        workspace_path = getWorkSpase();
4        System.out.println("----工作空间:\t\n" + getWorkSpase());
5
6        jar_name = jarName;
7        test_class = testClass;
8        test_name = testName;
9        android_id = androidId;
10        devices = devicesId;
11        runUiautomator();
12        System.out.println("*******************");
13        System.out.println("---FINISH DEBUG----");
14        System.out.println("*******************");
15    }

下面是push和run方法,在adb命令后面加上devices参数即可:

 1    // 4---push jar
2    public void pushTestJar(String localPath) {
3        localPath = "\"" + localPath + "\"";
4        System.out.println("----jar包路径: " + localPath);
5        String pushCmd = "adb -s "+devices+" push " + localPath + " /data/local/tmp/";
6        System.out.println("----" + pushCmd);
7        execCmd(pushCmd);
8    }
9
10    // 运行测试
11    public void runTest(String jarName, String testName) {
12        String runCmd = "adb -s "+devices+" shell uiautomator runtest ";//此处-s表示机器
13        String testCmd = jarName + ".jar " + "--nohup -c " + testName;
14        System.out.println("----runTest:  " + runCmd + testCmd);
15        execCmd(runCmd + testCmd);
16    }

下面是要调试类中的使用方法,也是加一个参数即可,将来肯定是要做一个list或者map数组和实时获取设备的devicesid的,这里比较粗糙,直接写了值。

new UiAutomatorHelper("Demo", "student.Student", "testTest", "1", NEXUS5DEVICESID);

以后打算用多线程让两台手机同时运行不同的测试用例,不过暂时没想好管理策略。

技术类文章精选

  1. java一行代码打印心形

  2. Linux性能监控软件netdata中文汉化版

  3. 接口测试代码覆盖率(jacoco)方案分享

  4. 性能测试框架

  5. 如何在Linux命令行界面愉快进行性能测试

  6. 图解HTTP脑图

  7. 将swagger文档自动变成测试代码

  8. 五行代码构建静态博客

  9. 基于java的直线型接口测试框架初探

非技术文章精选

  1. 为什么选择软件测试作为职业道路?

  2. 写给所有人的编程思维

  3. 自动化测试的障碍

  4. 自动化测试的问题所在

  5. 成为优秀自动化测试工程师的7个步骤

  6. 未来10年软件测试的新趋势-上

  7. 未来10年软件测试的新趋势-上

  8. 17种软件测试人员常用的高效技能-上

  9. 17种软件测试人员常用的高效技能-下

大咖风采

  1. Tcloud 云测平台--集大成者

  2. Android App 测试工具及知识大集合

点击查看公众号地图

原文作者:FunTester;如有侵权,请联系管理员删除。

下一篇: 公众号地图
请登录后发表评论 登录
全部评论

注册时间:2019-07-07

  • 博文量
    1037
  • 访问量
    420693