skip to Main Content

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

3

Answers


  1. Your yml code looks ok to me. This is a formatting issue.

    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:
              runTests: false
      tests:
        runs-on: ubuntu-22.04
        needs: install
        steps:
          - name: Check out code
            uses: actions/checkout@v2
          - name: Install dependencies
            uses: cypress-io/github-action@v2
            with:
              runTests: false
          - name: Run Automation tests
            run: npm run cy:run -- --env grepTags="@Envtest1",ENV="staging"
            uses: ./
            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
    

    Checked this on an online formatter –

    Yml formatter

    Login or Signup to reply.
  2. 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" 
    
    Login or Signup to reply.
  3. @Paolo is correct, you can’t use with: on a bash command step. But just to explain a bit more:

    with: is only appropriate for steps that use another action.

    For example, your "Check out code" step calls a standard action,

    steps:
      - name: Check out code
        uses: actions/checkout@v2
    

    and you could add with: sections to provide custom input to that

    The following is the top of Github’s checkout action. The inputs: listed there correspond to the valid with: sections in your own workflow

    name: 'Checkout'
    description: 'Checkout a Git repository at a particular version'
    inputs:
      repository:
        description: 'Repository name with owner. For example, actions/checkout'
        default: ${{ github.repository }}
      ref:
        description: >
          The branch, tag or SHA to checkout. When checking out the repository that
          triggered a workflow, this defaults to the reference or SHA for that
          event.  Otherwise, uses the default branch.
      token:
        description: >
          Personal access token (PAT) used to fetch the repository. The PAT is configured
          with the local git config, which enables your scripts to run authenticated git
          commands. The post-job step removes the PAT.
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search