【发布时间】: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没有区别