codeceptjs / CodeceptJS

Supercharged End 2 End Testing Framework for NodeJS
http://codecept.io
MIT License
4.1k stars 724 forks source link

[Bug]: Codecept with Playwright e2e tests throws connection refused error in Github Actions #3361

Closed RashmiRamdas closed 11 months ago

RashmiRamdas commented 2 years ago

I'm trying to run e2e tests in parallel with workers (run-workers) in Github Actions in headless mode and getting this error

browserContext.storageState: net::ERR_FAILED at https://localhost:3000/ at Playwright._after Some of the tests run successfully before throwing this error. I have observed this error only on Github Actions and works fine on local


browserContext.storageState: net::ERR_FAILED at https://localhost:3000/
    at Playwright._after (/data/runners/node_modules/codeceptjs/lib/helper/Playwright.js:434:50) {
  name: 'Error'
}
  Click on close icon in nav bar when the form is in dirty state then Save the changes- Crystal
    --- STARTED "before each" hook: Before for "Click on close icon in nav bar when the form is in dirty state then Save the changes- Crystal" ---
    I clear cookie 
    › Screenshot is saving to /data/runners/test/output/record_2ade0e9c5f1ca5cebfabd11e1e1ae3fa/0000.png
    I am on page "/home"
    [1] Error | Error: page.goto: net::ERR_CONNECTION_REFUSED at https://localhost:3000/showcase/home
=========================== logs ===========================
navigating to "https://localhost:3000/showcase/home", waiting until "networkidle"
============================================================
    › Screenshot is saving to /data/runners/test/output/record_2ade0e9c5f1ca5cebfabd11e1e1ae3fa/0001.png
    [1] Error | Error: page.goto: net::ERR_CONNECTION_REFUSED at https://localhost:3000/showcase/home
=========================== logs ===========================
navigating to "https://localhost:3000/showcase/home", waiting until "networkidle"
============================================================
    [1] Error | Error: page.goto: net::ERR_CONNECTION_REFUSED at https://localhost:3000/showcase/home
=========================== logs ===========================
navigating to "https://localhost:3000/showcase/home", waiting until "networkidle"
============================================================
    [1] Error | Error: page.goto: net::ERR_CONNECTION_REFUSED at https://localhost:3000/showcase/home
=========================== logs ===========================
navigating to "https://localhost:3000/showcase/home", waiting until "networkidle"
============================================================
    [1] Error | Error: page.goto: net::ERR_CONNECTION_REFUSED at https://localhost:3000/showcase/home
=========================== logs ===========================
navigating to "https://localhost:3000/showcase/home", waiting until "networkidle"
============================================================
    [1] Error | Error: page.goto: net::ERR_CONNECTION_REFUSED at https://localhost:3000/showcase/home
=========================== logs ===========================
navigating to "https://localhost:3000/showcase/home", waiting until "networkidle"
============================================================
    [1] Error | Error: page.goto: net::ERR_CONNECTION_REFUSED at https://localhost:3000/showcase/home
=========================== logs ===========================
navigating to "https://localhost:3000/showcase/home", waiting until "networkidle"
============================================================
    [1] Error | Error: page.goto: net::ERR_CONNECTION_REFUSED at https://localhost:3000/showcase/home
=========================== logs ===========================
navigating to "https://localhost:3000/showcase/home", waiting until "networkidle"
============================================================
    [1] Error | Error: page.goto: net::ERR_CONNECTION_REFUSED at https://localhost:3000/showcase/home
=========================== logs ===========================
navigating to "https://localhost:3000/showcase/home", waiting until "networkidle"
============================================================
    [1] Error | Error: page.goto: net::ERR_CONNECTION_REFUSED at https://localhost:3000/showcase/home
=========================== logs ===========================
navigating to "https://localhost:3000/showcase/home", waiting until "networkidle"
============================================================
    [1] Error | Error: page.goto: net::ERR_CONNECTION_REFUSED at https://localhost:3000/showcase/home
=========================== logs ===========================
navigating to "https://localhost:3000/showcase/home", waiting until "networkidle"
============================================================
    [1] Error | Error: page.goto: net::ERR_CONNECTION_REFUSED at https://localhost:3000/showcase/home
=========================== logs ===========================
navigating to "https://localhost:3000/showcase/home", waiting until "networkidle"
============================================================
    [1] <teardown> Stopping recording promises
  ✖ FAILED in 212ms

Details

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: process.env.SHOWCASE_URL || integration.url || "https://localhost:3000/showcase",
            browser: process.profile || integration.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
        }
    },
};
kobenguyent commented 2 years ago

perhaps the url is not proper? http://localhost:3000/ instead of https

RashmiRamdas commented 2 years ago

URL is correct, it is https://localhost:3000/showcase. Some of the tests pass with this config and some random tests fails with above error.

Also, created ticket with playwright https://github.com/microsoft/playwright/issues/15642 for this issue. They have confirmed its related to codecept module as there is no Playwright._after in the stock Playwright library.

DavertMik commented 2 years ago

Is this still valid?

    // close other sessions
    try {
      const contexts = await this.browser.contexts();
      const currentContext = contexts[0];
      if (currentContext && (this.options.keepCookies || this.options.keepBrowserState)) {
        this.storageState = await currentContext.storageState();
      }

      await Promise.all(contexts.map(c => c.close()));
    } catch (e) {
      console.log(e);
    }

    // await this.closeOtherTabs();
    return this.browser;

Currently all storageState activity is wrapped in try/catch block

coskunuyar commented 2 years ago

Same issue with bitbucket pipelines

mosaadm commented 1 year ago

any updates on this ?

Emad-Armoun commented 1 year ago

Are there any updates on this?

achisholm commented 1 year ago

Arrived here via https://github.com/microsoft/playwright/issues/15642. I'm experiencing this same issue on playwright v1.29.2 when I run a github action

AyoCodess commented 1 year ago

any updates, we have the same issue in GitHub actions only. everything works well locally

coskunuyar commented 1 year ago

my action is giving up on playwright :)

kobenguyent commented 11 months ago

Closed for now! Feel free to reopen if you still encounter the issue with latest version and would be nice to provide a sample code to reproduce the issue.