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

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

Open
Steffx115 opened this issue Oct 1, 2019 · 22 comments
Assignees
Labels
Projects

Comments

@Steffx115
Copy link

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
@elv1s42 elv1s42 self-assigned this Oct 2, 2019
@elv1s42 elv1s42 added the bug label Oct 2, 2019
@elv1s42 elv1s42 added this to ToDo (Prioritised) in Ghpr Common via automation Oct 2, 2019
@elv1s42 elv1s42 added the Hacktoberfest https://hacktoberfest.digitalocean.com/ label Oct 2, 2019
@elv1s42
Copy link
Member

elv1s42 commented Oct 4, 2019

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 elv1s42 moved this from ToDo (Prioritised) to InProgress (Dev/QA) in Ghpr Common Oct 4, 2019
@Steffx115
Copy link
Author

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

elv1s42 commented Oct 18, 2019

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 elv1s42 added question and removed bug Hacktoberfest https://hacktoberfest.digitalocean.com/ labels Oct 18, 2019
@Steffx115
Copy link
Author

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

elv1s42 commented Oct 21, 2019

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

Steffx115 commented Oct 21, 2019

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

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

@elv1s42
Copy link
Member

elv1s42 commented Oct 25, 2019

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

Steffx115 commented Oct 25, 2019

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

elv1s42 commented Oct 25, 2019

Ok, let me try once again

@elv1s42
Copy link
Member

elv1s42 commented Oct 25, 2019

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

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

@Steffx115
Copy link
Author

Steffx115 commented Oct 28, 2019

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

hi, is there any update on this?

@elv1s42
Copy link
Member

elv1s42 commented Dec 4, 2019

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

lagori commented Mar 26, 2020

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

lagori commented Mar 26, 2020

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

lagori commented Mar 26, 2020

image

@elv1s42
Copy link
Member

elv1s42 commented Mar 27, 2020

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

elv1s42 commented Mar 27, 2020

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

lagori commented Apr 2, 2020

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 elv1s42 added bug and removed question labels Apr 7, 2020
@elv1s42
Copy link
Member

elv1s42 commented Apr 7, 2020

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

@elv1s42
Copy link
Member

elv1s42 commented Apr 10, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Ghpr Common
  
InProgress (Dev/QA)
Development

No branches or pull requests

3 participants