Currently, I have something working to capture screenshots on iOS for appium tests using java and junit. Before completing the test, he runs this code to get the last visible thing on the screen before killing the connection.
@After
public void tearDown() throws Exception {
if (platform.equals(iOS)) {
captureScreenshot(testName.getMethodName());
}
driver.quit();
}
@SuppressWarnings("Augmenter")
public void captureScreenshot(String testName) {
String imagesLocation = "target/surefire-reports/screenshot/" + platform + "/";
new File(imagesLocation).mkdirs();
String filename = imagesLocation + testName + ".jpg";
try {
Thread.sleep(500);
WebDriver augmentedDriver = new Augmenter().augment(driver);
File scrFile = ((TakesScreenshot)augmentedDriver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File(filename), true);
} catch (Exception e) {
System.out.println("Error capturing screen shot of " + testName + " test failure.");
File f = new File(filename);
f.delete();
}
}
This sorting works for android, but recently it has completely killed the current test, but this may be related to the device that is trying to take a snapshot. Before it saves the file, but the image will be blank or broken.
Does anyone know how to get image / screen capture running on Android using appium? Maybe something with UIAutomator?
source
share