Appium Appium 测试时切换到 webview 模式后如何对手机屏幕进行截图?在 native_app 模式下的截图方法此时排不上用,报 httpserver 无响应错误

金圣勋 · 2017年09月22日 · 1244 次阅读

在 native_app 模式下的截图可以全屏或根据 element 进行部分截图,全屏截图是:
File screen=appiumDriver.getScreenshotAs(OutputType.FILE);
File screenFile = new File(filepath+filename+".png");
FileUtils.copyFile(screen, screenFile);
基于 element 的部分截图是:
File srcFile=appiumDriver.getScreenshotAs(OutputType.FILE);
BufferedImage fullimage=ImageIO.read(srcFile);
WebElement ele=this.parseElement(area);
point=ele.getLocation();
eleimage=fullimage.getSubimage(point.getX(), point.getY(), ele.getSize().getWidth(), ele.getSize().getHeight());
ImageIO.write(eleimage, "png", srcFile);
FileUtils.copyFile(srcFile, new File(filepath+filename+".png"));
以上代码中执行 appiumDriver.getScreenshotAs(OutputType.FILE);时 webview 模式下无响应,无法截图,请问哪位知道这个问题如何解决?我希望是 webview 模式下也能正常全屏截图或部分截图。

共收到 4 条回复 时间 点赞

get_screenshot_as_file 也可以 webview 模式截图的吧,我用的就是这个,可以截啊~

def capture(self):
now_time = time.strftime("%Y%m%d%H%M%S", time.localtime(time.time()))
shortcut = self.driver.get_screenshot_as_file("D:\xxx\xxx\Screenshot\" + now_time + ".png")
return shortcut

截图时,先切换回 native_app 下再截图

webview 模式下不支持手机截图,切换 native_app

adb 截图可以用吗

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册