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.4k stars 3.63k forks source link

[BUG] Error at show HTML report #10010

Closed radekBednarik closed 2 years ago

radekBednarik commented 2 years ago

Context:

Code Snippet

node:events:368
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRINUSE: address already in use :::9323
    at Server.setupListenHandle [as _listen2] (node:net:1334:16)
    at listenInCluster (node:net:1382:12)
    at Server.listen (node:net:1469:7)
    at HttpServer.start (D:\Software Testing\Projects\SA_repos\TRACKING_automated_regression_tests\node_modules\playwright-core\lib\utils\httpServer.js:85:18)
    at showHTMLReport (D:\Software Testing\Projects\SA_repos\TRACKING_automated_regression_tests\node_modules\@playwright\test\lib\reporters\html.js:103:28)
    at HtmlReporter.onEnd (D:\Software Testing\Projects\SA_repos\TRACKING_automated_regression_tests\node_modules\@playwright\test\lib\reporters\html.js:72:15)
    at Multiplexer.onEnd (D:\Software Testing\Projects\SA_repos\TRACKING_automated_regression_tests\node_modules\@playwright\test\lib\reporters\multiplexer.js:73:7)
    at Runner._run (D:\Software Testing\Projects\SA_repos\TRACKING_automated_regression_tests\node_modules\@playwright\test\lib\runner.js:400:7)
Emitted 'error' event on Server instance at:
    at emitErrorNT (node:net:1361:8)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  code: 'EADDRINUSE',
  errno: -4091,
  syscall: 'listen',
  address: '::',
  port: 9323
}

Describe the bug

After test finishes and html report is to be auto served, the error displayed above is thrown. When I try to open http://localhost:9323, the HTML report is shown, although it is not fully functional - for example clicking on the failed test case to show details will open only blank page.

mxschmitt commented 2 years ago

Could it be that you have the HTML report open in another Terminal? I tried to reproduce it on Windows, but was not able to, for me it shutdown always correctly and a new HTML report was successfully opened.

radekBednarik commented 2 years ago

@mxschmitt okej, I tried to reproduce it, and it seems like this will happen, when:

mxschmitt commented 2 years ago

I tried a bunch of times to repro it, but was unfortunately not able to. What kind of Terminal are you using? (Powershell, cmd.exe, VSCode?)

radekBednarik commented 2 years ago

Powershell, 7.1.5

mxschmitt commented 2 years ago

~~Update: I was able to reproduce it! ~~

mxschmitt commented 2 years ago

Could it be that you close the HTML report with CTRL + C and press then by accident N?

I was only to reproduce it when doing that, when I pressed Y, it was working all the time.

radekBednarik commented 2 years ago

Unfortunately, no. I am doing, what I described in repro steps, no accidental key pressing. I can also provide my (slightly modified to run without headless and only one test in one project) playwright.config.js, if that helps:

const { join } = require("path");
const { cpus } = require("os");

require("dotenv").config();

const GLOBAL_SETUP_PATH = join(process.cwd(), "common/globals/globalSetup.js");
const JUNIT_RESULTS_PATH = join(process.cwd(), "results.xml");
const TOUCHPOINT = process.env.TOUCHPOINT;

module.exports = {
  // setup for all browsers
  use: {
    headless: true,
    viewport: { width: 1920, height: 1080 },
    ignoreHTTPSErrors: true,
    trace: "on-first-retry",
    // screenshot: "only-on-failure",
    // video: "retain-on-failure",
    // options for worker scoped context
    wContextOptions: {
      viewport: { width: 1920, height: 1080 },
      ignoreHTTPSErrors: true,
      // screenshot: "only-on-failure",
      // video: "retain-on-failure",
    },
  },
  timeout: 60000,
  globalSetup: GLOBAL_SETUP_PATH,
  testMatch: `**/${TOUCHPOINT}/spec/configurationStarted/cz.spec.js`,
  workers: process.env.CI ? 8 : cpus().length / 2,
  reportSlowTests: null,
  retries: 2,
  reporter: [["dot"], ["junit", { outputFile: JUNIT_RESULTS_PATH }], ["html"]],
  projects: [
    {
      name: "Chromium",
      use: {
        browserName: "chromium",
      },
    },
    // {
    //   name: "WebKit",
    //   use: {
    //     browserName: "webkit",
    //   },
    // },
  ],
};
pavelfeldman commented 2 years ago

The issue is that there is a process running on your system that keeps the 9223 port open. You should find the process that keeps the port open and kill it!

radekBednarik commented 2 years ago

@pavelfeldman yes, I get that, but isn't the core issue here, that the process is left hanging in first place under some circumstances (described above)?

mxschmitt commented 2 years ago

Reopening, was able to repro on a Mac. I was on an old Node.js version. After updating I could not reproduce.

mxschmitt commented 2 years ago

A provisional fix related to this bug got landed, it will be a part of 1.17, let us know if you still encounter related issues!

geoffreyhale commented 2 years ago

Able to reproduce the same issue when adding only the following line:

image
matrs commented 8 months ago

Sometimes happens to me. Still, if you're on linux you can do :

# get the PID
lsof -i@localhost | grep 'PORT_NUMBER_IN_USE'
kill -9 PID_FROM_ABOVE