scenario.embed用于嵌入两个不同的屏幕截图.浏览器顶部的一个屏幕截图和最底层的一个屏幕截图。然而,屏幕截图在黄瓜报告中产生相同的文件名,因此在报告中只看到两个相同的屏幕快照。
只拍摄一个屏幕就可以很好地嵌入到黄瓜报告中。然而,这是第一次尝试包括两个(2)屏幕截图。它以前没有用过两个屏幕截图。pom.xml;黄瓜-报告3.16.0,黄瓜- java 1.2.5,java 1.8 jenkinsci/黄瓜-报告-插件
if (scenario.isFailed()) {
try {
System.out.println("Taking screenshot 1");
byte[] screenshot = ((TakesScreenshot) getWebDriver()).getScreenshotAs(OutputType.BYTES);
scenario.embed(screenshot, "image/png");
System.out.println("Screenshot 1 taken");
System.out.println("Taking screenshot 2");
getWebDriver().manage().window().setPosition(new Point(0,0));
byte[] screenshot2 = ((TakesScreenshot) getWebDriver()).getScreenshotAs(OutputType.BYTES);
scenario.embed(screenshot2, "image/png");
System.out.println("Screenshot 2 taken");
Expected
No error message. Cucumber report to include two different screenshots with different filename.
Actual
No error message. Cucumber report to include two same screenshots with same filename.
Resulting cucumber-html-reports/report-feature_3750966460.html :
<a>Attachment 1 (png)</a>
<a href="embeddings/embedding_-2088059111.png" download target="_blank">
<span class="download-button glyphicon glyphicon-download-alt"></span>
</a>
</div>
<div id="embedding-9" class="collapse collapsable-details">
<div class="embedding-content">
<img src="embeddings/embedding_-2088059111.png">
</div>
. . .
<a>Attachment 2 (png)</a>
<a href="embeddings/embedding_-2088059111.png" download target="_blank">
<span class="download-button glyphicon glyphicon-download-alt"></span>
</a>
</div>
<div id="embedding-10" class="collapse collapsable-details">
<div class="embedding-content">
<img src="embeddings/embedding_-2088059111.png">
</div>发布于 2022-10-25 05:21:20
试试下面的代码逻辑:
if (scenario.isFailed()) {
//take screenshot
String screenshotName =scenario.getName().replaceAll("", "_");
byte[] sourcepath =((TakesScreenshot)driver).getScreenshotAs(OutputType.BYTES);
scenario.attach(sourcepath, "image/png", screenshotName);
} https://stackoverflow.com/questions/56188579
复制相似问题