Search code examples
dockerdockerfilee2e-testingtestcafe

Testcafe - how to allow Docker image to reach localhost:3000


I have running a webapp on my local machine (http:localhost:3000). Im using testcafe docker image to run a container

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

I'm having this error

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".

I tried hardcoding host.docker.internal:3000/path in my test, but I dont want to keep that value hardcoded on every test.

I saw this post but he/she endup up creating a container for the webapp, I want to avoid that in order to make the test in local environment more simple


Solution

  • If you run your tests on a Linux machine, you can use the host network mode:

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

    Please make sure that the URL in your example is correct (localhost:300 or localhost:3000).