microsoft / playwright-dotnet

.NET version of the Playwright testing and automation library.
https://playwright.dev/dotnet/
MIT License
2.47k stars 235 forks source link

System.NullReferenceException at Microsoft.Playwright.NUnit.BrowserService #1563

Closed beamsjr closed 3 years ago

beamsjr commented 3 years ago

I am trying to follow the "First test" instructions here but when I run dotnet test -- NUnit.NumberOfTestWorkers=5 I get the following error:

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
  Failed ShouldAdd [4 s]
  Error Message:
   System.NullReferenceException : Object reference not set to an instance of an object.
  Stack Trace:
     at Microsoft.Playwright.NUnit.BrowserService.<>c__DisplayClass4_0.<<Register>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.Playwright.NUnit.WorkerAwareTest.RegisterService[T](String name, Func`1 factory)
   at Microsoft.Playwright.NUnit.BrowserService.Register(WorkerAwareTest test, IBrowserType browserType)
   at Microsoft.Playwright.NUnit.BrowserTest.BrowserSetup()
   at NUnit.Framework.Internal.TaskAwaitAdapter.GenericAdapter`1.GetResult()
   at NUnit.Framework.Internal.AsyncToSyncAdapter.Await(Func`1 invoke)
   at NUnit.Framework.Internal.Commands.SetUpTearDownItem.RunSetUpOrTearDownMethod(TestExecutionContext context, MethodInfo method)
   at NUnit.Framework.Internal.Commands.SetUpTearDownItem.RunSetUp(TestExecutionContext context)
   at NUnit.Framework.Internal.Commands.SetUpTearDownCommand.<>c__DisplayClass0_0.<.ctor>b__0(TestExecutionContext context)
   at NUnit.Framework.Internal.Commands.BeforeAndAfterTestCommand.<>c__DisplayClass1_0.<Execute>b__0()
   at NUnit.Framework.Internal.Commands.BeforeAndAfterTestCommand.RunTestMethodInThreadAbortSafeZone(TestExecutionContext context, Action action)
  Failed ShouldMultiply [< 1 ms]
  Error Message:
   System.NullReferenceException : Object reference not set to an instance of an object.
  Stack Trace:
     at Microsoft.Playwright.NUnit.BrowserService.<>c__DisplayClass4_0.<<Register>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.Playwright.NUnit.WorkerAwareTest.RegisterService[T](String name, Func`1 factory)
   at Microsoft.Playwright.NUnit.BrowserService.Register(WorkerAwareTest test, IBrowserType browserType)
   at Microsoft.Playwright.NUnit.BrowserTest.BrowserSetup()
   at NUnit.Framework.Internal.TaskAwaitAdapter.GenericAdapter`1.GetResult()
   at NUnit.Framework.Internal.AsyncToSyncAdapter.Await(Func`1 invoke)
   at NUnit.Framework.Internal.Commands.SetUpTearDownItem.RunSetUpOrTearDownMethod(TestExecutionContext context, MethodInfo method)
   at NUnit.Framework.Internal.Commands.SetUpTearDownItem.RunSetUp(TestExecutionContext context)
   at NUnit.Framework.Internal.Commands.SetUpTearDownCommand.<>c__DisplayClass0_0.<.ctor>b__0(TestExecutionContext context)
   at NUnit.Framework.Internal.Commands.BeforeAndAfterTestCommand.<>c__DisplayClass1_0.<Execute>b__0()
   at NUnit.Framework.Internal.Commands.BeforeAndAfterTestCommand.RunTestMethodInThreadAbortSafeZone(TestExecutionContext context, Action action)

Failed!  - Failed:     2, Passed:     0, Skipped:     0, Total:     2, Duration: 4 s - Rfsmart.PointOfCare.PlaywrightTests.dll (net5.0)
SimonCropp commented 3 years ago

can u format that stack trace using a fenced code block https://docs.github.com/en/github/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks#fenced-code-blocks

SimonCropp commented 3 years ago

i cant reproduce this. can you create a stand alone solution that reproduces the problem and push that to a github repository

avodovnik commented 3 years ago

That looks like you have something incorrectly set for the browser name. By default, we'll look at the BROWSER environmental variable.

Can you check if you've got something set there?

beamsjr commented 3 years ago

That indeed was my issue. Thank you.

SimonCropp commented 3 years ago

should a more useful exception be thrown in this scenario?

avodovnik commented 3 years ago

@SimonCropp see #1573 - we now fail the test, if this happens. I considered throwing an exception in the base implementation, but I didn't see the value and it just introduces a potential (unwarranted) behavioural change.