How to change baseURL during tests in cypress-io/github-actions

240 Views Asked by At

I'm trying to run my Cypress tests using Github Actions. I have everything set up but I have a problem with baseURL variable which is set during GitubActions process and then passed to Cypress. In my case it is an ip and port address to the server on which the tested application will be running (it can be running on different servers). This baseURL is then used to check if the server is running and also it is used in tests as a URL for API requests. The problem is that I need to send some API requests to an address with different port number. I think my problem would be solved if one of the following things would be possible:

  1. Cypress would skip verifying if server configured as baseURL is running
  2. I could change (slice) baseURL once server verification is over (either during Github Actions process or in Cypress code)

Does anyone know if one of the things above is possible and if so how to do it?

I've tried to search how to skip cypress server verification or change baseURL passed from GithubActions process to Cypress but I couldn't find an answer

1

There are 1 best solutions below

2
A.Plank On

The details of your test are missing, but three things you can do wrt to this are

  • change baseUrl anywhere in the test suite with Cypress.config('baseUrl', newUrl)

  • omit baseUrl from cypress.config.js to skip the server check

  • use env section of config to set the API url (fully qualified) to stop cy.request() using baseUrl

    cy.request(`${Cypress.env('apiUrl')}/${item}`)
    

REF: request

url (String)

If you do not provide a fully qualified domain name (FQDN) URL, Cypress will make its best guess as to which host you want cy.request() to use in the URL.


baseUrl in YML

If you're doing something like this (from Cypress' repo example)

    # example with web application build
    # and several services to start
    runs-on: ubuntu-22.04
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Cypress tests
        uses: ./
        with:
          working-directory: examples/start
          build: npm run build
          # single start command per line
          start: |
            npm start
            npm run start2
          wait-on: 'http://localhost:8000'
          config: 'baseUrl=http://localhost:8000'   <-- DO NOT SET HERE 

don't do that either.

As I mentioned already, set the baseUrl only after the test suite has started - that will avoid the error on server check.