Playwright Export
A comprehensive guide to integrating TestDriver with Playwright for automated test generation.
This guide explains how to use TestDriver to generate Playwright test scripts and integrate them into your repository using a GitHub Actions workflow. The workflow automates the process of generating Playwright tests, creating a pull request with the generated test, and ensuring all dependencies are installed.
Workflow overview
- Install Playwright: The workflow installs Playwright and its dependencies.
- Generate Playwright Test: TestDriver generates a Playwright test script using the
playwright codegen
tool. - Create Pull Request: The generated test is committed to a new branch, and a pull request is created for review.
Prerequisites
- GitHub Repository: Ensure your project is hosted on GitHub.
- TestDriver API Key: Store your API key as a GitHub secret (for example,
TD_API_KEY
). - Node.js Installed: Playwright requires Node.js to run.
GitHub Actions workflow
Here’s the GitHub Actions workflow to automate the process:
Workflow file: .github/workflows/playwright.yaml
Workflow steps explained
1. Check out repository
The workflow checks out the repository to ensure the latest code is available for the test generation process.
2. Install Playwright
The prerun
script installs Playwright globally and sets up its dependencies (for example, Chromium browser).
3. Generate Playwright test
The playwright codegen
command generates a Playwright test script (pw-test.spec.js
) for the specified URL (https://airbnb.com
).
4. Create pull request
The workflow commits the generated test script to a new branch (generate-playwright
) and creates a pull request with the title TestDriver / Generate Playwright Test
.
Running the workflow
Trigger the Workflow
- Push changes to the
main
branch. - Open a pull request.
- Manually trigger the workflow using the workflow_dispatch event.
Review the Pull Request
- Navigate to the Pull Requests tab in your GitHub repository.
- Review the generated Playwright test script (
pw-test.spec.js
).
Merge the Pull Request
- Once reviewed, merge the pull request to include the generated test in your repository.
Example output
- Generated Test File:
testdriver/pw-test.spec.js
- Pull Request: A new pull request titled
TestDriver / Generate Playwright Test
will be created.
Best practices
- Secure API Key: Store the TestDriver API key as a GitHub secret to avoid exposing sensitive information.
- Review Generated Tests: Always review the generated Playwright test scripts to ensure they meet your requirements.
- Customize Test Generation: Modify the
playwright codegen
command to target specific URLs or workflows.
By following this guide, you can seamlessly integrate TestDriver with Playwright to generate and manage end-to-end tests in your GitHub repository.