Search code examples
cypressgithub-actionspipeline

Unexpected value "with" in the yml file in the GitHub actions pipeline


While running the Cypress tests, getting below error in GitHub action pipeline: The workflow is not valid. .github/workflows/main.yml (Line: 44, Col: 9): Unexpected value 'with'. Could someone please advise how can we add browser : chrome in the yml file at the with: level.

name: Cypress Automation Tests
    
    on:
      pull_request:
        types: [opened, synchronize, reopened]
      push:
        branches: [develop]
    
    env:
      
      CYPRESS_BOOKING_FREE_USER_PASSWORD: ${{ secrets.CYPRESS_BOOKING_FREE_USER_PASSWORD }}
      
    
    jobs:
      install:
        runs-on: ubuntu-22.04
        steps:
          - name: Checkout
            uses: actions/checkout@v2
          - name: Install dependencies
            uses: cypress-io/github-action@v2
            with:
              # just perform install
              runTests: false
    
      tests:
        runs-on: ubuntu-22.04
        needs: install
        steps:
          - name: Check out code
            uses: actions/checkout@v2
          # we re-install the dependencies
          - name: Install dependencies
            uses: cypress-io/github-action@v2
            with:
              # just perform install
              runTests: false
    
          - name: Run Automation tests
            run: npm run cy:run -- --env grepTags="@Envtest1",ENV="staging"
            with:
              browser: chrome
          - name: Upload Results
            uses: actions/upload-artifact@v3
            if: failure()
            with:
              name: cypress-screenshots
              path: cypress/screenshots
          - uses: actions/upload-artifact@v2
            if: always()
            with:
              name: cypress-videos
              path: cypress/videos

Solution

  • The with option isn't compatible with the run command you gave above it.

    But it's ok to use --browser Cypress command line option, same as local cy:run command

    Ref: cypress run --browser

    cypress run --browser chrome
    

    The pipeline (abbreviated to make it clearer)

    jobs:
      install:
        runs-on: ubuntu-22.04
        steps:
          ...
    
      tests:
        runs-on: ubuntu-22.04
        needs: install
        steps:
          ...
          - name: Run Automation tests
            run: npm run cy:run -- --browser chrome --env grepTags="@Envtest1",ENV="staging"