GHPReporter / Ghpr.NUnit

Adapter for NUnit 3 (generate HTML report for NUnit 3)
http://ghpreporter.github.io/
MIT License
35 stars 14 forks source link

Screenshot added via NUnit TestContext.AddTestAttachment is displayed twice in GHPReport #61

Open Steffx115 opened 4 years ago

Steffx115 commented 4 years ago

Steps to reproduce Add screenshot to NUnit TestContext via AddtestAttachment method

Expected behavior Screenshot should only be displayed once

Desktop (please complete the following information):

elv1s42 commented 4 years ago

Hi @Steffx115 !

Can you please clarify how do you take screenshots in your tests? Are you doing it inside [TearDown] method or inside [Test] method? Are you using only TestContext.AddTestAttachment(...) method without ScreenHelper.SaveScreenshot(...) method?

These details will help me to reproduce the issue.

Thank you

Steffx115 commented 4 years ago

Hi,

We have a class called TestBase ,from which every TestClass is inherited, inside this class we take the screenshot inside the [TearDown] method, and we only use the TestContext.AddTestAttachment(...) method to save the screenshot

elv1s42 commented 4 years ago

Hi @Steffx115,

I've tried to reproduce the issue on my side and there are no duplicates. I used this code to reproduce the issue: image

The report has only one screenshot in this case.

Steffx115 commented 4 years ago

Did u let the Test fail so the Screenshot is taken from the TearDown method? Because we add the ScreenShot int he teardown using TestContext.AddTestAttachment

elv1s42 commented 4 years ago

Hi @Steffx115 !

Sorry, my bad.

I've tried to reproduce it once again with the correct repro steps - failing test with screenshot taken in the [Teardown] method: image

The test is now failing: image

But still one screenshot is taken: image

Please note that I'm using the prepared base64 string instead of the real screenshot for tests to work faster:

image

Thank you

Steffx115 commented 4 years ago

The only difference i notice now is, that we use .bmp as file extension for saving the screenshot

EDIT: i changed the file extension to .png, but this had no effect on this issue

Steffx115 commented 4 years ago

additional Info: Opening the test result via the VS Test explorer also only shows one Screenshot as test attachment

elv1s42 commented 4 years ago

Hi @Steffx115 ! Still no luck with trying to reproduce the issue. Can you please try to run this test to see if you'll get the screenshot twice for my example as well?

Thank you

Steffx115 commented 4 years ago

hi @elv1s42 , i just noticed that you didnt reproduce this with the class structure that I use you would need to move the [TestFixture] declaration and the [Teardown] method, which takes the screenshot, to another class and inherit from it.

So then you would have public class Tests : TestBase which contains only the tests, and no Teardown and no TestFixture declaration

elv1s42 commented 4 years ago

Ok, let me try once again

elv1s42 commented 4 years ago

@Steffx115 , still works fine for me with this structure: image

The latest commit with the test is in the master branch.

Steffx115 commented 4 years ago

In our test solution we have 2 TestFixtures defined for TestBase, is it possible that the screenshot is duplicated because of this?

EDIT: we only execute 1 TestFixture per testrun

Steffx115 commented 4 years ago

hi, is there any update on this?

elv1s42 commented 4 years ago

Hi @Steffx115!

Sorry for the delay, I still was not able to reproduce the issue. Can you please provide a small code sample so I would be able to reproduce your issue?

Thank you

lagori commented 4 years ago

Hi @elv1s42,

I am also having the same double screenshot issue. Following is my code: [TearDown] public void TakeScreenIfFailed() { var res = TestContext.CurrentContext.Result.Outcome; if (res.Equals(ResultState.Failure) || res.Equals(ResultState.Error)) { ScreenHelper.SaveScreenshot(Utils.TakeScreenshot(driver));

        }
    }

static public byte[] TakeScreenshot(IWebDriver driver) { Screenshot ss = ((ITakesScreenshot)driver).GetScreenshot(); string screenshot = ss.AsBase64EncodedString; byte[] screenshotAsByteArray = ss.AsByteArray; return screenshotAsByteArray; }


Many Thanks.

lagori commented 4 years ago

Also, When using TestContext as well it is having double image [Test] public void VerifyHomeLink() { Assert.IsTrue(driver.FindElement(By.LinkText("Home")).Displayed); TestContext.WriteLine("Test context line..."); TestContext.AddTestAttachment(@"C:\Pros\temp\ss.png", "optional ss info...");

        Console.WriteLine("Verify Home Link Test Method1..... -Test1 >> " + driver);
    }
lagori commented 4 years ago

image

elv1s42 commented 4 years ago

Hi @lagori, Thank you for the detailed example!

Can you please provide me some more information about the environment you are using?

Are you using NUnit console with Ghpr.NUnit package to run the tests or are you generating the report from NUnit .xml file using Ghpr.Console package?

elv1s42 commented 4 years ago

@lagori,

Also, it will be really helpful if you provide the content of the corresponding .json file for the test where the screenshot is duplicated.

Here is the example of the file: image

Thank you

lagori commented 4 years ago

Hi @elv1s42 , Sorry for a delayed response. Please find the details. The execution is done by Nunit3-Console. image

The way its installed is the Nunit3 Console runner is downloaded and the path is added to Environment variables. image

relative path to the addin is added image relavent files in the build path added as below image

Environment VS 2019 .NETFramework 4.72 class library NUnit console with Ghpr.NUnit package used.

GHP reports and logs as zipped _GHPReporter_NUnit_Report.zip

Also one more observation - there is a screenshot saved at the execution directory. Not sure if its meant to be saved. image

Hope this helps.

elv1s42 commented 4 years ago

Thank you @lagori! I will try to prepare the release with the fix this week.

elv1s42 commented 4 years ago

Hello @Steffx115 and @lagori!

This issue is now fixed in v0.9.12. Please be aware that it's required to update both Ghpr.NUnit and Ghpr.Core NuGet packages.

Thank you