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

[Question]: How can i use Page in NUnit OneTimeTearDown? #2447

Open
jmurphy-asurity opened this issue Jan 10, 2023 · 1 comment
Open

[Question]: How can i use Page in NUnit OneTimeTearDown? #2447

jmurphy-asurity opened this issue Jan 10, 2023 · 1 comment

Comments

@jmurphy-asurity
Copy link

I am running tests using .Net and NUnit. I have some code that creates some state that the individual tests in the same file will share and use. Once that has been set up, the individual tests are run. Some of the tests use the Order attribute because they are sensitive to order, others do not need it. I would like to use a OneTimeTearDown block to clean the state up, but when I try to use Page in it I get the error below. I am currently working around this issue by using a test with a name that starts with Z (to force it to run last) for the cleanup, but that's not ideal.

TearDown : Microsoft.Playwright.PlaywrightException : Target page, context or browser has been closed
StackTrace: --TearDown
   at Microsoft.Playwright.Transport.Connection.InnerSendMessageToServerAsync[T](String guid, String method, Object args) in /_/src/Playwright/Transport/Connection.cs:line 163
   at Microsoft.Playwright.Transport.Connection.WrapApiCallAsync[T](Func`1 action, Boolean isInternal)
   at Microsoft.Playwright.Core.Frame.GotoAsync(String url, FrameGotoOptions options) in /_/src/Playwright/Core/Frame.cs:line 544
   at NUnit.Framework.Internal.TaskAwaitAdapter.GenericAdapter`1.BlockUntilCompleted()
   at NUnit.Framework.Internal.MessagePumpStrategy.NoMessagePumpStrategy.WaitForCompletion(AwaitAdapter awaiter)
   at NUnit.Framework.Internal.AsyncToSyncAdapter.Await(Func`1 invoke)
   at NUnit.Framework.Internal.Commands.SetUpTearDownItem.RunSetUpOrTearDownMethod(TestExecutionContext context, IMethodInfo method)
   at NUnit.Framework.Internal.Commands.SetUpTearDownItem.RunTearDown(TestExecutionContext context)```
@RenderMichael
Copy link
Contributor

[OneTimeTearDown] runs after the entire line of [TearDown]'s finish, so I don't think this is possible. I would add [Order] to all the tests, and give your cleanup method [Order(int.MaxValue)]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants