我正在尝试将已转换为base64字符串的图像显示为“a href”标记内的链接。
Java方法:
public void TakeScreenShot (String ScenarioName, String Description,JsonHtmlDataHelper jsonHtmlDataHelper)
{
TakesScreenshot takeScreenshotDriver = (TakesScreenshot) driver;
byte[] screenshotData = takeScreenshotDriver.getScreenshotAs(OutputType.BYTES);
JsonObject jsonObjectHtmlReport = new JsonObject();
jsonObjectHtmlReport.addProperty("ScenarioTest", ScenarioName);
String imageData = Base64.encodeBase64String(screenshotData);
String imgTag ="<img src=\"data:image/png;base64, " + imageData + "\" width=\"200\" height=\"150\"/>";
System.out.println(imageData);
jsonObjectHtmlReport.addProperty("TestStepDescription", imgTag);
jsonObjectHtmlReport.addProperty("TestStepResult","PASSED");
jsonHtmlDataHelper.AddProperty(jsonObjectHtmlReport);
}
上述方法正确显示HTML图像,但我想添加一个链接,将页面重定向到此图像。根据要求,我不能将图像存储在任何地方。
我尝试了以下内容:
<a rel=\"group\" href='#' onclick=\"$.fancybox.open({href:'data:image/png;base64," +imageData + "'})\">Click here</a>;
<a width=\"550\" height=\"190\" href=/ onclick=\"onclick=location.href=\'data:image/png;base64," + imageData + "\'\">click here</a>;
<img src=\"data:image/png;base64, " + imageData + "\" width=\"200\" height=\"150\"/>;
答案 0 :(得分:0)
你目前有这个:
String imgTag ="<img src=\"data:image/png;base64, " + imageData + "\" width=\"200\" height=\"150\"/>";
您可以使用链接到<a>
网址的data
标记将其包围:
String imgTag ="<a href=\"data:image/png;base64," + imageData + "\"><img src=\"data:image/png;base64," + imageData + "\" width=\"200\" height=\"150\"/></a>";