Robotium处理跨进程的问题

发表于:2015-8-12 10:05

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:xuxu    来源:51Testing软件测试网采编

  先贴上年前的两个帖子:
  @qinggchu http://testerhome.com/topics/1826
  @yangchengtest http://testerhome.com/topics/1876
  Adb-For-Test
  https://github.com/gb112211/Adb-For-Test
  用在robotium中去处理跨进程的时候还有坑没填上,主要就是权限问题,这里可以看下@qinggchu的这篇博客http://blog.csdn.net/qingchunjun/article/details/43343735
  robotium中使用uiautomator命令获取uidump.xml的时候是需要root权限才能获取到的,所以在跨进程时,要通过解析uidump.xml去定位元素位置的时候,就需要使用root过的真机才行,关键需要使用su命令。
  参考@qinggchu修改的例子,年后回来就花了点时间修改了下Adb-For-Test,Adb-For-Robotium,简单测试了下,基本上可以满足需求,例子中有一个执行robotium脚本时录制的视频。
  主要修改的地方就是获取uidump.xml,原谅我去解析的时候先是用的cat命令
// 获取设备当前界面的控件信息,并解析uidump.xml文件
private void uidump() {
ShellUtils.suShell("uiautomator dump /data/local/tmp/uidump.xml");
sleep(2000);
ShellUtils.suShell("chmod 777 /data/local/tmp/uidump.xml");
sleep(2000);
try {
xml = ShellUtils.StringTOInputStream(ShellUtils
.getShellOut(ShellUtils
.shell("cat /data/local/tmp/uidump.xml")));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
dumps = new UiDumpService().getDumps(xml);
}
//需要root权限执行命令时使用该方法
public static void suShell(String cmd) {
Process ps = null;
DataOutputStream os;
try {
ps = Runtime.getRuntime().exec("su");
os = new DataOutputStream(ps.getOutputStream());
os.writeBytes(cmd + "\n");
os.writeBytes("exit\n");
os.flush();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static InputStream StringTOInputStream(String in) throws Exception {
ByteArrayInputStream is = new ByteArrayInputStream(in.getBytes("ISO-8859-1"));
return is;
}
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号