mardi 4 août 2020

Cypress could not load my webpage when using Docker and Docker compose

This is my docker-compose.yml file:

version: '3.7'
services:
  pa-portal:
    image: my_app
    volumes:
      - productDB:/web_app/db
    ports:
      - "8080:8080"
  cypress:
    image: "cypress/included:4.4.0"
    depends_on:
      - pa-portal
    environment:
      - CYPRESS_baseUrl=http://pa-portal::8080
    working_dir: /web_app-tests

    volumes:
      - ./:/web_app-tests

volumes:
  productDB:

When I do docker-compose up on my command line (in the Cypress directory) the tests do run (which means, with the help of the depends_on stanza, that pa-portal is up and running) but they fail because cy.visit() is failing with the error message :CypressError: cy.visit() must be called with a url or an options object containing a url as its 1st argument

I don't get why this is happening as I have set the baseUrl.

I have tried removing this part of the docker-compose file:

environment:
  - CYPRESS_baseUrl=http://pa-portal::8080

and doing cy.visit("pa-portal:8080") in my tests but still no luck - this time it tells me that it can't find it fails to make the request to pa-portal:

cypress_1    |   My Test Suite
    1) "before each" hook for "new sale"
cypress_1    | 
cypress_1    | 
cypress_1    |   0 passing (273ms)
cypress_1    |   1 failing
cypress_1    | 
cypress_1    |   1) My Test Suite "before each" hook for "new sale":
cypress_1    |      CypressError: `cy.visit()` failed trying to load:
cypress_1    | 
cypress_1    | pa-portal:8080
cypress_1    | 
cypress_1    | We attempted to make an http request to this URL but the request failed without a response.
cypress_1    | 
cypress_1    | We received this error at the network level:
cypress_1    | 
cypress_1    |   > Error: Invalid protocol: pa-portal:

I would have thought that accessing the web app through "pa-portal:8080" would work considering both services (pa-portal and cypress) will be on the same default network so they can talk to each other this way.

Another thing which I am finding odd is that "localhost:8080" works just fine in a browser on my host machine which I wasn't expecting at all, as the service is called "pa-portal". I feel like I may be missing some fundamental knowledge about services/networks in Docker and Docker-compose.

Aucun commentaire:

Enregistrer un commentaire