【问题标题】:Appium crashed when I am taking screenshotAppium 在我截屏时崩溃了
【发布时间】:2016-08-12 19:06:34
【问题描述】:

我无法截取失败的屏幕截图。早些时候,在我的真实 iOS 设备上一切正常,但现在 - Appium 崩溃并且无法截屏,我无法弄清楚发生了什么。

Appium 日志:link here

Java 代码:

public void takeScreenShotOnFailure(ITestResult testResult, String name) throws IOException  {
    if (testResult.getStatus() == ITestResult.FAILURE) {
        File scrFile = dr.getScreenshotAs(OutputType.FILE);
        Date date = new Date();
        SimpleDateFormat home = new SimpleDateFormat("dd.MM hh:mm:ss");
        String homedate = home.format(date);
        FileUtils.copyFile(scrFile, new File("test-output/screenshots/" + name + ".jpg"));
    }
}

有什么想法吗?

【问题讨论】:

  • 尝试将扩展名更改为 .png
  • Appium 在这一行崩溃:File scrFile = dr.getScreenshotAs(OutputType.FILE);
  • 好吧,抱歉,当我运行量角器脚本和 appium 时,我遇到了和你一样的错误
  • 虽然有同样的错误,但我们有两个不同的问题,可能是一般错误,不取决于屏幕截图或我的问题!

标签: java screenshot appium appium-ios


【解决方案1】:

试试这个代码:

  WebDriver driver = new FirefoxDriver();
    driver.get("http://www.google.com/");
    File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
    // Now you can do whatever you need to do with it, for example copy somewhere
    FileUtils.copyFile(scrFile, new File("c:\\tmp\\screenshot.png"));

【讨论】:

  • 我使用 IOSDriver,但它还没有帮助
【解决方案2】:
    File file = m_driver.getScreenshotAs(OutputType.FILE);
    try {
        FileUtils.copyFile(file, new File(screenshotName + "ScreenShot.jpg"));
        System.out.println(screenshotName + "ScreenShot.jpg generated\n");
    } catch (IOException e) {
        e.printStackTrace();
    }

这就是我使用 IOSDriver m_driver 生成屏幕截图的方式。我在 Mac 上使用它。从您的日志中,我建议您在尝试截屏时确保您的 IOSDriver 仍然存在。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-06-08
    • 1970-01-01
    • 2015-03-07
    • 2016-02-06
    • 1970-01-01
    • 1970-01-01
    • 2017-06-18
    相关资源
    最近更新 更多