Reputation: 131
I have a set of cypress e2e tests. The code for these tests lives in their own git repo.
When executing these tests manually through cypress cli I can hit different URL's based on environment DEV/QA/STG and PROD.
I can run the application locally but prefer not to and what I want to do is execute the tests inside the container and have them access the application outside of the container.
In trying to accomplish this I have started the application locally on port 4200. My cypress config has the base url property set in its config file and I can successfully run the tests from the Cypress cli (not in docker).
In my cypress test repo, I have the following Dockerfile
FROM cypress/base:12.18.4
RUN mkdir /app
WORKDIR /app
COPY . /app
RUN npm install
RUN $(npm bin)/cypress verify
RUN ["npm","run","cypress:run"]
Executing docker run
I see the following error.
#12 6.411 Cypress could not verify that this server is running:
#12 6.411
#12 6.411 > http://localhost:4200/
#12 6.411
#12 6.411 We are verifying this server because it has been configured as your `baseUrl`.
#12 6.411
#12 6.411 Cypress automatically waits until your server is accessible before running tests.
#12 6.411
#12 6.411 We will try connecting to it 3 more times...
#12 9.417 We will try connecting to it 2 more times...
#12 12.42 We will try connecting to it 1 more time...
#12 12.42
#12 16.43 Cypress failed to verify that your server is running.
Not entirely sure how to "allow" tests to reach out to my localhost:4200
Kind of feel I need to create a docker-compose file but not sure about the networking details.
Any help or thought greatly appreciated
Upvotes: 1
Views: 4949
Reputation: 31
Maybe this one can be helpful too.
In your cypress.json you can set:
"baseUrl": "http://host.docker.internal:4200"
In this case, your cypress tests will run against the localhost of your machine on which the docker container is running with port 4200.
It means you tell docker to use the localhost of the host machine.
Upvotes: 3
Reputation: 156
Just add --network host
key to your docker run
command:
docker run --name cypress --network host cypress/base:12.18.4
https://docs.docker.com/network/network-tutorial-host/
Upvotes: 2