DevExpress / testcafe

A Node.js tool to automate end-to-end web testing.
https://testcafe.io
MIT License
9.81k stars 668 forks source link

Random "Cannot establish browser connection" errors with Docker #8256

Closed viktorss89 closed 2 weeks ago

viktorss89 commented 4 weeks ago

What is your Scenario?

When I run my tests through Docker (local or in Azure DevOps pipelines) I get random (40-50% of times) failures of this type:

"1 of 1 browser connections have not been established:

I've checked all the related issues to this one and I could not fix it with the solutions that people gave

What is the Current behavior?

When the tests start executing the browser connection is not established

What is the Expected behavior?

When the tests start executing the browser connection is established

What is the public URL of the test page? (attach your complete example)

I believe it is not related to the application (it only happened after upgrading testcafe from 3.3.0 to 3.6.2)

What is your TestCafe test code?

This is how the Dockerfile looks like:

`FROM node:18-alpine

USER root RUN apk add --no-cache bash chromium

RUN mkdir /app && mkdir /app/results WORKDIR /app

ARG BRANCH_NAME COPY package.json package-lock.json .npmrc ./

Setting the HOME variable to addresses the "npm ERR! code EACCES" error

ENV HOME=. RUN npm ci

COPY . ./ RUN sleep 30 CMD ["npm", "run", "pipelineHeadless"]`

And this is the command of pipelineHeadless

"pipelineHeadless": "testcafe 'chromium:headless --no-sandbox --disable-dev-shm-usage --ignore-certificate-errors' $TEST_DIR -s path=results/screenshots,takeOnFails=true -S --reporter spec,nunit3:results/report.xml"

Your complete configuration file

{ "skipJsErrors": true, "screenshots": { "path": "reports/screenshotsOnFail/", "takeOnFails": true }, "reporter": [ { "name": "spec" }, { "name": "html", "output": "reports/report.html" }, { "name": "json", "output": "reports/report.json" } ], "compilerOptions": { "typescript": { "configPath": "./tsconfig.json" } } }

Your complete test report

I attach an example of how it looks like the initialization when it works ok:

`cms-frontend-e2e@0.1.0 pipelineHeadless testcafe 'chromium:headless --no-sandbox --disable-dev-shm-usage --ignore-certificate-errors' $TEST_DIR -s path=results/screenshots,takeOnFails=true -S --reporter spec,nunit3:results/report.xml

The "reporter" and "screenshots.path" options from the configuration file will be ignored. Running tests in:

Screenshots

No response

Steps to Reproduce

Try any sample tests you may already have running through that Dockerfile and command I passed (try a few times)

TestCafe version

3.6.2

Node.js version

18.20.4

Command-line arguments

testcafe 'chromium:headless --no-sandbox --disable-dev-shm-usage --ignore-certificate-errors' $TEST_DIR -s path=results/screenshots,takeOnFails=true -S --reporter spec,nunit3:results/report.xml

Browser name(s) and version(s)

Chrome 127

Platform(s) and version(s)

Alpine Linux 3.20.2

Other

No response

github-actions[bot] commented 3 weeks ago

Thank you for submitting a bug report. We would love to help you investigate the issue. Please share a simple code example that reliably reproduces the bug. For more information, read the following article: How To Create a Minimal Working Example When You Submit an Issue. We look forward to your response.

viktorss89 commented 3 weeks ago

@Bayheck Any given test on any website will trigger this issue. That's why I didn't provide one.

Bayheck commented 3 weeks ago

Hello,

Could the issue be related to the machine where you run your tests?

Have you tried running the tests on a different machine?

Also, you mentioned 'local or in Azure DevOps pipelines'. Do you see any difference in the failure rate between the two environments?

Any given test on any website will trigger this issue. That's why I didn't provide one

We need a simple and reliable example from start to end - preferably in the form of a repository in your case. The repository should contain all the information and files necessary to reproduce the issue. Any user should be able to follow your instructions. Something like this: image

Please refer to the following help topic: https://testcafe.io/documentation/402636/faq/general-info#how-to-create-a-minimal-working-example-when-you-submit-an-issue.

viktorss89 commented 2 weeks ago

I fixed the issue changing the docker image from "node:18-alpine" to "node:alpine3.19"