This repository contains end-to-end UI tests using Playwright with TypeScript and Jest.
- Node.js (LTS version recommended)
- IDE or editor of choice
π Documentation: Fork a repository
git clone https://github.com/$yourGitHubUsername/gha-typescript-playwright.git
cd gha-typescript-playwright
npm install
npx playwright install --with-deps
npx playwright test
Each exercise has:
- Detailed instructions
- Link(s) to relevant GitHub Actions (and other) documentation
π Workflow file: .github/workflows/01-basic-workflow.yaml
π‘ Goal: Understand workflow structure and manually trigger a workflow.
- Inside the
.github/workflows/
directory, create a new file01-basic-workflow.yaml
. - Define a workflow that:
- Can be triggered manually
- Runs a simple print command
- Commit & push the workflow.
- Trigger the workflow manually from GitHub Actions.
- Observe the logs.
π Relevant Documentation:
π Workflow file: .github/workflows/02-run-tests.yaml
π‘ Goal: Run Playwright tests in GitHub Actions.
- Create a workflow file that:
- Runs Playwright tests on every push to
main
.
- Runs Playwright tests on every push to
- Commit & push the workflow.
- Observe test execution in GitHub Actions logs.
π Relevant Documentation:
- Events that trigger workflows
- Using jobs in a workflow
- Adding scripts to your workflow
- Playwright: Setting up CI
π Workflow file: .github/workflows/03-cache-dependencies.yaml
π‘ Goal: Cache dependencies to speed up workflow execution.
- Create a workflow file (based on
02-run-tests.yaml
) that:- Caches dependencies to avoid reinstalling them on every run.
- Restores the cache if available, otherwise installs dependencies as usual.
- Commit & push the workflow.
- Observe the caching mechanism in the GitHub Actions logs.
π Relevant Documentation:
π Workflow file: .github/workflows/04-upload-reports.yaml
π‘ Goal: Store test results (screenshots, logs) as GitHub Actions artifacts.
- Create a workflow file (based on
03-cache-dependencies.yaml
), that uploads the following folders:- For TypeScript:
playwright-report
andtest-results
- For Java:
target/reports
andtarget/surefire-reports
- For TypeScript:
- Commit & push changes. 3Run the tests and check artifacts in GitHub Actions UI.
π Relevant Documentation:
π Workflow file: .github/workflows/05-show-report.yaml
π‘ Goal: Display test results directly in the GitHub Actions summary tab.
- Create a workflow file (based on
03-cache-dependencies.yaml
), that displays the HTML test report using an action such asphoenix-actions/test-reporting@v15
or a similar alternative.- For Java: Use the report file
target/reports/surefire.html
- For TypeScript: Use the report file
playwright-report/index.html
- For Java: Use the report file
- Commit & push changes.
- Observe the test report preview in the GitHub Actions summary tab.
π Relevant Documentation:
π Workflow file: .github/workflows/06-run-on-pr.yaml
π‘ Goal: Automatically test pull requests.
- Create a workflow file (based on
03-cache-dependencies.yaml
) - Modify the workflowβs
on:
field to trigger tests on pull requests. - Create a new branch, modify a test, and open a pull request.
- Observe the test execution in GitHub Actions.
π Relevant Documentation:
π‘ Goal: Prevent merging if tests fail.
- Ensure your workflow is set up to run tests on pull requests (e.g., using your existing
.github/workflows/05-run-on-pr.yaml
file). - In GitHub, enable "Require status checks to pass before merging" (classic protection rule) for your branch.
- Test the setup by pushing a commit that intentionally fails a test.
- βNote: This setup only works if you have a paid GitHub plan.
- π‘Note: For organizations on GitHub Team/Enterprise, you can also use branch rulesets.
π Relevant Documentation:
π Workflow file: .github/workflows/08-custom-action.yaml
π‘ Goal: Create and use a custom GitHub Action.
-
Edit your workflow to simulate Playwright test output and use the custom action to process it.
See hints
Create a directory
test-results
and generates a test report filereport.txt
inside it.
Write fake test results to the file, simulating passed and failed tests. -
Inside
.github/actions/
, create a folderplaywright-summary
. -
Inside the folder, create
action.yaml
and define a composite action that processes Playwright test results.See hints
The custom action processes the
test-results/report.txt
file, extracts its content, and formats a summary for display in GitHub job summaries. -
Commit & push your changes.
-
Observe the formatted test summary in the GitHub Actions logs.
β¨ Note: Feel free to come up with an own idea and implement it as custom action.
π Relevant Documentation:
π Workflow file: .github/workflows/09-scheduled-regression.yaml
π‘ Goal: Set up a workflow that automatically runs on a weekday schedule.
- Create a new workflow file
09-scheduled-regression.yaml
(based on any of the already existing workflows) - Modify the workflow to trigger automatically on a schedule (weekdays at 1 AM UTC).
- Commit & push your changes.
- Observe test execution in GitHub Actions logs once the scheduled time passes.
β Note: To really observe the execution, set the trigger to execute shortly after you will have pushed.
π Relevant Documentation:
π Workflow file: .github/workflows/10-containerized-testing.yaml
π‘ Goal: Run tests inside Docker containers to ensure consistency across different environments.
- Create a workflow
10-containerized-testing.yaml
file (based on03-cache-dependencies.yaml
) that:- Uses Docker containers to run tests.
- Runs on every push and pull request.
- Modify your test setup to execute inside a Docker container.
- For Java: Use a
maven:latest
container to run tests. - For TypeScript: Use a
node:latest
container with Playwright pre-installed.
- For Java: Use a
- Ensure dependencies are installed inside the container.
- Commit & push your changes.
- Observe the test execution logs inside the container.
π Relevant Documentation:
- Using Docker in GitHub Actions
- Playwright Docker setup
- Maven in Docker
- Node.js in Docker
- Running tests inside Docker
π Workflow file: .github/workflows/11-parallel-tests.yaml
π‘ Goal: Configure a matrix strategy in GitHub Actions to run Playwright tests concurrently across different browsers or environments.
- Create a new workflow file
11-parallel-tests.yaml
(based on03-cache-dependencies.yaml
). - Use a matrix strategy to define multiple browsers (e.g.,
chromium
,firefox
,webkit
)- For Java: pass a system property (e.g.
-Dplaywright.browserName=${{ matrix.browser }}
). - For TypeScript: pass the browser name to
npx playwright test
(e.g.--browser ${{ matrix.browser }}
).
- For Java: pass a system property (e.g.
- Java only: Update your project files so tests can pick the correct browser:
- Open
src/test/java/dev/christianbaumann/PlaywrightTest.java
- Uncomment the second @BeforeAll method and comment out the default one
- Open
- Commit & push the new workflow (and any modified files).
- Observe the concurrent runs in GitHub Actions. Each job in the matrix should execute in parallel, one for each browser/ environment.
π Relevant Documentation:
π Workflow file: .github/workflows/12-cross-platform-parallel.yaml
π‘ Goal: Execute tests in parallel across all combinations of Ubuntu, Windows, Mac with Chromium, Firefox, and Webkit.
- Create a workflow (based on
11-parallel-tests.yaml
) file that:- Runs tests in parallel across Ubuntu, Windows, and Mac.
- Tests each browser: Chromium, Firefox, and Webkit.
- Uses a matrix strategy to cover all combinations.
- Java: Keep the changes in
src/test/java/dev/christianbaumann/PlaywrightTest.java
from Exercise 11 - Commit & push the workflow.
- Observe the test execution across different platforms and browsers.
π Relevant Documentation:
π Workflow file: .github/workflows/13-debugging.yaml
π‘ Goal: Learn how to troubleshoot and debug GitHub Actions workflows effectively.
- Create a new workflow file
13-debugging.yaml
. - Add a job that prints environment variables and debug logs using
ACTIONS_STEP_DEBUG
. - Introduce an intentional failure (e.g., running a non-existent command) and observe error messages.
- Enable debug logging in GitHub Actions settings.
- Rerun the failed workflow with debugging enabled and analyze the logs.
- Fix the issue and confirm a successful run.
π Relevant Documentation:
π Workflow file: .github/workflows/14-env-secrets.yaml
π‘ Goal: Store and use environment variables and secrets securely in workflows.
- Create a new workflow file
14-env-secrets.yaml
. - Define environment variables inside a job.
- Store a GitHub Actions secret (
MY_SECRET
) in the repository settings. - Access the secret in a workflow using
${{ secrets.MY_SECRET }}
. - Print environment variables but ensure secrets are not exposed in logs.
- Confirm that the workflow executes successfully without revealing sensitive information.
π Relevant Documentation: