Reputation: 21
Does anybody know how to save screenshot taken from real android device by appium+selenium to device local storage? Here I have method which can take screenshot from device and save it to PC storage. But how to set path to save them on real device folder (e.g. deviceName\tablet\GUI\screenshots\screenshot.jpg ...or other way), taking into account that code should run on PC.
p.s. My app is hybrid so I make switch context to "NATIVE_APP" and then back to WEBVIEW.
public static void getScreenshot(String screenName) throws IOException {
String contextName = AppiumConfigurationTest.driver.getContext();
AppiumConfigurationTest.driver.context("NATIVE_APP");
String Screenshotpath = "C:\\!automation\\build\\reports\\gui_screen_capture\\";
File screenShot = AppiumConfigurationTest.driver.getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(screenShot, new File(Screenshotpath + screenName+"_ " + "." + "jpg"));
AppiumConfigurationTest.driver.context(contextName);
}
Upvotes: 1
Views: 1750
Reputation: 128
File scrFile = ((TakesScreenshot) appiumDriver).getScreenshotAs(OutputType.FILE);
BufferedImage originalImage=null;
try {
originalImage= ImageIO.read(((TakesScreenshot) appiumDriver).getScreenshotAs(OutputType.FILE));
}
catch(Exception e) {
System.out.println("\n\n\n\nbuffered image" + originalImage +"\n\n\n\n\n\n");
Thread.sleep(5000);
e.printStackTrace();
}
System.out.println("buffered image" + originalImage);
BufferedImage.TYPE_INT_ARGB : originalImage.getType();
BufferedImage resizedImage = CommonUtilities.resizeImage(originalImage, IMG_HEIGHT, IMG_WIDTH);
ImageIO.write(resizedImage, "jpg", new File(path + "/"+ testCaseId + "/img/" + index + ".jpg"));
Upvotes: 1
Reputation: 31888
You can execute adb command from your code, in which case this shall help you :
adb shell screencap -p /sdcard/screen.png
Note : Saving the screenshots on laptop with different named tests/build is better than saving them on devices.
Upvotes: 1