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

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

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

public UiAutomatorHelper(String jarName, String testClass, String testName, String androidId, String devicesId) {
		System.out.println("-----------start--uiautomator--debug-------------");
		workspace_path = getWorkSpase();
		System.out.println("----工做空间:\t\n" + getWorkSpase());
 
		jar_name = jarName;
		test_class = testClass;
		test_name = testName;
		android_id = androidId;
		devices = devicesId;
		runUiautomator();
		System.out.println("*******************");
		System.out.println("---FINISH DEBUG----");
		System.out.println("*******************");
	}

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

// 4---push jar
	public void pushTestJar(String localPath) {
		localPath = "\"" + localPath + "\"";
		System.out.println("----jar包路径: " + localPath);
		String pushCmd = "adb -s "+devices+" push " + localPath + " /data/local/tmp/";
		System.out.println("----" + pushCmd);
		execCmd(pushCmd);
	}
 
	// 运行测试
	public void runTest(String jarName, String testName) {
		String runCmd = "adb -s "+devices+" shell uiautomator runtest ";//此处-s表示机器
		String testCmd = jarName + ".jar " + "--nohup -c " + testName;
		System.out.println("----runTest:  " + runCmd + testCmd);
		execCmd(runCmd + testCmd);
	}

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

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

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

技术类文章精选

  1. java一行代码打印心形
  2. Linux性能监控软件netdata中文汉化版
  3. 接口测试代码覆盖率(jacoco)方案分享
  4. 性能测试框架
  5. 如何在Linux命令行界面愉快进行性能测试
  6. 图解HTTP脑图
  7. 如何测试几率型业务接口
  8. httpclient处理多用户同时在线
  9. 将swagger文档自动变成测试代码
  10. 五行代码构建静态博客
  11. httpclient如何处理302重定向
  12. 基于java的直线型接口测试框架初探
  13. Tcloud 云测平台--集大成者
  14. 如何测试几率型业务接口
  15. Android App 测试工具及知识大集合

非技术文章精选

  1. 为何选择软件测试做为职业道路?
  2. 成为杰出Java开发人员的10个步骤
  3. 写给全部人的编程思惟
  4. 自动化测试的障碍
  5. 自动化测试的问题所在
  6. 测试之《代码不朽》脑图
  7. 成为优秀自动化测试工程师的7个步骤
  8. 优秀软件开发人员的态度
  9. 如何正确执行功能API测试
  10. 将来10年软件测试的新趋势-上
  11. 将来10年软件测试的新趋势-上
  12. 自动化测试解决了什么问题
  13. 17种软件测试人员经常使用的高效技能-上
  14. 17种软件测试人员经常使用的高效技能-下

大咖风采

  1. Tcloud 云测平台--集大成者
  2. Android App 测试工具及知识大集合

点击查看公众号地图

相关文章
相关标签/搜索