|
| 1 | +name: onRouteBC Specification Tests |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + ### Required |
| 7 | + target: |
| 8 | + description: 'PR number, test, uat or prod.' |
| 9 | + default: 'test' |
| 10 | + required: true |
| 11 | + type: string |
| 12 | + show_artifact: |
| 13 | + description: 'boolean to show artifacts on run (default is on failure)' |
| 14 | + default: false |
| 15 | + required: true |
| 16 | + type: boolean |
| 17 | + workflow_dispatch: |
| 18 | + inputs: |
| 19 | + ### Required |
| 20 | + target: |
| 21 | + description: 'PR number, test, uat or prod.' |
| 22 | + default: 'test' |
| 23 | + required: true |
| 24 | + type: string |
| 25 | + show_artifact: |
| 26 | + description: 'boolean to show artifacts on run (default is on failure)' |
| 27 | + default: false |
| 28 | + required: true |
| 29 | + type: boolean |
| 30 | + |
| 31 | + |
| 32 | +jobs: |
| 33 | + vars: |
| 34 | + name: Set Variables |
| 35 | + outputs: |
| 36 | + target: ${{ steps.env.outputs.target }} |
| 37 | + environment: ${{ steps.env.outputs.environment }} |
| 38 | + runs-on: ubuntu-22.04 |
| 39 | + steps: |
| 40 | + - name: env |
| 41 | + id: env |
| 42 | + run: | |
| 43 | + pr="${{inputs.target}}" |
| 44 | + pr=${pr,,} |
| 45 | + if [[ $pr != 'test' && $pr != 'demo' && $pr != 'uat' && $pr != 'prod' ]]; then |
| 46 | + target="$pr" |
| 47 | + environment="dev" |
| 48 | + else |
| 49 | + target=${{inputs.target}} |
| 50 | + environment=${{inputs.target}} |
| 51 | + fi |
| 52 | + echo "target=$target" >> $GITHUB_OUTPUT |
| 53 | + echo "environment=$environment" >> $GITHUB_OUTPUT |
| 54 | +
|
| 55 | +
|
| 56 | + name: ${{matrix.test}}-${{matrix.role}}-${{matrix.browser}} |
| 57 | + needs: [vars] |
| 58 | + environment: ${{needs.vars.outputs.environment}} |
| 59 | + runs-on: ubuntu-22.04 |
| 60 | + defaults: |
| 61 | + run: |
| 62 | + working-directory: tests/ |
| 63 | + strategy: |
| 64 | + fail-fast: false |
| 65 | + matrix: |
| 66 | + browser: |
| 67 | + - chrome |
| 68 | + #- edge |
| 69 | + #- firefox |
| 70 | + test: |
| 71 | + - 'copy-permit.cy.js' |
| 72 | + role: [PC, SA, TRAIN, CTPO, CA, PA] |
| 73 | + |
| 74 | + timeout-minutes: 10 |
| 75 | + steps: |
| 76 | + - uses: actions/checkout@v4 |
| 77 | + |
| 78 | + - name: Load credentials for ${{ matrix.role }} |
| 79 | + id: creds |
| 80 | + run: | |
| 81 | + # Dynamically fetch secrets using GitHub Actions syntax |
| 82 | + echo "CYPRESS_USERNAME=${{ vars[format('USERNAME_{0}', matrix.role)] }}" >> $GITHUB_ENV |
| 83 | + echo "CYPRESS_PASSWORD=${{ secrets[format('PASSWORD_{0}', matrix.role)] }}" >> $GITHUB_ENV |
| 84 | +
|
| 85 | + - name: Run Cypress tests for ${{ matrix.role }} |
| 86 | + uses: cypress-io/github-action@v6.9.2 |
| 87 | + env: |
| 88 | + CYPRESS_baseUrl: https://${{ github.event.repository.name }}-${{ needs.vars.outputs.target || 'test' }}-frontend.apps.silver.devops.gov.bc.ca/ |
| 89 | + CYPRESS_wait_time: 2000 |
| 90 | + CYPRESS_user_role: ${{matrix.role}} |
| 91 | + CYPRESS_username: ${{env.CYPRESS_USERNAME}} |
| 92 | + CYPRESS_password: ${{env.CYPRESS_PASSWORD}} |
| 93 | + with: |
| 94 | + browser: ${{ matrix.browser }} |
| 95 | + config: pageLoadTimeout=10000,video=true |
| 96 | + spec: cypress/e2e/smoke/${{matrix.test}} |
| 97 | + working-directory: tests |
| 98 | + |
| 99 | + - uses: actions/upload-artifact@v4 |
| 100 | + if: failure() || inputs.show_artifact |
| 101 | + with: |
| 102 | + name: ${{matrix.test}}-${{matrix.role}}-${{matrix.browser}} screenshot |
| 103 | + path: tests/cypress/screenshots/ |
| 104 | + if-no-files-found: ignore # 'warn' or 'error' are also available, defaults to `warn` |
| 105 | + |
| 106 | + - uses: actions/upload-artifact@v4 |
| 107 | + if: failure() || inputs.show_artifact |
| 108 | + with: |
| 109 | + name: ${{matrix.test}}-${{matrix.role}}-${{matrix.browser}} video |
| 110 | + path: tests/cypress/videos/ |
| 111 | + overwrite: true |
| 112 | + if-no-files-found: ignore # 'warn' or 'error' are also available, defaults to `warn` |
| 113 | + |
0 commit comments