问题描述
我正在使用 testNG 和 Selenium 运行一些测试.测试数据来自 CSV 文件.在每个步骤中,都可以截取页面的屏幕截图.我正在尝试将此屏幕截图添加到 testNG HTML 报告(可通过电子邮件发送的报告)中.
I am running some tests using testNG and Selenium. The test data comes from a CSV file. In each step it is possible to take a screenshot of the page. I am trying to add this screenshot to the testNG HTML report (emailable report).
我用这个来添加 img 元素;
I am using this to add the img element;
Reporter.log("<img src=\"file:///" + pathToScreen + "\" alt=\"\"/><br />");
现在这部分起作用了,因为它实际上是将其添加到报告中,如下面的屏幕截图所示.但是 HTML 代码似乎不起作用.
Now this works partially, because it is in fact adding this to the report as you can see in the screenshot below. But the HTML code does not seem to work.
是不是图片文件路径不对?我想是的,但我不知道如何解决这个问题.
Is the path to the image file wrong? I think so, but I am not sure how I can fix this.
更新:这是来自 HTML 报告的源代码.显然它甚至没有将其解析为 HTML???
UPDATE:This is from the source code of the HTML report. Apparently its not even parsing it as HTML???
<div class="messages"><img src="file://C:\Users\myUSername\Desktop/screenshots/step 1_enter username_baseline.png" alt=""/></img></div>
推荐答案
好吧,显然我看错了文件.我正在查看 emailable-report.html 而reporter.log 将所有内容发送到index.html.在 index.html 文件中,使用我第一篇文章中的代码一切正常.
Ok apparantly I was looking at the wrong file. I was looking at the emailable-report.html while reporter.log sends everything to index.html. In the index.html file everything is working fine using the code in my first post.
这篇关于将屏幕截图添加到 TestNG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!