简体   繁体   English

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

[英]How to convert screenshot object into file object in Ashot selenium

I wrote a java method whose return type is file. 我写了一个java方法,其返回类型是file。 This method grabs a screenshot of screen with Ashot and store it on a Screenshot object. 此方法使用Ashot抓取屏幕截图并将其存储在Screenshot对象上。 I need to convert that screenshot object into file object so that I can return file object. 我需要将该屏幕截图对象转换为文件对象,以便我可以返回文件对象。

   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;
}

This should do the trick 这应该可以解决问题

// 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.

相关问题 [Ashot][Selenium] - 适用于 iOS 和 Android 的截图 - [Ashot][Selenium] - Take screenshot for iOS and Android 如何通过 Selenium 和 Java 使用 AShot 库截取整页截图 - How to take full page screenshot using AShot library through Selenium and Java 使用 Ashot 和 Selenium 从多个 URL 截取屏幕截图 - Taking screenshot from multiple URL's with Ashot and Selenium Selenium:无法使用 aShot 库截取完整的页面截图 - Selenium: Not able to take complete page screenshot using aShot library 使用Selenium和Webdriver截取flash对象的屏幕截图 - Taking screenshot of flash object using Selenium with Webdriver 使用 Ashot 和 Watir 截屏 - Take Screenshot using AShot and Watir Selenium中的Allure AShot()屏幕截图 - Allure AShot() screenshots in Selenium 如何将 Selenium By 对象转换为 CSS 选择器? - How to convert Selenium By object to a CSS selector? 如何在 selenium 中使用 Ashot 为整个网页截屏 - How to use Ashot in selenium to take screen shot for entire webpage 如何将 object 的屏幕截图存储到字符串并将图像保存到 selenium WebDriver 中的 excel 工作表中? - How can I store a screenshot from an object to a string and save the image into an excel worksheet in selenium WebDriver?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM