This repository contains end-to-end UI tests using Playwright with Java and JUnit 5.
- Java 21
- Maven
- IDE or editor of choice
🔗 Documentation: Fork a repository
git clone https://github.com/$yourGitHubUsername/gha-java-playwright.git
cd gha-java-playwrightmvn installmvn testEach 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-reportandtest-results - For Java:
target/reportsandtarget/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@v15or 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.yamlfile). - 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-resultsand generates a test report filereport.txtinside 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.yamland define a composite action that processes Playwright test results.See hints
The custom action processes the
test-results/report.txtfile, 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.yamlfile (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:latestcontainer to run tests. - For TypeScript: Use a
node:latestcontainer 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.javafrom 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: