appium java实现截屏,java – 使用appium捕获Android屏幕截图

我目前正在努力捕获iOS上的截图,以便使用

java和junit进行appium测试.在测试完成之前,它会运行此代码以在杀死连接之前获取屏幕上最后一个可见的内容

@After

public void tearDown() throws Exception {

if (platform.equals(iOS)) {

captureScreenshot(testName.getMethodName());

}

driver.quit();

}

@SuppressWarnings("Augmenter")

public void captureScreenshot(String testName) {

String imagesLocation = "target/surefire-reports/screenshot/" + platform + "/";

new File(imagesLocation).mkdirs(); // Insure directory is there

String filename = imagesLocation + testName + ".jpg";

try {

Thread.sleep(500);

WebDriver augmentedDriver = new Augmenter().augment(driver);

File scrFile = ((TakesScreenshot)augmentedDriver).getScreenshotAs(OutputType.FILE);

FileUtils.copyFile(scrFile, new File(filename), true);

} catch (Exception e) {

System.out.println("Error capturing screen shot of " + testName + " test failure.");

// remove old pic to prevent wrong assumptions

File f = new File(filename);

f.delete(); // don't really care if this doesn't succeed, but would like it to.

}

}

这种方法适用于Android,但最近它完全杀死了运行测试,但这可能与它试图获取快照的设备有关.在保存文件之前,图像会出现空白或损坏.

任何人都知道如何使用appium在android上运行图像/屏幕捕获?也许是UIAutomator的东西?

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值