testableapple
testableapple

Reputation: 325

Appium crashed when I am taking screenshot

I can't take a screenshot on failure. Earlier, all was ok on my real iOS device, but now - Appium crashed and screenshot not taking, and I can't figure out what was going on.

Appium log: link here

Java code:

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"));
    }
}

Any ideas?

Upvotes: 3

Views: 548

Answers (2)

Jasmine James
Jasmine James

Reputation: 1

    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();
    }

This is how I am generating screen shots using the IOSDriver m_driver. I am using this on a Mac. From you logs, I would suggest that you make sure you IOSDriver is still alive when trying to take the screenshot.

Upvotes: 0

Emna Ayadi
Emna Ayadi

Reputation: 2460

Try this code :

  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"));

Upvotes: 1

Related Questions