我写了一个java方法,其返回类型是file。此方法使用Ashot抓取屏幕截图并将其存储在屏幕截图对象上。我需要将截图对象转换为文件对象,以便我可以返回文件对象。如何将屏幕截图对象转换为Ashot硒中的文件对象
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;
}
你能告诉我们你的代码? –