GN.
GN.

Reputation: 9829

Run end to end tests on Github actions

How to run end-to-end tests on Github actions?

I'm trying to figure out how to start a server, so that the end-to-end test suite can run on it.

In our example we have a Rails app that has some Cucumber and Cypress tests.

Upvotes: 5

Views: 3105

Answers (1)

tokto
tokto

Reputation: 156

You could try running a server using Python's http.server or start a rails server.

First, create a path .github/workflows in your app's root and then create a test.yaml file inside /workflows.

Add the basic configuration for Ruby, something along the lines of:

# .github/workflows/test.yml

name: Test
on: push  # Trigger on push

jobs:
  test:
    name: Run tests
    runs-on: ubuntu-16.04 # Specific version for Cypress

    steps:
    - name: Checkout repository
      uses: actions/checkout@v2
    - name: Set up Ruby
      uses: ruby/setup-ruby@v1
      with: 
        ruby-version: '2.6' # Specify your version
    - name: Cache gems # You can cache your gems to make the workflow run faster
      uses: actions/cache@v2
      with:
        path: vendor/bundle
        key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
        restore-keys: |
          ${{ runner.os }}-gems-
    - name: Install gems
      run: |
        bundle config path vendor/bundle
        bundle install --jobs 4 --retry 3

    - name: Start server in the background
      run: |
        bundle exec rails server &
        sleep 5 && 
        curl http://localhost:3000 -I

    # Add step for running cucumber tests here
    
    - name: Run Cypress
      uses: cypress-io/github-action@v1
      with:
        browser: chrome
        headless: true
    - name: Upload screenshots as artifacts
      uses: actions/upload-artifact@v1
      if: failure()
      with:
        name: cypress-screenshots
        path: cypress/screenshots
    - name: Upload videos as artifacts
      uses: actions/upload-artifact@v1
      if: always()
      with:
        name: cypress-videos
        path: cypress/videos

When you commit the file and push, head over to your github repo's Action tab to check if it works or if you need to debug.

Also, I recommend you check out this article https://boringrails.com/articles/building-a-rails-ci-pipeline-with-github-actions/.

Upvotes: 6

Related Questions