Cypress is unable to find Vagrant provided server in Github Actions

72 views Asked by At

Relevant link: https://github.com/freeipa/freeipa-webui/pull/186

I am trying to run cypress tests on ipa server installed in Vagrant. I output the Vagrant's IP after the installation to /etc/hosts, which, I presume, is a host file used by GitHub runner. However, cypress does not seem to be able to find the running server. Previously (about a month ago), the runners were using 192.168.x.y IP and the vagrant provisioning has been consistently running on an assigned static address. This has changed recently and the vagrant provisioning is running on 10.0.x.y address. With 192.168.x.y address, cypress had no issue finding the server.

What I tried:

  • http and https for baseUrl param of cypress config
  • setting host with the IP as a env param for cypress step (see gating.yml in the PR above)
  • using wait-on with server's url (server.ipa.demo) in gating.yml

Relevant code:

cypress.config.ts

e2e: {
    specPattern: "**/*.feature",
    baseUrl: "http://server.ipa.demo",

gating.yml

      - name: Cache Vagrant boxes
        uses: actions/cache@v3
        with:
          path: ~/.vagrant.d/boxes
          key: ${{ runner.os }}-vagrant-${{ hashFiles('Vagrantfile') }}
          restore-keys: |
            ${{ runner.os }}-vagrant-

      - name: Cleanup running Vagrant boxes in case they are running
        run: vagrant destroy --force

      - name: Run vagrant up
        run: vagrant up --no-provision

      - name: Run vagrant provision
        run: vagrant provision

      - name: Put IPA Server's IP to /etc/hosts
        run: sudo echo "$(vagrant ssh -c "hostname -I") server.ipa.demo" | sudo tee -a /etc/hosts

      - name: Save server's IP address to env
        run: echo "SERVER_IP=$(vagrant ssh -c "hostname -I")" >> $GITHUB_ENV

      - name: Print exported variable
        run: echo "$SERVER_IP"

      - name: Run Cypress tests
        uses: cypress-io/github-action@v6
        with:
          browser: firefox
          env: host="https://${{ env.SERVER_IP  }}"

The error:

Cypress could not verify that this server is running:

  > https://server.ipa.demo/

We are verifying this server because it has been configured as your baseUrl.

Cypress automatically waits until your server is accessible before running tests.

We will try connecting to it 3 more times...
We will try connecting to it 2 more times...
We will try connecting to it 1 more time...
2

There are 2 answers

0
Michal Polovka On BEST ANSWER

I have managed to resolve this issue using following steps:

  1. replace mac-os runner by ubuntu.

When running Vagrant from mac-os, Vagrant was assigned only 10.0.2.15 address, which was not usable for connecting to the server running in Vagrant.

When using ubuntu, Vagrant gets assigned both 10.0.2.15 and 192.168.x.y addresses, where 192... works in the internal network.

  1. For putting servers IP address into /etc/hosts, I have used following step
      - name: Put IPA Server's IP to /etc/hosts
        run: sudo echo "$(vagrant ssh -c "hostname -I|sed 's/10\.0\.2\.15//'") server.ipa.demo" | sudo tee -a /etc/hosts

You can see PR#186 for details.

0
TesterDick On

I would say you just need to edit /etc/hosts.

This is a section from my file, shows the mapping of real IP to named address.

# Added by Docker Desktop
192.168.1.83 host.docker.internal
192.168.1.83 gateway.docker.internal

From your description you currently have the following mapping, and that used to work

192.168.x.y server.ipa.demo

but now the IP has changed you just need to edit the file (as administrator) to

10.0.x.y server.ipa.demo

Note that Cypress is just pinging the baseUrl you provide, and leaving it up to the system to find the server, so there's nothing to configure from the Cypress end.


I notice from the pull request you reference above that you already know this, so I'm wondering what you are looking for - is it a way to bypass /etc/hosts?

# Needed by Cypress - optional if you edit your /etc/hosts
config.vm.network "forwarded_port", guest: 443, host: 443
config.vm.network "forwarded_port", guest: 80, host: 80

Perhaps you can do it with this config github-action/.github/workflows /example-config.yml

      - name: Run Cypress tests
        uses: cypress-io/github-action@v6
        with:
          browser: firefox
          config: baseUrl=https://${{ env.SERVER_IP  }}

or assign the env var to Cypress config in cypress.config.js

const {defineConfig} = require('cypress')

module.exports = defineConfig({
  e2e: {
    setupNodeEvents(on, config) {
      config.baseUrl = process.env.SERVER_IP
      return config 
    }
  }
})