我正在尝试对容器化的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
我了解到了host.docker.internal,据说Cypress知道如何在特定的容器中查找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.将环境变量移到cypress.json中并没有什么不同:
{
"baseUrl": "host.docker.internal",
"video": false
}发布于 2021-07-14 01:20:10
将cypress.json更改为:
{
"CYPRESS_BASE_URL": "host.docker.internal",
"video": false
}将CYPRESS_BASE_URL解析为环境变量无济于事,但将其放入文件中确实起到了作用。奇怪的是,这会带来不同的结果。
感谢@jonrsharpe
https://stackoverflow.com/questions/68366645
复制相似问题