【问题标题】:TestCafe chromium test run as part of docker buildTestCafe 铬测试作为 docker build 的一部分运行
【发布时间】:2019-11-28 05:42:47
【问题描述】:

由于某种原因,在我们的 CI 中,我们需要在 docker 容器内运行节点测试(包括获取依赖项等)。所以,我试图让 UI 测试作为 docker build 的一部分运行。

这就是我的 Dockerfile 的样子:

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"

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

另外,我尝试使用user 用户,但在运行测试之前在uitests 文件夹内创建reports 文件夹时出现权限错误。

我尝试了使用和不使用--no-sandbox 选项,遇到了同样的问题。也试过chromium:headless --no-sandbox,还是一样的错误。

有什么建议吗?谢谢。

更新: 还尝试了用户:user(通过使用/tmp 文件夹进行报告来避免权限问题)并遇到了同样的问题:

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.

更新 2: 用 firefox 也试过了,同样的问题:ERROR Unable to establish one or more of the specified browser connections. This can be caused by network issues or remote device failure.

更新 3: 抱歉耽搁了。在别的事情上分心了。在 CI 和本地机器上都试过了,这是相同的行为。还尝试了评论 echo -e '#!/bin/sh\n/usr/bin/chromium-browser --no-sandbox --remote-debugging-port=9222 --headless' > /usr/local/bin/testcafe-docker 中的建议,并在 CI 和本地环境中获得了以下输出。

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.

【问题讨论】:

  • 能否请您检查问题是否可重现:- 在您本地机器上的 Docker 中? - 在带有 TestCafe 图像的 CI 上的 Docker 中?此外,您可能希望将 Docker 文件中的 RUN ln -s /opt/testcafe/docker/testcafe-docker.sh /usr/local/bin/testcafe-docker 替换为以下行:RUN echo -e '#!/bin/sh\n/usr/bin/chromium-browser --no-sandbox --remote-debugging-port=9222 --headless' > /usr/local/bin/testcafe-docker; chmod +x /usr/local/bin/testcafe-docker 并向我们提供 Chrome 输出。
  • 更新了原始问题。不好意思推迟了。有vnc吗?可以在 docker 容器中看到浏览器(非无头)吗?

标签: automated-tests chromium e2e-testing testcafe docker-build


【解决方案1】:

最近的“Chromium”版本不允许您在 root 用户下运行它们。在运行 TestCafe 测试之前,将用户从“root”更改为user。 此外,您需要设置创建新文件夹的权限。 详细解释见write in shared volumes docker

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

【讨论】:

  • 我也试过user..但它是一样的..更新了原始问题。
  • 您能否提供一个没有您的私人资料的 docker 镜像示例?
  • 已解决。我的测试试图打开 url:localhost:8080.. 将其更改为 127.0.0.1:8080 有效。可能是 docker 容器中的一些解决问题.. 但如果错误消息更清楚,那就太好了.. 例如couldn't reach localhost:8080。未来改进的空间。
  • 其实是因为代理。我们使用代理来访问互联网。我在 docker 镜像中添加了 http_proxyhttps_proxyno_proxy。可能是 docker 容器中的浏览器试图通过代理访问 testcafe 服务器(在同一容器中运行)。 (因为它不使用 127.0.0.1/localhost?)删除代理设置现在有效,因为我不需要在此测试中访问互联网。
  • 172.17.0.2 添加到no_proxy 对我有用。要将0,1,2,3,4,5,6,7,8,9 添加到no_proxy.. 我们将无法通过 IP 地址访问互联网上的任何内容。
【解决方案2】:

这是因为代理。我们使用代理来访问互联网。我在 docker 镜像中添加了 http_proxyhttps_proxyno_proxy(127.0.0.1)。 docker 容器中的浏览器试图通过代理访问 testcafe 服务器(在同一容器中运行),因为它不使用 127.0.0.1/localhost 而是使用 172.17.0.2作为容器内的 testcafe 服务器主机。因此,将172.17.0.2 添加到no_proxy 有效。

【讨论】:

    猜你喜欢
    • 2020-03-04
    • 1970-01-01
    • 2020-07-15
    • 2017-12-30
    • 2011-04-06
    • 2022-01-12
    • 2019-08-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多