Ghpr.NUnit icon indicating copy to clipboard operation
Ghpr.NUnit copied to clipboard

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

Open Steffx115 opened this issue 6 years ago • 22 comments

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):

  • OS: Windows 10 Enterprise 64 bit
  • Browser: Chrome 77.0.3865.90 64 bit

Steffx115 avatar Oct 01 '19 10:10 Steffx115

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

elv1s42 avatar Oct 04 '19 16:10 elv1s42

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

Steffx115 avatar Oct 11 '19 10:10 Steffx115

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.

elv1s42 avatar Oct 18 '19 08:10 elv1s42

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

Steffx115 avatar Oct 21 '19 09:10 Steffx115

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

elv1s42 avatar Oct 21 '19 09:10 elv1s42

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 avatar Oct 21 '19 11:10 Steffx115

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

Steffx115 avatar Oct 21 '19 13:10 Steffx115

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

elv1s42 avatar Oct 25 '19 08:10 elv1s42

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

Steffx115 avatar Oct 25 '19 08:10 Steffx115

Ok, let me try once again

elv1s42 avatar Oct 25 '19 08:10 elv1s42

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

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

elv1s42 avatar Oct 25 '19 08:10 elv1s42

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 avatar Oct 28 '19 11:10 Steffx115

hi, is there any update on this?

Steffx115 avatar Nov 27 '19 16:11 Steffx115

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

elv1s42 avatar Dec 04 '19 09:12 elv1s42

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 avatar Mar 26 '20 11:03 lagori

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 avatar Mar 26 '20 11:03 lagori

image

lagori avatar Mar 26 '20 11:03 lagori

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 avatar Mar 27 '20 15:03 elv1s42

@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

elv1s42 avatar Mar 27 '20 16:03 elv1s42

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.

lagori avatar Apr 02 '20 03:04 lagori

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

elv1s42 avatar Apr 07 '20 11:04 elv1s42

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

elv1s42 avatar Apr 10 '20 16:04 elv1s42