我正在尝试使用Allure aShot()类在我正在工作的网站上截取特定WebElements的屏幕截图,下面是我在selenium中使用的代码。请访问此链接,其中显示了aShot()项目文档:
https://github.com/yandex-qatools/ashot
所以我的问题是,这些实际保存的WebElement的AShot()屏幕截图在哪里?我使用testNG执行下面的方法,并成功地生成了诱惑力报告,但我在这些报告中或在我的框架中的任何地方都看不到这些屏幕截图。请检查以下代码,很难精确定位这些图像的位置。
因此,我的基本问题是:如何指定selenium将WebElement的这些AShot()屏幕截图存储到我们想要的特定文件中?
我尝试将下面提到的Screenshot类转换为BufferedImage或TakesScreenshot类,并使用ImageIO.write或FileUtils.copyFile方法将这些图像复制到文件中并将其存储在那里,但我收到错误消息,例如,"java.lang.ClassCastException: ru.yandex.qatools.ashot.Screenshot无法转换为org.openqa.selenium.TakesScreenshot“,我也尝试了其他方法,但均未成功。
请帮助我解决这个问题,我们如何知道/指定这些AShot()屏幕截图的保存位置?
public WebDriver driver;
@Test
public void getAShotImage() {
driver.get("http://....../");
WebElement element = driver.FindElement(By.xpath(".............."));
AShot shot = new AShot();
shot.takeScreenShot(driver, element);
OR
shot.coordsProvider(new WebDriverCoordsProvider()).takeScreenshot(driver, element);
}发布于 2015-04-11 23:11:09
你可以通过从方法中返回字节数组来附加截图。请看以下示例:
@Attachment(value="Screenshot", type="image/png")
private static byte[] captureScreenshot(Webdriver driver)
{
byte[] screenshot = null;
screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
}
return screenshot
}上面的代码没有使用Ashot,但它显示了如何附加文件。此外,如果您仍然无法看到屏幕截图,请检查您的步骤是否显示在report.If中,而不是FAQ中讨论的javaagent。
发布于 2015-04-13 22:11:43
AShot返回Screenshot对象,该对象包含元素的图像和用于截图比较的信息。在这种情况下,您可以使用getImage()方法来获取图像。
new AShot().takeScreenshot(....).getImage();Screenshot将很快包含字节数组,而不是BufferedImage。
https://stackoverflow.com/questions/29572859
复制相似问题