Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jiawade opened this issue Sep 7, 2020 · 13 comments
Closed

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

jiawade opened this issue Sep 7, 2020 · 13 comments

Comments

@jiawade
Copy link

jiawade commented Sep 7, 2020

No description provided.

@grasshopper7
Copy link
Owner

grasshopper7 commented Sep 7, 2020

@jiawade
Copy link
Author

jiawade commented Sep 8, 2020

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
Copy link
Owner

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

@jiawade
Copy link
Author

jiawade commented Sep 9, 2020

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
Copy link
Owner

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

.

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
Copy link
Author

jiawade commented Sep 10, 2020

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
Copy link
Owner

grasshopper7 commented Sep 10, 2020

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
Copy link
Author

jiawade commented Sep 10, 2020

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

@grasshopper7
Copy link
Owner

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
Copy link
Owner

grasshopper7 commented Nov 23, 2020

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
Copy link
Author

jiawade commented Dec 4, 2020

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

@jiawade jiawade closed this as completed Dec 4, 2020
@grasshopper7
Copy link
Owner

Will close after full maven release.

@grasshopper7 grasshopper7 reopened this Dec 7, 2020
@grasshopper7
Copy link
Owner

Added in 2.6.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants