Testcafe - 如何让 Docker 镜像到达 localhost:3000

问题描述 投票:0回答:1

我在我的本地机器上运行了一个 webapp (http:localhost:3000)。我正在使用

testcafe docker image
来运行容器

docker run -v ${PWD}/e2e:/tests -it testcafe/testcafe firefox --base-url localhost:3000

我有这个错误

2) Failed to load the page at "http://localhost:3000/changelog".
Increase the value of the "pageRequestTimeout" variable, enable the
"retryTestPages" option, or use quarantine mode to perform additional attempts to
execute this test.
You can find troubleshooting information for this issue at
"https://go.devexpress.com/TestCafe_FAQ_ARequestHasFailed.aspx".

      Error details:
      Failed to find a DNS-record for the resource at "http://localhost:3000/changelog".

我在我的测试中尝试过硬编码

host.docker.internal:3000/path
,但我不想在每次测试中都对该值进行硬编码。

我看到了 这篇文章 但他/她最终为 webapp 创建了一个容器,我想避免这种情况以使本地环境中的测试更加简单

docker dockerfile e2e-testing testcafe
1个回答
2
投票

如果你在 Linux 机器上运行测试,你可以使用 host 网络模式:

docker run --network="host" -v ${PWD}/tests:/tests -it testcafe/testcafe firefox ./tests/test.js --base-url localhost:3000

请确保示例中的 URL 正确(

localhost:300
localhost:3000
)。

© www.soinside.com 2019 - 2024. All rights reserved.