Kumar Gaurav
Kumar Gaurav

Reputation: 769

TestCafe chromium test run as part of docker build

For some reason, in our CI, we need to run node tests inside docker container (including fetching dependencies, etc.). So, I am trying to have UI tests run as a part of docker build.

This is how my Dockerfile looks like:

FROM testcafe/testcafe:1.3.3

USER root

#some packages needed for some dependencies
RUN apk add --no-cache yarn python make build-base vim curl 

RUN ln -s /opt/testcafe/docker/testcafe-docker.sh /usr/local/bin/testcafe-docker

WORKDIR /usr/src/app

RUN yarn config set registry https://private-npm-registry --global

COPY package*.json ./

RUN yarn

COPY . .

RUN yarn test:ui:ci

# "test:ui:clean": "rm -rf uitests/reports"
# "test:ui:ci-debug": "yarn test:ui:clean; testcafe-docker 'chromium --no-sandbox' uitests/tests -S -s uitests/reports/screenshots --video uitests/reports/videos -r spec,json:uitests/reports/report.json,html:uitests/reports/report.html",
# "test:ui:ci": "start-server-and-test serve http://127.0.0.1:8080 test:ui:ci-debug"

I get ERROR Unable to establish one or more of the specified browser connections. This can be caused by network issues or remote device failure.

Also, I tried using user user, but it gives permission error when creating reports folder inside uitests folder before running tests.

I tried it with and without the --no-sandbox option, got the same issue. Also tried chromium:headless --no-sandbox, got the same error.

Any suggestion, please? Thanks.

UPDATE: Also tried with user: user (avoiding permission issue by using /tmp folder for report) and got same issue:

20-Jul-2019 23:53:33    > yarn test:ui:clean; whoami; ls -sail; testcafe-docker 'chromium --no-sandbox' uitests/tests -S -s /tmp/uitests/reports/screenshots --video /tmp/uitests/reports/videos -r spec,json:/tmp/uitests/reports/report.json,html:/tmp/uitests/reports/report.html
20-Jul-2019 23:53:33    
20-Jul-2019 23:53:34    $ rm -rf /tmp/uitests/reports
20-Jul-2019 23:53:34    user
20-Jul-2019 23:53:34    total 528
20-Jul-2019 23:53:34         13      4 drwxr-xr-x   10 user     user          4096 Jul 20 13:52 .
20-Jul-2019 23:53:34         12      4 drwxr-xr-x    8 root     root          4096 Jul 20 13:52 ..
20-Jul-2019 23:53:34         79      4 -rw-r--r--    1 root     root            20 Jul 19 07:06 .dockerignore
20-Jul-2019 23:53:34         75      4 -rw-r--r--    1 root     root            45 Jul 19 07:06 .eslintignore
20-Jul-2019 23:53:34         83      4 -rw-r--r--    1 root     root           790 Jul 19 07:06 .eslintrc
20-Jul-2019 23:53:34         78      4 drwxr-xr-x    8 root     root          4096 Jul 20 13:48 .git
20-Jul-2019 23:53:34         82      4 -rw-r--r--    1 root     root           326 Jul 20 13:48 .gitignore
20-Jul-2019 23:53:34         87      4 -rw-r--r--    1 root     root           189 Jul 19 07:06 Dockerfile
20-Jul-2019 23:53:34         81      4 -rw-r--r--    1 root     root           592 Jul 20 13:48 DockerfileUITest
20-Jul-2019 23:53:34         89      4 -rw-r--r--    1 root     root           451 Jul 19 07:06 README.md
20-Jul-2019 23:53:34         90      4 drwxr-xr-x    3 root     root          4096 Jul 19 07:06 backend
20-Jul-2019 23:53:34       4096      4 drwxr-xr-x    3 user     user          4096 Jul 20 13:53 build
20-Jul-2019 23:53:34         85      4 -rwxr-xr-x    1 root     root           959 Jul 19 07:06 build.sh
20-Jul-2019 23:53:34         84      4 -rw-r--r--    1 root     root          1124 Jul 19 07:06 deploy.yaml
20-Jul-2019 23:53:34         91      4 drwxr-xr-x 1348 user     user          4096 Jul 20 13:52 node_modules
20-Jul-2019 23:53:34         74      4 -rw-r--r--    1 root     root          2959 Jul 20 13:48 package.json
20-Jul-2019 23:53:34         76      4 drwxr-xr-x    2 root     root          4096 Jul 19 07:06 public
20-Jul-2019 23:53:34         88      4 -rwxr-xr-x    1 root     root           742 Jul 19 07:06 runUITestsInCI.sh
20-Jul-2019 23:53:34         77      4 drwxr-xr-x    8 root     root          4096 Jul 19 07:06 src
20-Jul-2019 23:53:34         80      4 drwxr-xr-x    7 root     root          4096 Jul 19 07:06 uitests
20-Jul-2019 23:53:34         86    448 -rw-r--r--    1 root     root        454847 Jul 20 13:48 yarn.lock
20-Jul-2019 23:53:34    Using locally installed version of TestCafe.
20-Jul-2019 23:55:36    ERROR Unable to establish one or more of the specified browser connections. This can be caused by network issues or remote device failure.
20-Jul-2019 23:55:36    
20-Jul-2019 23:55:36    Type "testcafe -h" for help.

