[TearDown]
public override void AfterEach()
{
if (TestContext.CurrentContext.Result.State != TestState.Success)
|
| [TearDown] public virtual void AfterEach() { if (TestContext.CurrentContext.Result.Outcome != NUnit.Framework.Interfaces.ResultState.Success) { Screenshot screenshot = driver.GetScreenshot(); screenshot.SaveAsFile("Screenshots\\" + DateTime.Now.ToString("yyyyMMdd_HHmm_") + TestContext.CurrentContext.Test.Name + ".png", System.Drawing.Imaging.ImageFormat.Png); // Dismiss alerts Helpers.AcceptAlert(driver); IEnumerable<IWebElement> EditCowButtons; if ((EditCowButtons = driver.FindElements(InseminationScreen.EditCowButton)).Any()) { EditCowButtons.First().Click(); } } allPassed = allPassed && (TestContext.CurrentContext.Result.Outcome == NUnit.Framework.Interfaces.ResultState.Success); } |
I notice you try to take a screenshot whenever the test result is not Success. I don't know your code but it seems likely that you would only have it available in case of a Failure result.
Outcome can have an unlimited set of values, with about eight common built-in ones.
--
You received this message because you are subscribed to the Google Groups "NUnit-Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nunit-discus...@googlegroups.com.
To post to this group, send email to nunit-...@googlegroups.com.
Visit this group at https://groups.google.com/group/nunit-discuss.
For more options, visit https://groups.google.com/d/optout.
when you say "The entire TestContext object is null" what do you mean? Is CurrentContext null? is Result null?
Where is your TearDown located wrt the test class. Is it in it or in a base class?
What build of the framework are you using? (.Net 4.5, Portable, etc.)
I'm assuming we are continuing the discussion in the context of NUnit 3. Since that is a completely new program to NUnit V2, it will be confusing to try to analyze both at the same time.
What would be helpful, if you can create it, would be a simple test case - nothing to do with screenshots - that demonstrates that the context (or some part) of it is null. We cold work that as a bug.
FYI, tests of the context in NUnit are here: https://github.com/nunit/nunit/blob/master/src/NUnitFramework/tests/TestContextTests.cs Can you see anything substantially different about what you are doing as compared to what we test?
What would be helpful, if you can create it, would be a simple test case - nothing to do with screenshots - that demonstrates that the context (or some part) of it is null. We cold work that as a bug.