如何调试在testcafe/testcafe docker容器中运行的Testcafe浏览器? [英] How do I debug a Testcafe browser running in a testcafe/testcafe docker container?

查看:116
本文介绍了如何调试在testcafe/testcafe docker容器中运行的Testcafe浏览器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Page类中对React应用程序的登录功能进行了测试:

Got a test for a React app's login function in a Page 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... 

该测试在本地运行时通过但在容器中失败

And the test, which passes when running locally but fails in the container

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 });

在容器中运行时,测试在本地通过,但失败(登录不起作用).

The test passes locally but fails (the login doesn't work) when running in the container.

当我在本地运行测试时,它会按预期进行调试:

When I run the test locally it debugs as expected:

testcafe chrome --inspect-brk = 9230 ./tests/login.test.js --skip-js-errors

按预期,进程 node_modules/testcafe/lib/cli 显示在我的 chrome://inspect/#devices 中.

The process node_modules/testcafe/lib/cli shows up in my chrome://inspect/#devices, as expected.

但是,当我在testcafe docker容器中运行testcafe时,将无法使用以下任何命令进行调试:

However, when I run testcafe in the testcafe docker container it won't debug with any of these commands:

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'/屏幕截图的--skip-js-errors --inspect-brk = 9230/tests/**/login.test.js

我所使用的容器是否存在一些我不知道的限制?我之前已经调试了在Docker容器中运行的Node进程,我知道可以做到.但这是前一阵子.我想念什么吗?

Is there some limitation to the container that I'm using that I'm not aware of? I've debugged Node processes running in Docker containers before, I know it can be done. But it was a while ago. Am I missing something?

推荐答案

您可以使用 NODE_OPTIONS 环境变量来启用远程调试:

You can use the NODE_OPTIONS environment variable to enable remote debugging:

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 并导航至在中指定的DevTools URL devtoolsFrontendUrl 属性.

If you don't use docker-machine, you can open http://localhost:9229/json in your browser and navigate to a DevTools URL specified in the devtoolsFrontendUrl property.

否则,使用 docker-machine ip 命令获取Docker VM的IP地址,然后打开 http://$ {DOCKER_MACHINE_IP}:9229/json 到获取一个DevTools URL.

Otherwise, use the docker-machine ip command to get the IP address of your Docker VM and open http://${DOCKER_MACHINE_IP}:9229/json to get a DevTools URL.

这篇关于如何调试在testcafe/testcafe docker容器中运行的Testcafe浏览器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