microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
66.81k stars 3.66k forks source link

[Bug]: Test doesn't fail as expected #32536

Open beksajt opened 2 months ago

beksajt commented 2 months ago

Version

1.46.0

Steps to reproduce

await Page.GotoAsync("http://www.google.com/");
await Expect(Page).ToHaveTitleAsync("xD");

Expected behavior

pw 1 39 0

Test result should be failed with exception: Microsoft.Playwright.PlaywrightException : Page title expected to be 'xD'

Actual behavior

Test can't finish its job and spins forever: pw 1 46 0

Additional context

Found out that it happens only when chromium is set in runsettings. Firefox works ok.

Environment

- Operating System: Windows10
- CPU: [arm64]
- Browser: [ Chromium ]
- .NET Version (TFM): [net8.0]
- Other info:
runsettings:
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
  <!-- NUnit adapter -->  
  <NUnit>
    <NumberOfTestWorkers>24</NumberOfTestWorkers>
  </NUnit>
  <!-- General run configuration -->
  <RunConfiguration>
    <EnvironmentVariables>
      <!-- For debugging selectors, it's recommend to set the following environment variable -->
      <DEBUG>pw:api</DEBUG>
    </EnvironmentVariables>
  </RunConfiguration>
  <!-- Playwright -->  
  <Playwright>
    <BrowserName>chromium</BrowserName>
    <ExpectTimeout>5000</ExpectTimeout>
    <LaunchOptions>
      <Headless>false</Headless>
      <Channel>msedge</Channel>
    </LaunchOptions>
  </Playwright>
</RunSettings>
mxschmitt commented 2 months ago

While the test looks good, I suspect something else is going wrong. I recommend the following:

  1. Try to run the test in the terminal via dotnet test. So we know its not something Visual Studio causes.
  2. Try to set the DEBUG=pw:browser,pw:api environment variable, this should give us more debug output about the browser launch
beksajt commented 2 months ago

Firefox run failed as expected, but chromium is hanging as previously (i waited 5min+) Attaching logs from two runs: firefox and chromium (msedge):

firefox.txt chromium.txt

mxschmitt commented 2 months ago

I see that you are using Microsoft Edge. Most likely on your system cooperate policies / Enterprise policies are applied which are preventing from running Playwright how it should, see here.

Could you try running it without the channel option?

beksajt commented 2 months ago

I tried without channel option and result is the same. Also i tried with playwright 1.39.0 (the same code, the same runsettings) And here is the log: chromium-edge-1.39.0.txt

mxschmitt commented 1 month ago

The logs you shared are still using Edge - do you have logs with just Chromium (no channel)?

beksajt commented 1 month ago

There you go no-channel-1.46.0.txt

mxschmitt commented 1 month ago

Looking at the logs I observe that the directory cleanup seems to hang and then races with the 30s timer to kill the browser:

2024-09-10T11:07:19.901Z pw:browser [pid=9268] starting temporary directories cleanup 2024-09-10T11:07:49.188Z pw:browser [pid=9268]

It internally will retry when EBUSY, EMFILE, ENFILE, ENOTEMPTY, or EPERM error is encountered during directory removal.

Do you have a special anti virus installed on your system? Enterprise policies should not play a role when you use just Chromium.

beksajt commented 1 month ago

Nope, i dont use any special anti virus. When i downgrade nuget package to 1.39.0 test is finished with fail (as expected). Take a look a this log. There is an exception at the end, but at least it exits. no-channel-1.39.0.txt

mxschmitt commented 1 month ago

I see, this is probably also the case except that we don't surface it anymore:

2024-09-10T11:03:35.922Z pw:browser [pid=14916] exception while removing C:\Users\$USER\AppData\Local\Temp\playwright_chromiumdev_profile-XXXXXXnNz44M: Error: EPERM: operation not permitted, unlink 'C:\Users\Konrad\AppData\Local\Temp\playwright_chromiumdev_profile-XXXXXXnNz44M\Default\Network\Cookies-journal'

Looks like Chromium keeps the file open / in busy state.