繁体   English   中英

Selenium中的Allure AShot()屏幕截图

[英]Allure AShot() screenshots in Selenium

我正在尝试用Allure aShot()类在我正在工作的网站上拍摄特定WebElement的屏幕截图,下面是我在selenium中使用的实现此目的的代码。 请访问此链接,其中显示aShot()项目文档:

https://github.com/yandex-qatools/ashot

所以我的问题是,这些WebElement的AShot()屏幕截图实际上保存在哪里? 我使用testNG执行以下方法,并成功生成了诱人的报告,但在这些报告或框架中的任何位置都看不到这些屏幕截图。 请检查以下代码,查明这些图像的位置非常困难。

再说一次,我的基本问题是:我们如何指定硒将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);

}

您可以通过从方法返回字节数组来附加屏幕截图。 看下面的例子:

@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不是那么很可能你缺少javaagent在讨论常见问题解答

AShot返回Screenshot对象,该对象包含元素的图像以及用于比较屏幕快照的信息。 在这种情况下,您可以使用getImage()方法获取图像。

new AShot().takeScreenshot(....).getImage();

Screenshot很快将包含字节数组而不是BufferedImage

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM