TakesScreenshot.getScreenshotAs() does not work for Android 6.0 emulator (API level 23)

Hello,

[Appium version: 1.3.4]

the code snippet below creates a blank screenshot file for Android 6.0 emulator (API level 23):

File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
File targetFile = new File("target/screenshots/test.jpg");
FileUtils.copyFile(scrFile, targetFile);

It works for the API levels 17 to 22.

Thank you in advance for your help.

I don’t know if this has been solved within the Appium framework but I came across this using straight UiAutomator and it turned out to be a file system permission issue with the new permission handling approach to Android 6.0. You have to run “shell pm grant android.permission.WRITE_EXTERNAL_STORAGE” AND “shell pm grant android.permission.READ_EXTERNAL_STORAGE” before starting your tests (and also keep in mind those permissions are reset whenever you clear app data using pm as well). I wrote a blog post about that here: