|
| 1 | +name: Playwright Tests |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + pull_request: |
| 6 | + branches: [ releaseCandidate, beta, main ] |
| 7 | + push: |
| 8 | + branches: [ releaseCandidate, beta, main ] |
| 9 | + |
| 10 | +jobs: |
| 11 | + # Fork PRs: run tests with mocks (no access to secrets) |
| 12 | + test-mocked: |
| 13 | + if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == true |
| 14 | + timeout-minutes: 60 |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - uses: actions/checkout@v6 |
| 18 | + |
| 19 | + - name: Setup Node.js |
| 20 | + uses: actions/setup-node@v6 |
| 21 | + with: |
| 22 | + node-version: '24' |
| 23 | + cache: 'npm' |
| 24 | + |
| 25 | + - name: Restore node_modules cache |
| 26 | + id: cache-npm |
| 27 | + uses: actions/cache@v5 |
| 28 | + with: |
| 29 | + path: ~/.npm |
| 30 | + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} |
| 31 | + restore-keys: | |
| 32 | + ${{ runner.os }}-build-${{ env.cache-name }}- |
| 33 | + ${{ runner.os }}-build- |
| 34 | + ${{ runner.os }}- |
| 35 | +
|
| 36 | + - name: Install dependencies |
| 37 | + run: npm ci |
| 38 | + |
| 39 | + - name: Install Playwright Browsers |
| 40 | + run: npx playwright install chromium |
| 41 | + |
| 42 | + - name: Run Playwright tests (mocked) |
| 43 | + run: npm run test:e2e:mock |
| 44 | + |
| 45 | + - uses: actions/upload-artifact@v4 |
| 46 | + if: always() |
| 47 | + with: |
| 48 | + name: playwright-report-mocked |
| 49 | + path: playwright-report/ |
| 50 | + retention-days: 30 |
| 51 | + |
| 52 | + # Repo PRs + manual dispatch + post-merge push: run tests against real org |
| 53 | + test-real-org: |
| 54 | + if: >- |
| 55 | + github.event_name == 'workflow_dispatch' |
| 56 | + || github.event_name == 'push' |
| 57 | + || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork != true) |
| 58 | + timeout-minutes: 60 |
| 59 | + runs-on: ubuntu-latest |
| 60 | + steps: |
| 61 | + - uses: actions/checkout@v6 |
| 62 | + |
| 63 | + - name: Setup Node.js |
| 64 | + uses: actions/setup-node@v6 |
| 65 | + with: |
| 66 | + node-version: '24' |
| 67 | + cache: 'npm' |
| 68 | + |
| 69 | + - name: Restore node_modules cache |
| 70 | + id: cache-npm |
| 71 | + uses: actions/cache@v5 |
| 72 | + with: |
| 73 | + path: ~/.npm |
| 74 | + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} |
| 75 | + restore-keys: | |
| 76 | + ${{ runner.os }}-build-${{ env.cache-name }}- |
| 77 | + ${{ runner.os }}-build- |
| 78 | + ${{ runner.os }}- |
| 79 | +
|
| 80 | + - name: Setup Salesforce CLI and authenticate |
| 81 | + if: ${{ vars.SF_TEST_MOCKENABLED == 'false' }} |
| 82 | + env: |
| 83 | + SF_CLI_URL: ${{ vars.SF_CLI_URL }} |
| 84 | + SF_TEST_APIVERSION: ${{ vars.SF_TEST_APIVERSION }} |
| 85 | + SF_TEST_MOCKENABLED: ${{ vars.SF_TEST_MOCKENABLED }} |
| 86 | + SF_TEST_ACCOUNTID: ${{ vars.SF_TEST_ACCOUNTID }} |
| 87 | + SF_TEST_FLOWID: ${{ vars.SF_TEST_FLOWID }} |
| 88 | + SF_TEST_FLOWDEFID: ${{ vars.SF_TEST_FLOWDEFID }} |
| 89 | + SF_AUTH_URL: ${{ secrets.SF_AUTH_URL }} |
| 90 | + run: | |
| 91 | + # Install Salesforce CLI |
| 92 | + echo "Installing Salesforce CLI from $SF_CLI_URL" |
| 93 | + wget $SF_CLI_URL -O sf-cli.tar.xz |
| 94 | + mkdir -p sf-cli |
| 95 | + tar xJf sf-cli.tar.xz -C sf-cli --strip-components=1 |
| 96 | + echo "$PWD/sf-cli/bin" >> $GITHUB_PATH |
| 97 | + export PATH="$PWD/sf-cli/bin:$PATH" |
| 98 | + sf --version |
| 99 | + |
| 100 | + # Authenticate and get access token |
| 101 | + echo "Authenticating to Salesforce org using SF_AUTH_URL..." |
| 102 | + echo $SF_AUTH_URL > ./SFDX_AUTH_URL.txt |
| 103 | + sf org login sfdx-url -f ./SFDX_AUTH_URL.txt -a cicdorg -d |
| 104 | +
|
| 105 | + # Display the authenticated org and extract the access token and instance url |
| 106 | + echo "Extracting authentication information..." |
| 107 | + ORG_INFO=$(sf org display --json -o cicdorg 2>/dev/null) |
| 108 | + SF_EXIT_CODE=$? |
| 109 | + |
| 110 | + if [ $SF_EXIT_CODE -ne 0 ]; then |
| 111 | + echo "Error: sf org display failed with exit code $SF_EXIT_CODE" |
| 112 | + exit 1 |
| 113 | + fi |
| 114 | + |
| 115 | + # Check if we got valid JSON |
| 116 | + if [ -z "$ORG_INFO" ]; then |
| 117 | + echo "Error: sf org display returned empty output" |
| 118 | + exit 1 |
| 119 | + fi |
| 120 | + |
| 121 | + ACCESS_TOKEN=$(echo "$ORG_INFO" | jq -r '.result.accessToken // empty' 2>/dev/null) |
| 122 | + INSTANCE_URL=$(echo "$ORG_INFO" | jq -r '.result.instanceUrl // empty' 2>/dev/null) |
| 123 | + |
| 124 | + if [ -z "$ACCESS_TOKEN" ]; then |
| 125 | + echo "Error: Could not extract access_token from auth response" |
| 126 | + exit 1 |
| 127 | + fi |
| 128 | + |
| 129 | + # Mask the token so it never appears in logs |
| 130 | + echo "::add-mask::$ACCESS_TOKEN" |
| 131 | + |
| 132 | + # Extract hostname from instance URL |
| 133 | + if [ -n "$INSTANCE_URL" ]; then |
| 134 | + SF_HOST=$(echo "$INSTANCE_URL" | sed 's|https\?://||' | sed 's|/.*||') |
| 135 | + else |
| 136 | + echo "Error: Could not determine Salesforce instance URL" |
| 137 | + exit 1 |
| 138 | + fi |
| 139 | + |
| 140 | + if [ -z "$SF_HOST" ]; then |
| 141 | + echo "Error: Could not determine Salesforce hostname" |
| 142 | + exit 1 |
| 143 | + fi |
| 144 | + |
| 145 | + # Generate test-constants.local.js with real credentials |
| 146 | + echo "Generating tests/e2e/test-constants.local.js..." |
| 147 | + printf '%s\n' \ |
| 148 | + 'export const TEST_CONSTANTS = {' \ |
| 149 | + ' mockHost: "'"$SF_HOST"'",' \ |
| 150 | + ' mockToken: "'"$ACCESS_TOKEN"'",' \ |
| 151 | + ' apiVersion: "'"$SF_TEST_APIVERSION"'",' \ |
| 152 | + ' accountRecordId: "'"$SF_TEST_ACCOUNTID"'",' \ |
| 153 | + ' accountRecordName: "Test Account 1",' \ |
| 154 | + ' testUserSearchTerm: "Integration User",' \ |
| 155 | + ' flowId: "'"$SF_TEST_FLOWID"'",' \ |
| 156 | + ' flowDefId: "'"$SF_TEST_FLOWDEFID"'",' \ |
| 157 | + ' mockEnabled: '"$SF_TEST_MOCKENABLED" \ |
| 158 | + '};' > tests/e2e/test-constants.local.js |
| 159 | +
|
| 160 | + - name: Install dependencies |
| 161 | + run: npm ci |
| 162 | + |
| 163 | + - name: Install Playwright Browsers |
| 164 | + run: npx playwright install chromium |
| 165 | + |
| 166 | + - name: Run Playwright tests |
| 167 | + run: npm run test:e2e |
| 168 | + |
| 169 | + - uses: actions/upload-artifact@v4 |
| 170 | + if: always() |
| 171 | + with: |
| 172 | + name: playwright-report |
| 173 | + path: playwright-report/ |
| 174 | + retention-days: 30 |
0 commit comments