Appium实现截图和清空EditText

发表于:2015-6-30 11:36

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

 作者:to be crazy    来源:51Testing软件测试网采编

  adb基本命令总结(Android Debug Bridge)
  adb 是PC和设备连接的桥梁,可以通过adb对devices进行相关操作
  adb devices           列出你的devices
  adb kill-server         杀掉adb服务(如果设备连接出问题,可尝试)
  adb start-server      重启adb服务
  adb shell                进入默认device的Linux shell,可以直接执行Linux命令
  adb shell screenrecord /sdcard/runCase.mp4  录制视频保存,默认3min,也可以加--time-limit 60限制时间
  adb install jd.apk      向设备安装app
  adb pull /sdcard/runCase.mp4 c:// 把手机中文件copy到电脑
  adb push C://runCase.mp4 /sdcard/          把电脑中文件放到手机
  以上就是一些基本的adb 命令
  appium实现截图
  由于我有webdriver 的基础,理解起来比较easy,appium截图实际是继承webdriver的
  selenium 中使用的是TakesScreenShot接口getScreenShotAs方法,具体实现如下
1 /**
2      * This Method create for take screenshot
3      *
4      * @author Young
5      * @param drivername
6      * @param filename
7      */
8     public static void snapshot(TakesScreenshot drivername, String filename) {
9         // this method will take screen shot ,require two parameters ,one is
10         // driver name, another is file name
11
12         String currentPath = System.getProperty("user.dir"); // get current work
13                                                                 // folder
14         File scrFile = drivername.getScreenshotAs(OutputType.FILE);
15         // Now you can do whatever you need to do with it, for example copy
16         // somewhere
17         try {
18             System.out.println("save snapshot path is:" + currentPath + "/"
19                     + filename);
20             FileUtils
21                     .copyFile(scrFile, new File(currentPath + "\\" + filename));
22         } catch (IOException e) {
23             System.out.println("Can't save screenshot");
24             e.printStackTrace();
25         } finally {
26             System.out.println("screen shot finished, it's in " + currentPath
27                     + " folder");
28         }
29     }
  调用: snapshot((TakesScreenshot) driver, "zhihu_showClose.png");
  你可以在捕获异常的时候调用,可以实现错误截图,做测试结果分析很有效
  appium清空EditText(一个坑)
  在使用appium过程中,发现sendkeys和clear方法并不太好使,只好自己封装模拟手工一个一个删除
  这里用到keyEvent,具体内容请参考api http://appium.github.io/java-client/
  要删除一段文字,该怎么做:
  1. 获取文本长度
  2. 移动到文本最后
  3. 按下删除按钮,直到和文本一样长度
  移动到文本最后: 123删除67
  public static final intBACKSPACE67
  public static final intDEL67
  public static final intKEYCODE_MOVE_END123
31/3123>
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

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

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

沪ICP备05003035号

沪公网安备 31010102002173号