如何在Testcafe中对docker和electronic使用'resizeWindow'? ResizeWindow Testcafe测试在gitlab yml中启动 package.json ./ ci / .testcafe-electron-rc 经测试的docker映像:

问题描述

在使用gitlab测试电子应用程序时,我在docker容器内使用Testcafe中的resizeWindow有问题。

注意:在本地设置(linux)上,所有测试均按预期工作,但在docker容器resizeWindow内似乎无法正常工作。容器内的其他测试也可以工作。

也许我缺少xvfb的任何配置,还是应该使用fluxBox

任何建议如何解决这个问题?


使用docker测试错误

$ yarn test-e2e-ci
yarn run v1.22.4
$ node -r @babel/register ./internals/scripts/CheckBuildsExist.js && cross-env NODE_ENV=test testcafe electron:./ci ./test/e2e/DockerTest.e2e.ts --screenshots takeOnFails=true
 Running tests in:
 - Electron 9.0.4 / Linux 0.0
 Docker execution
 ✖ `ResizeWindow` works as expected 
   1) AssertionError: expected 1024 to deeply equal 100
      browser: Electron 9.0.4 / Linux 0.0
          8 |
          9 |test('`ResizeWindow` works as expected ',async t => {
         10 |  await t.resizeWindow(100,100);
         11 |  const innerWidth = await t.eval(() => window.innerWidth);
         12 |  const innerHeight = await t.eval(() => window.innerHeight);
       > 13 |  await t.expect(innerWidth).eql(100);
         14 |  await t.expect(innerHeight).eql(100);
         15 |});
         16 |
         at <anonymous>
      (/builds/myFancyProject/test/e2e/DockerTest.e2e.ts:13:30)
         at fulfilled
      (/builds/myFancyProject/test/e2e/DockerTest.e2e.ts:5:58)
 1/1 Failed (8s)

警告:

 Warnings (3):
 --
  Was unable to resize the window due to an error.
  The
  /builds/myFancyProject/node_modules/testcafe-browser-tools/bin/linux/glibc-64/resize
  process Failed with the null exit code.
 --

使用的测试设置:

ResizeWindow testcafe测试

test('`ResizeWindow` works as expected ',async t => {
  await t.resizeWindow(100,100);
  const innerWidth = await t.eval(() => window.innerWidth);
  const innerHeight = await t.eval(() => window.innerHeight);
  await t.expect(innerWidth).eql(100);
  await t.expect(innerHeight).eql(100);
});

在gitlab yml中启动

- xvfb-run --server-num=99 --server-args='-ac -screen 0 1024x768x16' yarn test-e2e-ci

package.json

"test-e2e-ci": "node -r @babel/register ./internals/scripts/CheckBuildsExist.js && cross-env NODE_ENV=test testcafe electron:./ci ./test/e2e/ --screenshots takeOnFails=true",

./ ci / .testcafe-electron-rc

{
  "mainWindowUrl": "../app/app.html","appPath": "../app","appArgs": "--no-sandBox"
}

经测试的docker映像:

circleci/node:latest-browsers

FROM node:lts-stretch

RUN apt-get update \
    && apt-get install -y xvfb \
    libnotify4 \
    libgconf2-4 \
    libnss3 \
    libxtst-dev \
    libc6 \
    libstdc++6 \
    libgcc1 \
    libgtk-3-0 \
    libasound2 \
    libxrender1 \
    libxss1

解决方法

您需要正确安装和设置fluxbox工具。 请参阅TestCafe docker相关文件中的示例: