grasshopper7 / extentreports-cucumber6-adapter

Cucumber-JVM 6 Adapter for Extent Framework
https://ghchirp.online/2098/
MIT License
16 stars 15 forks source link

how to attach base64 image to extent report, when testing failed? #11

Closed jiawade closed 3 years ago

grasshopper7 commented 4 years ago

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?

jiawade commented 4 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"

grasshopper7 commented 4 years ago

Had tried it some time back, but the browser was not displaying them. What is the reason for using this approach?

jiawade commented 4 years ago

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

index.zip

grasshopper7 commented 4 years ago

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.

jiawade commented 4 years ago

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: Snipaste_2020-09-10_22-24-41

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. Snipaste_2020-09-10_21-55-36

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. Snipaste_2020-09-10_22-24-41

grasshopper7 commented 4 years ago

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.

jiawade commented 4 years ago

ok, I see. perhaps I should continue use the cucumber extent 4.^_^ thanks a lot.

grasshopper7 commented 4 years ago

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.

grasshopper7 commented 3 years ago

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

jiawade commented 3 years ago

@grasshopper7 thank your effort to support this, very thanks!!

grasshopper7 commented 3 years ago

Will close after full maven release.

grasshopper7 commented 3 years ago

Added in 2.6.0