【问题标题】:How do I run containerized Cypress runner against containerized server?如何针对容器化服务器运行容器化 Cypress 运行程序?
【发布时间】:2021-07-13 17:04:17
【问题描述】:

我正在尝试针对容器化 Nginx 运行 Cypress 测试:

CONTAINER ID   IMAGE          COMMAND                  CREATED          STATUS          PORTS                                       NAMES
7c3efd24e6e6   tdd_nginx      "/docker-entrypoint.…"   19 minutes ago   Up 19 minutes   0.0.0.0:80->80/tcp, :::80->80/tcp           tdd_nginx_1

从官方docs得知我可以使用docker run -it -v $PWD:/e2e -w /e2e -e CYPRESS_baseUrl=host.docker.internal cypress/included:7.7.0

Here 我了解了host.docker.internal,据说赛普拉斯知道如何在特定容器中查找localhost

Nginx 容器暴露了 80 端口,所以我尝试了 -e CYPRESS_baseUrl=host.docker.internal:80 并且没有指定端口,因为在大多数情况下,80 端口是备用端口。

错误输出:

Cypress could not verify that this server is running:

  > http://host.docker.internal:80

We are verifying this server because it has been configured as your `baseUrl`.

Cypress automatically waits until your server is accessible before running tests.

We will try connecting to it 3 more times...
We will try connecting to it 2 more times...
We will try connecting to it 1 more time...

Cypress failed to verify that your server is running.

Please start this server and then run Cypress again.

将 env 变量移动到 cypress.json 没有任何区别:

{
  "baseUrl": "host.docker.internal",
  "video": false
}

【问题讨论】:

  • 不是CYPRESS_BASE_URL吗?
  • CYPRESS_BASE_URL 没有区别

标签: docker nginx cypress


【解决方案1】:

cypress.json 更改为:

{
  "CYPRESS_BASE_URL": "host.docker.internal",
  "video": false
}

CYPRESS_BASE_URL 解析为环境变量并没有帮助,但将其放入文件中就可以了。奇怪的是,它有所作为。

感谢@jonrsharpe

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-12-20
    • 2020-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-16
    • 1970-01-01
    相关资源
    最近更新 更多