anshooarora / extentreports-csharp

Community version of Extent API for .NET has moved to https://github.com/extent-framework/
http://extentreports.com/
Other
47 stars 43 forks source link

Extent reports 3.0.2 displays mulitple screenshot images for single log entry #58

Closed iamsraja closed 6 years ago

iamsraja commented 7 years ago

Extent reports 3.0.2 display multiple screenshot images for single log entry as below

image

The code fragment I use, public void Information(string msg, string screenshotPath) { _logger.Warning(msg); TestCaseReporter.Info(msg,MediaEntityBuilder.CreateScreenCaptureFromPath(screenshotPath).Build()); }

TestCaseReporter is the instance of ExtentTest class

iamsraja commented 7 years ago

@anshooarora Hi Anshoo, Could you please help with this issue?

anshooarora commented 7 years ago

Are you sure this method isn't being called 3 times?

iamsraja commented 7 years ago

Thanks for the response @anshooarora. If had called thrice, I should have had log message printed 3 times as well.

anshooarora commented 7 years ago

Can you create a small POC for me to reproduce?

iamsraja commented 7 years ago

@anshooarora Hi Anshoo, Apologies for the delay. Here is a POC for you to reproduce the issue. ExtentReports.ScreenCapture.zip

Sample screenshot from POC:-

image

iamsraja commented 7 years ago

@anshooarora Cause for issue:- In Log.cs, For 'Details' attribute, if (_screenCapture != null) { _details = _details + _screenCapture.Source; _screenCapture = null; (missingcode) } return _details;

I'm currently following a workaround to sort this issue, The code fragment I use, public void Information(string msg, string screenshotPath) { _logger.Warning(msg); TestCaseReporter.Info(msg,MediaEntityBuilder.CreateScreenCaptureFromPath(screenshotPath).Build()); HtmlReporter.Flush(); TestCaseReporter.GetModel().LogContext().GetLast().ScreenCapture = null; } TestCaseReporter is the instance of ExtentTest class

sivadeepti commented 7 years ago

Hi ,

Each time you call this code

Report.HtmlReporter.Flush();

will attach screenshots .

You have called multiple times in your After Scenario,After Step , After Feature .

Use Flush only once.

venug0453 commented 7 years ago

Hi, was this issue resolved? I am seeing multiple images for a step based on the number of tesc cases left to execute. For example, if am executing 3 tests, then the first test is logging three screenshots for steps where screenshot was taken, second test is logging 2 screenshots for each steps where screenshot was taken and third step is logging 1 screenshot.

Not sure how to fix this. Any help will be greatly appreciated. Thanks.

venug0453 commented 7 years ago

I was able to find a workaround for my issue above until it gets fixed by the author of Extent Reports API. This is what I am doing at the end of the test in C#.

[TestCleanup] public void MyTestCleanup() {
testReport.Flush(); //testReport is my ExtentReports object int logContextItemCnt = reportTest.GetModel().LogContext().Count; //reportTest is my ExtentTest object for (int i = 0; i < logContextItemCnt; i++) {
reportTest.GetModel().LogContext().Get(i).ScreenCapture = null; } }

jmatthews79 commented 6 years ago

im experiencing the same thing and I only have one instance of flush per test. However, @venug0453 workaround works perfectly to fix the issue in the meantime

Brian-Watson commented 6 years ago

@anshooarora We too are seeing this issue.

Brian-Watson commented 6 years ago

@ssureshraja This was addressed in 3.1.2. Can you close this issue?