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
67.14k stars 3.69k forks source link

When ECONNREFUSED error is thrown? #15749

Closed RashmiRamdas closed 2 years ago

RashmiRamdas commented 2 years ago

Hi Team, I was going through a file socksProxy.ts in https://github.com/microsoft/playwright/blob/c7212e6d56c05cf0618794e878b4d11987c70c36/packages/playwright-core/src/common/socksProxy.ts I came across ECONNREFUSED error code in socketFailed method. I would like to know when this error is thrown? And how to handle when this error is thrown ? I get this error when running e2e test in github actions. Some of the tests run successfully before throwing this error.

mxschmitt commented 2 years ago

I doubt that the code pointer which you shared is the cause of the error you are getting. Could you share more information with us like when your error is happening and the whole error message?

RashmiRamdas commented 2 years ago

I'm trying to run e2e tests in parallel with workers (run-workers) in Github Actions in headless mode.

Some of the tests run successfully before throwing this error. I have observed this error only on Github Actions and works fine on local

    [16]  Starting recording promises
User Settings Tests --
    Timeouts: 
  Update Personal Access Token and Git user Name
    --- STARTED "before each" hook: Before for "Update Personal Access Token and Git user Name" ---
    I am on page "/"
    [16] <check login> Error | Error: page.goto: net::ERR_CONNECTION_REFUSED at https://localhost:3000/showcase/
=========================== logs ===========================
navigating to "https://localhost:3000/showcase/", waiting until "networkidle"
============================================================
    [16] <check login> Error | Error: page.goto: net::ERR_CONNECTION_REFUSED at https://localhost:3000/showcase/
=========================== logs ===========================
navigating to "https://localhost:3000/showcase/", waiting until "networkidle"
============================================================
    [16] <check login> Error | Error: page.goto: net::ERR_CONNECTION_REFUSED at https://localhost:3000/showcase/
=========================== logs ===========================
navigating to "https://localhost:3000/showcase/", waiting until "networkidle"
============================================================
    [16] <check login> Error | Error: page.goto: net::ERR_CONNECTION_REFUSED at https://localhost:3000/showcase/
=========================== logs ===========================
navigating to "https://localhost:3000/showcase/", waiting until "networkidle"
============================================================
    [16] <check login> Error | Error: page.goto: net::ERR_CONNECTION_REFUSED at https://localhost:3000/showcase/
=========================== logs ===========================
navigating to "https://localhost:3000/showcase/", waiting until "networkidle"
============================================================
 › Failed auto login for user due to Error: page.goto: net::ERR_CONNECTION_REFUSED at https://localhost:3000/showcase/
=========================== logs ===========================
navigating to "https://localhost:3000/showcase/", waiting until "networkidle"
============================================================

conf file

const { setHeadlessWhen, setWindowSize } = require("@codeceptjs/configure");
const { integration } = require(`./../package.json`);
const page = require("./utils/pageObject");
const bootstrap = require("./utils/boostrap");
const users = require("./utils/users");

setHeadlessWhen(process.env.CI || integration.headless);
setWindowSize(1920, 1080);

exports.config = {
    tests: `./**/*.+(e2e|visual).+(js|ts)`,
    output: `./output`,
    helpers: {
        Playwright: {
            url:  "https://localhost:3000/showcase",
            browser: "chromium",
            show: !integration.headless,
            coloredLogs: true,
            smartWait: integration.waitInSeconds * 1000 || 5 * 1000,
            uniqueScreenshotNames: true,
            fullPageScreenshots: true,
            restart: false,
            keepBrowserState: true,
            keepCookies: true,
            waitForNavigation: "networkidle0",
            timeouts: {
                script: 60000,
                "page load": 10000,
            },
            ignoreHTTPSErrors: true,
            chromium: {
                args: [
                    "--disable-web-security",
                    "--allow-insecure-localhost",
                    "--ignore-certificate-errors",
                    "--no-sandbox",
                    "-–allow-file-access-from-files",
                ],
            },
            firefox: {
                args: [
                    "--disable-web-security",
                    "--allow-insecure-localhost",
                    "--ignore-certificate-errors",
                    "--ignore-ssl-errors",
                    "--no-sandbox",
                    "-–allow-file-access-from-files",
                ],
            },
        },
        Actions: {
            require: "./utils/helpers/actionsHelper.js",
        },
    },
    include: {
        I: "./utils/customSteps.js",
        Selectors: "./utils/pageObject",
    },
    multiple: {
        e2e: {
            browsers: [{ browser: "firefox" }, { browser: "chromium" }],
        },
    },
    bootstrap: bootstrap,
    mocha: {},
    name: "showcase",
    plugins: {
        retryFailedStep: {
            enabled: true,
        },
        stepByStepReport: {
            enabled: true,
        },
        screenshotOnFail: {
            enabled: false,
        },
        customLocator: {
            enabled: true,
            prefix: "testid=",
            attribute: "data-testid",
        },
        allure: {
            enabled: false,
            enableScreenshotDiffPlugin: false,
        },
        autoLogin: {
            enabled: true,
            saveToFile: true,
            inject: "loginAs",
            users: users,
        },
        stepTimeout:{
            enabled: true,
            timeout: 10
        }
    },
};
mxschmitt commented 2 years ago

Seems like you need to wait until your site is ready and fully available. You can e.g. use this: https://www.npmjs.com/package/wait-on

RashmiRamdas commented 2 years ago

This issue happens randomly at some point. Initial few tests run successfully and also localhost starts running at 3000 port before starting tests, so site is available.

mxschmitt commented 2 years ago

How do you ensure that your dev server is ready and accepting requests?

dgozman commented 2 years ago

@RashmiRamdas If first tests run successfully, most likely your server stops while tests are still running, so that later localhost:3000 does not respond.

RashmiRamdas commented 2 years ago

How do you ensure that your dev server is ready and accepting requests?

codecept.app-runner is used which starts running tests once app is available

RashmiRamdas commented 2 years ago

@RashmiRamdas If first tests run successfully, most likely your server stops while tests are still running, so that later localhost:3000 does not respond.

yes when tests tries to run, net::ERR_CONNECTION_REFUSED is thrown so trying to understand why server stops with this error

dgozman commented 2 years ago

yes when tests tries to run, net::ERR_CONNECTION_REFUSED is thrown so trying to understand why server stops with this error

Not sure how we can help with that 😄 Sorry!

dgozman commented 2 years ago

Closing as per above. If you believe we can help you here and you have a repro that we can run locally, please file a new issue with a repro and link to this one.