配置ExtentReports以注入自定义html [英] Configuring ExtentReports to inject custom html
问题描述
我需要我的范围报告(v 3.0.0)才能在页面中具有超链接.我正在尝试为以下代码注入自定义HTML,其中webSessionID是我从网页上抓取的UUID.
I need my Extent Report (v 3.0.0) to have a hyperlink in the page. I am trying to inject the custom HTML for the following, where webSessionID is a UUID I scrape from the webpage.
URL格式应为:
<a href="https://myapp.xmltravel.com/app/logs/s/OPY5Q2EV3P:6CBA845DB3E99F97931FCC9ED84711EB">OPY5Q2EV3P:6CBA845DB3E99F97931FCC9ED84711EB</a>
这是我正在尝试的(注意相关区域的代码注释):
Here is what I am trying (note code comments for relevant areas):
我的代码:
public class TestBase implements Config {
protected WebDriver driver = null;
private Logger APPLICATION_LOGS = LoggerFactory.getLogger(getClass());
private static ExtentReports extent;
private static ExtentTest test;
private static ITestContext context;
private static String webSessionId;
@BeforeSuite
@Parameters({"env", "browser"})
public void beforeSuite(String env, String browser) {
String f = System.getProperty("user.dir") + "\\test-output\\FabrixExtentReport.html";
ExtentHtmlReporter h = new ExtentHtmlReporter(f);
extent = new ExtentReports();
extent.attachReporter(h);
extent.setSystemInfo("browser: ", browser);
extent.setSystemInfo("env: ", env);
String codeBlockOne = "<a href=" + "\"https://myapp.com/app/logs/s/\"";
String codeBlockTwo = "/a>";
m1 = MarkupHelper.createCodeBlock(codeBlockOne); //SET HTML OPENING
m2 = MarkupHelper.createCodeBlock(codeBlockTwo); //SET HTML CLOSING
}
@AfterMethod
public void afterMethod(ITestResult result) throws IOException {
switch (result.getStatus()) {
case ITestResult.FAILURE:
test.fail(result.getThrowable());
test.fail("Screenshot below: " + test.addScreenCaptureFromPath(takeScreenShot(result.getMethod().getMethodName())));
test.fail("WebSessionId: " + m1 + webSessionId + m2);//RELEVANT METHOD
break;
case ITestResult.SKIP:
test.skip(result.getThrowable());
break;
case ITestResult.SUCCESS:
test.pass("Passed");
break;
default:
break;
}
}
相关标签的当前输出为:
Current output of the relevant tag is:
<td class='step-details'>WebSessionId:
com.aventstack.extentreports.markuputils.CodeBlock@432038ectfbweb0~FE5625464A1F6ED331FB2355BDAF8F00com.aventstack.extentreports.markuputils.CodeBlock@7daa0fbd</ td>
</tr>
推荐答案
不熟悉ER,但您只是获得了标记对象引用的字符串表示形式. m1 = MarkupHelper.createCodeBlock(codeBlockOne);
m1将具有Markup
类型.尝试使用m1.getMarkup()
.
Not familiar with ER but you are just getting string representation of Markup object reference. m1 = MarkupHelper.createCodeBlock(codeBlockOne);
m1 will have Markup
type. Try to use m1.getMarkup()
.
这篇关于配置ExtentReports以注入自定义html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!