Running tests on testcafe docker works fine, but the browser versions are not latest.
Run on latest chrome and firefox version.
pull the docker image and run tests
$ docker run -v /Desktop/ci-integration-demo/tests:/tests -it testcafe/testcafe 'chromium --no-sandbox,firefox' /tests/test.js
Running tests in:
A set of examples that illustrate how to use TestCafe API
โ Text typing basics
โ Click an array of labels and then check their states
โ Dealing with text using keyboard
โ Moving the slider
โ Dealing with text using selection
โ Handle native confirmation dialog
โ Pick option from select
โ Filling a form
8 passed (25s)
Tested page URL: https://github.com/VasilyStrelyaev/ci-integration-demo/tree/master/tests
Test code
I will update the official image as soon as updated browser versions will appear in the repository
@sachs7 - if you want something to tide you over, here is our homegrown dockerfile that is focused on Local Headless Chrome + Remote Browsers [browserstack / saucelabs].
We add our code during build, you can change that by simply commenting out the COPY . /
```
FROM node:9-slim
RUN apt-get update && apt-get install -yq libgconf-2-4
RUN apt-get update && apt-get install -y wget --no-install-recommends && wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' && apt-get update && apt-get install -y google-chrome-unstable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst ttf-freefont --no-install-recommends && rm -rf /var/lib/apt/lists/* && apt-get purge --auto-remove -y curl && rm -rf /src/*.deb
RUN npm i -g testcafe
COPY package.json package.json
COPY package-lock.json package-lock.json
RUN npm install && rm -rf /tmp/*
COPY . /
RUN groupadd -r testcafe && useradd -r -g testcafe -G audio,video testcafe && mkdir -p /home/testcafe/Downloads && chown -R testcafe:testcafe /home/testcafe && chown -R testcafe:testcafe /node_modules
USER testcafe
ENTRYPOINT ["testcafe"]
CMD ["-h"]
```
@AndreyBelym - we have some learning from trying to work with the official image if you are willing to discuss. We think we can contribute some more robust docker interfaces for TestCafe.
Awesome @tk8817 I will try it out! Also, is there a way wherein you can point the Git Repo to fetch the tests. Something like:
docker run -v <https://github.com/some/repo>:/tests -it testcafe/testcafe -c 6 'chromium --no-sandbox' /tests/test.js -S -s /tests/screenshot
Hi @tk8817, of course I'll be happy to get your feedback and learn something from it ๐
The question was answered - https://github.com/DevExpress/testcafe/issues/2278#issuecomment-379763423
@tk8817 thanks for the script. i am struggling to run my test in the docker and i'm using this command
docker run -v ${PWD}:/tests node:9-slim chrome '/tests/tests/**/*'
could please tell me what i'm doing wrong?
Hi @augustineuzokwe, it looks like you are not running my code from above, instead you are running the vanilla node:9-slim image.
To run my code do the following
Dockerfiledocker build -t testcafe:custom .docker run testcafe:custom chrome /tests/tests/**/*:)
Hi @tk8817 thanks for your reply, really excited to run your solution.
chrome did not work with
Error unable to establish connection but i then tried chromium and it failed with the following
`Augustines-MacBook-Pro:client-e2e-tests augustine$ docker run -v ${PWD}:/tests testcafe:custom 'chrome:headless --no-sandbox' '/tests/tests/*/'
Using locally installed version of TestCafe.
Running tests in:
- HeadlessChrome 68.0.3438 / Linux 0.0.0
As an Admin portal user, i want to be able onboard a merchant with INSTORE
integration type
logged in as: test.PQ.INT.[email protected]
ERROR The HeadlessChrome 68.0.3438 / Linux 0.0.0 browser disconnected. This problem may appear when a browser hangs or is closed, or due to network issues.`
are you familiar with this issue?
@augustineuzokwe, try this
docker run --rm -it --shm-size=1gb testcafe:custom puppeteer:no_sandbox tests/**/*
In my prior comment I accidentally used your testcafe arguments not realizing that my image uses puppeteer rather than chrome in headless mode. Puppeteer is the official Google repo for working with Chrome programatically.
A couple notes:
--rm flag which removes the container when its done executing-it tflag which gives you an interactive tty shell--shm-size=1gb flag which is a trick to keep Chrome happy in DockerThanks @tk8817, I feel I should add --shm-size=1gb to the documentation.
Hi @tk8817 first of all, thanks for sharing this. I am running your Dockerfile image but I have the same issue mentioned before by @augustineuzokwe.
While executing ..
docker run --rm -it --shm-size=1gb testcafe:custom puppeteer:no_sandbox tests/**/*
I'm getting ..
ERROR Unable to find the browser. "puppeteer:no_sandbox" is not a browser alias or path to an executable file.
But also, trying with chrome, the process got hung and after I stop the process, the error thrown is the following:
ERROR Unable to establish one or more of the specified browser connections. This can be caused by network issues or remote device failure.
Any idea what is happening?
@alxtgda, when you use chrome in a Docker container, you should specify the ---no-sandbox flag for Chrome (starting it as docker run ... testcafe/testcafe 'chrome --no-sandbox') or starting the Docker container in the privileged mode using the --privileged flag (docker run --privileged ...).
So @AndreyBelym what about the ERROR Unable to find the browser. "puppeteer:no_sandbox" is not a browser alias or path to an executable file. issue. I got the same when I tried.
The only way I managed to get it running was to use chrome:headless . My guess is that I'm missing some xvfb configuration to have a graphical term.
docker run --rm -it --privileged --shm-size=1gb testcafe:custom_v1 'chrome:headless' tests/**/*
However I'm still experimenting a lot of _flakyness_ running it on the container in comparison with running it locally.
@tk8817 Hey, I am also experiencing flakyness with testcafe's docker image.
It's mostly solved when using --shm-size=4gb but I'm interested in understanding why it helps?
@AndreyBelym ?
Hi @amits1995, this switch controls size of the /dev/shm pseudo-file inside a Docker container. /dev/shm represents shared memory, that can be used for inter-process communications (IPC) and for high-speed temporary data storage, e,g. for storing browser's cache. Google Chrome actively uses shared memory, so increasing /dev/shm size helps in avoiding shared memory overflow.
I've found that since Chrome 65, you can tell the browser to not use shared memory by specifying the --disable-dev-shm-usage switch: Google Chrome in Docker tips. It will be nice if you check if this switch works for you and report the result here. It's a browser switch, so it must be specified to the TestCafe image like:
docker run -it testcafe/testcafe 'chromium -- no-sandbox --disable-dev-shm-usage' tests
Yep, tests are way more stable now with --disable-dev-shm-usage
Though I still have random issues with screenshots not being taken sometimes (usually because of a page redirect) but that's a different issue probably.
For the protocol, the error we used to see before using --disable-dev-shm-usage is:
ERROR The HeadlessChrome 68.0.3440 / Linux 0.0.0 browser disconnected. This problem may appear when a browser hangs or is closed, or due to network issues
Maybe it's worth updating this documentation
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs or feature requests. For TestCafe API, usage and configuration inquiries, we recommend asking them on StackOverflow.
Most helpful comment
@sachs7 - if you want something to tide you over, here is our homegrown dockerfile that is focused on Local Headless Chrome + Remote Browsers [browserstack / saucelabs].
We add our code during build, you can change that by simply commenting out the
COPY . /```
FROM node:9-slim
See https://crbug.com/795759
RUN apt-get update && apt-get install -yq libgconf-2-4
Install latest chrome dev package and fonts to support major charsets (Chinese, Japanese, Arabic, Hebrew, Thai and a few others)
Note: this installs the necessary libs to make the bundled version of Chromium that Puppeteer
installs, work.
RUN apt-get update && apt-get install -y wget --no-install-recommends && wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' && apt-get update && apt-get install -y google-chrome-unstable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst ttf-freefont --no-install-recommends && rm -rf /var/lib/apt/lists/* && apt-get purge --auto-remove -y curl && rm -rf /src/*.deb
RUN npm i -g testcafe
COPY package.json package.json
COPY package-lock.json package-lock.json
RUN npm install && rm -rf /tmp/*
COPY . /
Add user so we don't need --no-sandbox.
RUN groupadd -r testcafe && useradd -r -g testcafe -G audio,video testcafe && mkdir -p /home/testcafe/Downloads && chown -R testcafe:testcafe /home/testcafe && chown -R testcafe:testcafe /node_modules
Run everything after as non-privileged user.
USER testcafe
ENTRYPOINT ["testcafe"]
CMD ["-h"]
```
@AndreyBelym - we have some learning from trying to work with the official image if you are willing to discuss. We think we can contribute some more robust docker interfaces for TestCafe.