如何在 testcafe/testcafe docker 容器中调试 Testcafe 浏览器 运行?
How do I debug a Testcafe browser running in a testcafe/testcafe docker container?
在页面中测试了 React 应用程序的登录功能 class:
async login(t) {
console.log('starting login...');
debugger;
this.logBrowserMessages(t);
await this.loginModal({ visibilityCheck: true });
await t
.expect(this.loginModal.visible)
.ok()
// then log the user in etc...
和测试,当 运行 在本地时通过但在容器中失败
test.requestHooks(mock)('user can log in', async t => {
await page.login(t);
// Make sure test user's orders render.
await t.expect(page.orders.childNodeCount).gt(1, { timeout: 10000 });
测试在本地通过,但在容器中 运行ning 时失败(登录不起作用)。
当我 运行 在本地进行测试时,它会按预期进行调试:
testcafe chrome --inspect-brk=9230 ./tests/login.test.js --skip-js-errors
过程 node_modules/testcafe/lib/cli
出现在我的 chrome://inspect/#devices
中,正如预期的那样。
但是,当我在 testcafe docker 容器中 运行 testcafe 时,它不会使用以下任何命令进行调试:
docker run --expose 9230 -p 9230:9230 -e BASIC_AUTH_USER -e BASIC_AUTH_PASS -e NODE_ENV=docker -e TEST_USER -e TEST_PASS --shm-size=1gb -v `pwd`:/tests -v `pwd`/screenshots/docker:/screenshots testcafe/testcafe 'chromium --no-sandbox' --inspect-brk=0.0.0.0:9230 -S -s '/screenshots' --skip-js-errors /tests/**/login.test.js
docker run --expose 9230 -p 9230:9230 -e \"NODE_PATH=/opt:/opt/testcafe/node_modules:/tests/node_modules\" -e BASIC_AUTH_USER -e BASIC_AUTH_PASS -e NODE_ENV=docker -e TEST_USER -e TEST_PASS --shm-size=1gb -v `pwd`:/tests -v `pwd`/screenshots/docker:/screenshots testcafe/testcafe 'chromium --no-sandbox' --inspect-brk=0.0.0.0:9230 -S -s '/screenshots' --skip-js-errors /tests/**/login.test.js
docker run --expose 9230 -p 9230:9230 -e BASIC_AUTH_USER -e BASIC_AUTH_PASS -e NODE_ENV=docker -e TEST_USER -e TEST_PASS --shm-size=1gb -v `pwd`:/tests -v `pwd`/screenshots/docker:/screenshots testcafe/testcafe 'chromium --no-sandbox' --inspect-brk=127.0.0.1:9230 -S -s '/screenshots' --skip-js-errors /tests/**/login.test.js
docker run --expose 9230 -p 9230:9230 -e \"NODE_PATH=/opt:/opt/testcafe/node_modules:/tests/node_modules\" -e BASIC_AUTH_USER -e BASIC_AUTH_PASS -e NODE_ENV=docker -e TEST_USER -e TEST_PASS --shm-size=1gb -v `pwd`:/tests -v `pwd`/screenshots/docker:/screenshots testcafe/testcafe --inspect-brk=0.0.0.0:9230 --browsers 'chromium --no-sandbox' -S -s '/screenshots' --skip-js-errors /tests/**/login.test.js
docker run --expose 9230 -p 9230:9230 -e \"NODE_PATH=/opt:/opt/testcafe/node_modules:/tests/node_modules\" -e BASIC_AUTH_USER -e BASIC_AUTH_PASS -e NODE_ENV=docker -e TEST_USER -e TEST_PASS --shm-size=1gb -v `pwd`:/tests -v `pwd`/screenshots/docker:/screenshots testcafe/testcafe 'chromium --no-sandbox' -S -s '/screenshots' --skip-js-errors --inspect-brk=9230 /tests/**/login.test.js
我正在使用的容器是否有一些我不知道的限制?我之前在 Docker 容器中调试过 Node 进程 运行ning,我知道这是可以做到的。但那是不久前的事了。我错过了什么吗?
如果您在 Mac 上开发,一种可能性是您需要将主机指定为 host.docker.internal
而不是 127.0.0.1
以便 运行 主机上的服务对容器可见。这可能是本地和容器化测试运行之间的差异之一。
您可以使用NODE_OPTIONS
环境变量来启用远程调试:
docker run -it --rm -p 9229:9229 -e NODE_OPTIONS="--inspect-brk=0.0.0.0:9229" -v /host/path/to/tests:/tests testcafe/testcafe 'chromium --no-sandbox' /tests/test.js
如果您不使用 docker-machine
,您可以在浏览器中打开 http://localhost:9229/json
并导航到 devtoolsFrontendUrl
[=26= 中指定的 DevTools URL ].
否则,请使用 docker-machine ip
命令获取您的 Docker VM 的 IP 地址并打开 http://${DOCKER_MACHINE_IP}:9229/json
以获取 DevTools URL.
在页面中测试了 React 应用程序的登录功能 class:
async login(t) {
console.log('starting login...');
debugger;
this.logBrowserMessages(t);
await this.loginModal({ visibilityCheck: true });
await t
.expect(this.loginModal.visible)
.ok()
// then log the user in etc...
和测试,当 运行 在本地时通过但在容器中失败
test.requestHooks(mock)('user can log in', async t => {
await page.login(t);
// Make sure test user's orders render.
await t.expect(page.orders.childNodeCount).gt(1, { timeout: 10000 });
测试在本地通过,但在容器中 运行ning 时失败(登录不起作用)。
当我 运行 在本地进行测试时,它会按预期进行调试:
testcafe chrome --inspect-brk=9230 ./tests/login.test.js --skip-js-errors
过程 node_modules/testcafe/lib/cli
出现在我的 chrome://inspect/#devices
中,正如预期的那样。
但是,当我在 testcafe docker 容器中 运行 testcafe 时,它不会使用以下任何命令进行调试:
docker run --expose 9230 -p 9230:9230 -e BASIC_AUTH_USER -e BASIC_AUTH_PASS -e NODE_ENV=docker -e TEST_USER -e TEST_PASS --shm-size=1gb -v `pwd`:/tests -v `pwd`/screenshots/docker:/screenshots testcafe/testcafe 'chromium --no-sandbox' --inspect-brk=0.0.0.0:9230 -S -s '/screenshots' --skip-js-errors /tests/**/login.test.js
docker run --expose 9230 -p 9230:9230 -e \"NODE_PATH=/opt:/opt/testcafe/node_modules:/tests/node_modules\" -e BASIC_AUTH_USER -e BASIC_AUTH_PASS -e NODE_ENV=docker -e TEST_USER -e TEST_PASS --shm-size=1gb -v `pwd`:/tests -v `pwd`/screenshots/docker:/screenshots testcafe/testcafe 'chromium --no-sandbox' --inspect-brk=0.0.0.0:9230 -S -s '/screenshots' --skip-js-errors /tests/**/login.test.js
docker run --expose 9230 -p 9230:9230 -e BASIC_AUTH_USER -e BASIC_AUTH_PASS -e NODE_ENV=docker -e TEST_USER -e TEST_PASS --shm-size=1gb -v `pwd`:/tests -v `pwd`/screenshots/docker:/screenshots testcafe/testcafe 'chromium --no-sandbox' --inspect-brk=127.0.0.1:9230 -S -s '/screenshots' --skip-js-errors /tests/**/login.test.js
docker run --expose 9230 -p 9230:9230 -e \"NODE_PATH=/opt:/opt/testcafe/node_modules:/tests/node_modules\" -e BASIC_AUTH_USER -e BASIC_AUTH_PASS -e NODE_ENV=docker -e TEST_USER -e TEST_PASS --shm-size=1gb -v `pwd`:/tests -v `pwd`/screenshots/docker:/screenshots testcafe/testcafe --inspect-brk=0.0.0.0:9230 --browsers 'chromium --no-sandbox' -S -s '/screenshots' --skip-js-errors /tests/**/login.test.js
docker run --expose 9230 -p 9230:9230 -e \"NODE_PATH=/opt:/opt/testcafe/node_modules:/tests/node_modules\" -e BASIC_AUTH_USER -e BASIC_AUTH_PASS -e NODE_ENV=docker -e TEST_USER -e TEST_PASS --shm-size=1gb -v `pwd`:/tests -v `pwd`/screenshots/docker:/screenshots testcafe/testcafe 'chromium --no-sandbox' -S -s '/screenshots' --skip-js-errors --inspect-brk=9230 /tests/**/login.test.js
我正在使用的容器是否有一些我不知道的限制?我之前在 Docker 容器中调试过 Node 进程 运行ning,我知道这是可以做到的。但那是不久前的事了。我错过了什么吗?
如果您在 Mac 上开发,一种可能性是您需要将主机指定为 host.docker.internal
而不是 127.0.0.1
以便 运行 主机上的服务对容器可见。这可能是本地和容器化测试运行之间的差异之一。
您可以使用NODE_OPTIONS
环境变量来启用远程调试:
docker run -it --rm -p 9229:9229 -e NODE_OPTIONS="--inspect-brk=0.0.0.0:9229" -v /host/path/to/tests:/tests testcafe/testcafe 'chromium --no-sandbox' /tests/test.js
如果您不使用 docker-machine
,您可以在浏览器中打开 http://localhost:9229/json
并导航到 devtoolsFrontendUrl
[=26= 中指定的 DevTools URL ].
否则,请使用 docker-machine ip
命令获取您的 Docker VM 的 IP 地址并打开 http://${DOCKER_MACHINE_IP}:9229/json
以获取 DevTools URL.