Open Steffx115 opened 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
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
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:
The report has only one screenshot in this case.
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
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:
The test is now failing:
But still one screenshot is taken:
Please note that I'm using the prepared base64 string instead of the real screenshot for tests to work faster:
Thank you
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
additional Info: Opening the test result via the VS Test explorer also only shows one Screenshot as test attachment
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
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
Ok, let me try once again
@Steffx115 , still works fine for me with this structure:
The latest commit with the test is in the master
branch.
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
hi, is there any update on this?
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
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.
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);
}
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?
@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:
Thank you
Hi @elv1s42 , Sorry for a delayed response. Please find the details. The execution is done by Nunit3-Console.
The way its installed is the Nunit3 Console runner is downloaded and the path is added to Environment variables.
relative path to the addin is added relavent files in the build path added as below
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.
Hope this helps.
Thank you @lagori! I will try to prepare the release with the fix this week.
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
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):