如何将截图对象转换为Ashot selenium中的文件对象

时间:2017-06-22 06:48:30

标签: selenium cucumber

我写了一个返回类型为file的java方法。此方法使用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;
}

1 个答案:

答案 0 :(得分:2)

这应该可以解决问题

@example.errors.any?