Update page copy #185
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# I've customized the Playwright configuration for GitHub Actions | |
# to omit 'sloMo' and 'headed' modes used in my local environment, | |
# ensuring my configuration files remain consistent. This approach | |
# resolves the issue of having uncommitted changes to the configuration file. | |
# Additionally, I excluded a specific file from running in GitHub Actions | |
# by adding it to 'testIgnore' in the actions configuration. | |
# | |
# To achieve this, I created a repository variable in the GitHub repo settings, | |
# which is utilized in the YAML below. Further down, you'll notice that | |
# I've used the '--config' flag to specify this variable when starting the tests. | |
# | |
# If you explore the root of the test-playwright repo, you'll find two separate | |
# configuration files. | |
# playwright.actions.config.ts (for GitHub Actions) | |
# playwright.config.ts (for running tests locally) | |
name: Playwright GitHub Page (manual, pr/push) | |
env: | |
PLAYWRIGHT_ACTIONS_CONFIG: ${{ vars.PLAYWRIGHT_ACTIONS_CONFIG }} | |
on: | |
push: | |
pull_request: | |
workflow_dispatch: | |
jobs: | |
Playwright-GitHub-Page-Test: | |
runs-on: ubuntu-latest | |
timeout-minutes: 3 | |
steps: | |
- name: Message | |
run: | | |
echo "This action executes Playwright tests against pull requests and commits" | |
echo "Configuration: playwright.actions.config.ts" | |
echo "User: [${{ github.actor }}] initiated this test run" | |
echo "Commit subject: ${{ github.event.commits[0].message }}" | |
echo "Commit hash: ${{ github.sha }}" | |
echo "Branch: ${{ github.ref_name }}" | |
echo "GitHub workflow run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" | |
# We will check out two repos because the website files | |
# exist in one repo and Playwright exists in a different repo | |
# Check out primary repo where I will start a server locally in the GH Runner environment | |
- name: Checkout Website Repo | |
uses: actions/checkout@v4.1.6 | |
# Check out secondary repo where Playwright scripts live | |
- name: Checkout Playwright Repo | |
uses: actions/checkout@v4.1.6 | |
with: | |
repository: readytotest/test-playwright | |
#token: ${{ secrets.GH_PAT }} If checking out a private repo, create a secret called `GH_PAT` that contains your personal access token | |
ref: main | |
path: ./playwright-tests #Copy the Playwright repo to this directory within the GitHub page repo | |
- name: List current directory | |
run: ls | |
- name: Install dependencies | |
working-directory: ./playwright-tests #This is the sub-directory where the Playwright repo was copied to | |
run: npm ci | |
- name: Setup Node.js environment with most recent version | |
uses: actions/setup-node@v4.0.2 | |
with: | |
node-version: 'latest' | |
- name: Start Local Webserver in GH Runner environment (http://localhost:3000) | |
run: | #We need the & sleep 1 or it will hang on this step and won't progress | |
chmod +x start-server.sh | |
./start-server.sh & | |
sleep 1 | |
- name: CD to playwright-tests directory, print node version, and list contents | |
run: | | |
cd playwright-tests | |
node -v | |
ls | |
- name: Install Playwright Browsers | |
working-directory: ./playwright-tests #This is the sub-directory where the Playwright repo was copied to | |
run: npx playwright install --with-deps | |
- name: Run Playwright tests | |
working-directory: ./playwright-tests #This is the sub-directory where the Playwright repo was copied to | |
#Tests against http://localhost:3000 | |
run: npx playwright test --config $PLAYWRIGHT_ACTIONS_CONFIG | |
- name: Upload Report to GitHub | |
uses: actions/upload-artifact@v4.3.3 | |
if: always() | |
with: | |
name: Test Results + Video | |
path: ./playwright-tests/playwright-report/ | |
if-no-files-found: warn | |
retention-days: 60 |