Update-2: Tried with firefox as well and same issue: ERROR Unable to establish one or more of the specified browser connections. This can be caused by network issues or remote device failure.

Update-3: Sorry for the delay. Got distracted in something else. Tried both in CI and local machine and it was same behaviour. Also tried suggestion in comment echo -e '#!/bin/sh\n/usr/bin/chromium-browser --no-sandbox --remote-debugging-port=9222 --headless' > /usr/local/bin/testcafe-docker and got following output in both CI and local env.

02-Dec-2019 18:45:17    DevTools listening on ws://127.0.0.1:9222/devtools/browser/711c6409-be9a-4e08-959e-0c994c8c5742
02-Dec-2019 18:45:17    [1202/074517.060637:ERROR:gl_implementation.cc(282)] Failed to load /usr/lib/chromium/swiftshader/libGLESv2.so: Error loading shared library /usr/lib/chromium/swiftshader/libGLESv2.so: No such file or directory
02-Dec-2019 18:45:17    [1202/074517.064824:ERROR:viz_main_impl.cc(176)] Exiting GPU process due to errors during initialization
02-Dec-2019 18:45:17    [1202/074517.072317:WARNING:dns_config_service_posix.cc(341)] Failed to read DnsConfig.
02-Dec-2019 18:45:17    [1202/074517.072782:WARNING:gpu_process_host.cc(1220)] The GPU process has crashed 1 time(s)
02-Dec-2019 18:45:17    [1202/074517.135149:ERROR:gl_implementation.cc(282)] Failed to load /usr/lib/chromium/swiftshader/libGLESv2.so: Error loading shared library /usr/lib/chromium/swiftshader/libGLESv2.so: No such file or directory
02-Dec-2019 18:45:17    [1202/074517.139203:ERROR:viz_main_impl.cc(176)] Exiting GPU process due to errors during initialization
02-Dec-2019 18:45:17    [1202/074517.143251:WARNING:gpu_process_host.cc(1220)] The GPU process has crashed 2 time(s)
02-Dec-2019 18:45:17    [1202/074517.208950:WARNING:gpu_process_host.cc(990)] Reinitialized the GPU process after a crash. The reported initialization time was 0 ms
02-Dec-2019 18:45:17    [1202/074517.209227:ERROR:gpu_channel_manager.cc(397)] ContextResult::kFatalFailure: Failed to create shared context for virtualization.

Upvotes: 2

Views: 1007

Answers (2)

Kumar Gaurav
Kumar Gaurav

Reputation: 769

It is because of proxy. We use proxy to reach internet. I was adding http_proxy, https_proxy and no_proxy(127.0.0.1) in docker image. Browser in docker container was trying to reach testcafe server (running in same container) through proxy, because it does not use 127.0.0.1/localhost but 172.17.0.2as testcafe server host inside container. So adding 172.17.0.2 to no_proxy works.

Upvotes: 0

mlosev
mlosev

Reputation: 5227

The recent 'Chromium' versions are not allow you to run them under the root user. Change the user from 'root' to user before running TestCafe tests. Also, you need to setup permission for creating new folders. See the detailed explanation in write in shared volumes docker

...
USER user
RUN yarn test:ui:ci

Upvotes: 2

Related Questions