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

[Bug]: Console.WriteLine does not work with eventhandlers with multiple tests #2945

Open
christidoc opened this issue Jun 11, 2024 · 3 comments
Labels
P3-collecting-feedback upstream Issues that are already reported upstream.

Comments

@christidoc
Copy link

christidoc commented Jun 11, 2024

Version

1.44

Steps to reproduce

using Microsoft.Playwright.NUnit;

namespace WebAppUI.TestSuites;

[TestFixture]
[Parallelizable(ParallelScope.Default)]
public class MyTest : PageTest
{
	static int amountOfResponses = 0;

	[Test]
	public async Task TC1()
	{
		Page.Response += Listener;
		await Page.GotoAsync("https://playwright.dev/dotnet/");
		Console.WriteLine(amountOfResponses);
	}

	[Test]
	public async Task TC2()
	{
		Page.Response += Listener;
		await Page.GotoAsync("https://playwright.dev/dotnet/");
		Console.WriteLine(amountOfResponses);
	}

	private void Listener(object? sender, IResponse response)
	{
		Console.WriteLine(response.Url);
		amountOfResponses++;
	}
}

Expected behavior

https://playwright.dev/dotnet/
https://playwright.dev/dotnet/assets/css/styles.8a36420a.css
..........
18

https://playwright.dev/dotnet/
https://playwright.dev/dotnet/assets/css/styles.8a36420a.css
..........
36

Actual behavior

https://playwright.dev/dotnet/
https://playwright.dev/dotnet/assets/css/styles.8a36420a.css
etc...
18

36

Additional context

No response

Environment

- Operating System: [Windows 11]
- Browser: [Chromium]
- .NET Version (TFM): [net8.0]
@mxschmitt
Copy link
Member

mxschmitt commented Jun 11, 2024

I was able to reproduce in NUnit but not able to reproduce in MSTest, looks like a bug in NUnit.

Console.Error.WriteLine works while Console.WriteLine does not yield any output.

Filed as nunit/nunit#4728

@CharliePoole
Copy link

Well, the NUnit framework transforms all console writes from within tests to events. The runner that handles those events gets to decide whether or not to display them as well as where to display them and how.

NUnit Console runner, for example, displays error and progress output immediately. It saves stdout output to the test result but then displays that (delayed) as well.

In the case of dotnet test, I believe the adapter gets the first crack at the events and decides what to do. I don't now how or whether Playwright gets involved with output.

Frankly, I don't think it's a bug in NUnit, unless you have a goal that NUnit should work like MsTest. That, of course, has always been the underlying assumption of the Microsoft folks.

The part that is a mystery to me is why the first message gets displayed at all. Perhaps investigate who is picking up the TextOutput event and displaying it in that case.

@mxschmitt
Copy link
Member

Thank you for looking into this. I tried to reproduce it using NUnitLite Runner and there it surfaces the same problem: mxschmitt/nunit-repro-2nd-console-write-not-working@160bd92 - this means, that its no bug in dotnet test I guess.

I might try to build NUnit locally this week, if I have time in order to debug it further.

@mxschmitt mxschmitt added the upstream Issues that are already reported upstream. label Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3-collecting-feedback upstream Issues that are already reported upstream.
Projects
None yet
Development

No branches or pull requests

3 participants