[英][Ashot][Selenium] - Take screenshot for iOS and Android
[英]How to convert screenshot object into file object in Ashot selenium
我写了一个java方法,其返回类型是file。 此方法使用Ashot抓取屏幕截图并将其存储在Screenshot对象上。 我需要将该屏幕截图对象转换为文件对象,以便我可以返回文件对象。
public static File grabScreenshot() {
try {
Thread.sleep(Integer.parseInt(Property.getProperty("screenshotDelay")));
} catch (InterruptedException e) {
e.printStackTrace();
} catch (NumberFormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
File screenshot=null; //creating null file object to return
Screenshot screenshot1 = new AShot().shootingStrategy(new ViewportPastingStrategy(1000)).takeScreenshot(driver());
//Here I have to typecast the screenshot1 to file type so that I can return
return screenshot;
}
这应该可以解决问题
// getImage() will give buffered image which can be used to write to file
BufferedImage bi = new AShot()
.shootingStrategy(ShootingStrategies.viewportPasting(100))
.takeScreenshot(driver).getImage();
File outputfile = new File("image.jpg");
try {
ImageIO.write(bi, "jpg", outputfile);
} catch (IOException e) {
e.printStackTrace();
}
// Print the absolute path to see where the file is created
System.out.println(outputfile.getAbsolutePath());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.