Take a screenshot not working


I am trying to take a screenshot during a failure. The file is saved but i cannot open it.
When I try to open the file I get a message of: The file “clickOnFirstRow.png” could not be opened because it is empty.
I am using mac os.
I have set the capability:
This is my code:
public static void captureScreenshot(AppiumDriver driver, String screenshotName){

    try {
        TakesScreenshot ts=driver;
        File source = ts.getScreenshotAs(OutputType.FILE);
        File target = new File("/Users/shay/Desktop/" +screenshotName+".png");
        System.out.println("Screenshot was taken");
    } catch (IOException e) {
        Log.report("Exception while taking the screenshot");

Any idea what am I doing wrong?


this works for both appium and selenium.

WebDriver augmentedDriver = new Augmenter().augment(driver)
File scrFile = (TakesScreenshot)augmentedDriver).getScreenshotAs(OutputType.FILE)
FileUtils.copyFile(scrFile, new File("${storagePath}${File.separator}${fileName}"))

That is done in groovy, java should work basically the same

Can you post a Github Gist or pastebin of your Appium logs? I think that would reveal much more to what’s going on that a snippet of code that looks right. :stuck_out_tongue: