Closed jiawade closed 3 years ago
hi @grasshopper7 Is it possible to embed the screenshots to HTML report? like this: href='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAB4AAAAQ4CAYAAADo08FD.......... rather than a screenshot link, such as: href="../embedded1.png"
Had tried it some time back, but the browser was not displaying them. What is the reason for using this approach?
Because it is more convenient for our company to present the report in this way(by the way, cucumber native report is also used base64 images to show its screenshots), But a relatively bad method was used to solve it, that is, after the report is generated, the .png file is converted to a base64 string and replaced../embedded1.png the browser can display in this way, see following attachment
U can try it pretty easily. There is createScreenCaptureFromBase64String in MediaEntityBuilder class. https://github.com/extent-framework/extentreports-java/blob/b3e079b1d351bffcb8d82972372dc9635ed31a2b/src/main/java/com/aventstack/extentreports/MediaEntityBuilder.java#L43
In the ExtentCucumberAdapter change the implementation of the handleEmbed https://github.com/grasshopper7/extentreports-cucumber6-adapter/blob/28eba5e6ff0c46743ecdca2769dbfc44178b28f3/extentreports-cucumber6-adapter/src/main/java/com/aventstack/extentreports/cucumber/adapter/ExtentCucumberAdapter.java#L214.
Most of the existing code can be removed other than the mimetype check. Just add below. Should work.
stepTestThreadLocal.get().info("", MediaEntityBuilder.createScreenCaptureFromBase64String(event.getData()).build());
Let me know if it works. I will include an option to use base64 for attachments in future release.
I changed the code you provided to: stepTestThreadLocal.get().addScreenCaptureFromBase64String(Base64.getEncoder().encodeToString(event.getData())); It works!!! and baseI changed the code you provided to: stepTestThreadLocal.get().addScreenCaptureFromBase64String(Base64.getEncoder().encodeToString(event.getData())); It works!!! and based on:
By the way, I found a issue, when I upgraded extent-report version to 5.0.1 and adapter to 2.0.0, when testing over, no extent report is generated, but cucumber native report. And no any errors.
But when I changed extent-report version to 4.1.4 and adapter to 1.2.0, the extent-report is generated to target directory and everything is ok.
Cool. I will look into adding the base64 option images to html.
Which report are u trying to generate when using the cucumber6 adapter? Only Spark and Json are available in extent 5.
ok, I see. perhaps I should continue use the cucumber extent 4.^_^ thanks a lot.
what cucumber version are u using? u should be using adapter corresponding to that. adapter 5 supports spark, logger, html and json till version 1.5.1. adapter 6 supports spark, logger, html and json till version 1.2.0.
I have added base64 support for images. - https://oss.sonatype.org/content/repositories/snapshots/tech/grasshopper/extentreports-cucumber6-adapter/
U will need to add below dependency to project POM
<dependency>
<groupId>tech.grasshopper</groupId>
<artifactId>extentreports-cucumber6-adapter</artifactId>
<version>2.6.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
Set the below property in extent.properties extent.reporter.spark.base64imagesrc=true
U will need to enable snapshot release in POM - https://stackoverflow.com/questions/16286055/how-to-get-snapshot-from-sonatype/16286460#16286460
Let me send your feedback, then I will proceed to release this as a full upgrade. My concern is that the spark report size is going to be an issue
@grasshopper7 thank your effort to support this, very thanks!!
Will close after full maven release.
Added in 2.6.0
Have u checked the sample implementation - https://github.com/grasshopper7/cuke6-extent-adapter-report/blob/2f366dffea4c1d2f607c19eb703f6a842ceb3519/cuke6-extent-adapter-report/src/test/java/stepdefs/Stepdefs.java#L96 What is the problem you are facing?