Robotium截图设置

Robotium截图设置

1、前提条件

在被测试的应用中添加对SD卡的读写权限,文件为AndroidManifest.xml,添加以下标示

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" ></uses-permission>


2、使用solo的takeScreenshot方法来截取当前页面


takeScreenshot

public void takeScreenshot()
Takes a screenshot and saves it in "/sdcard/Robotium-Screenshots/". Requires write permission (android.permission.WRITE_EXTERNAL_STORAGE) in AndroidManifest.xml of the application under test.


使用该方法时,如果文件目录不存在,则会自动创建,且生成的图片文件格式如下

271113-054228.jpg, 其中27为日,11为月,13为年,其他的为时分秒,且文件默认格式为jpg

代码实现为:

solo.sleep(10000) ;
        solo.takeScreenshot() ;
        solo.sleep(1000) ;



takeScreenshot

public void takeScreenshot(String name)
Takes a screenshot and saves it with the specified name in "/sdcard/Robotium-Screenshots/". Requires write permission (android.permission.WRITE_EXTERNAL_STORAGE) in AndroidManifest.xml of the application under test.
Parameters:
name - the name to give the screenshot


使用该方法时,可以自定义生成的文件名字,且可以自动创建文件目录

代码实现为:

solo.sleep(10000) ;
        solo.takeScreenshot("test") ;
        solo.sleep(1000) ;

生成的文件为test.jpg



takeScreenshot

public void takeScreenshot(String name,
                           int quality)
Takes a screenshot and saves the image with the specified name in "/sdcard/Robotium-Screenshots/". Requires write permission (android.permission.WRITE_EXTERNAL_STORAGE) in AndroidManifest.xml of the application under test.
Parameters:
name - the name to give the screenshot
quality - the compression rate. From 0 (compress for lowest size) to 100 (compress for maximum quality)


使用该方法可以对生成的图片进行压缩,大小从0到100,值越小越失真

代码实现:

solo.sleep(10000) ;
        solo.takeScreenshot("test100",100) ;
        solo.sleep(1000) ;


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值