Workflow overview
- Run TestDriver CLI: Execute a TestDriver test file.
- Lifecycle Prerun: Automatically install Playwright and generate test scripts via
lifecycle/prerun.yaml
. - Execute Test: Run the main test logic to verify or use the generated Playwright tests.
- Create Pull Request: Optional additional steps can commit changes and create a pull request 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
). - Lifecycle Files: Create
lifecycle/prerun.yaml
for Playwright installation and generation. - TestDriver Test File: Create a test file (
testdriver/test.yaml
) for your main test logic.
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. Run TestDriver
TestDriver CLI executes the test file in headless mode. The test file should contain commands to install Playwright and generate the test scripts.3. Lifecycle configuration
Uselifecycle/prerun.yaml
to install and launch Playwright before your test runs. This keeps the setup separate from your actual test logic:
testdriver/test.yaml
file can then focus on the actual test logic:
4. Commit and create pull request
After TestDriver generates the Playwright test files, you can use additional GitHub Actions steps to commit the changes and create a pull request:Running the workflow
1
Trigger the Workflow
- Push changes to the
main
branch. - Open a pull request.
- Manually trigger the workflow using the workflow_dispatch event.
2
Review the Pull Request
- Navigate to the Pull Requests tab in your GitHub repository.
- Review the generated Playwright test script (
pw-test.spec.js
).
3
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.
- Use Lifecycle Files: Use
lifecycle/prerun.yaml
for Playwright installation and setup to separate concerns from your main test logic. - Error Handling: Include error handling in both lifecycle and test files to manage installation and generation failures gracefully.
- File Organization: Keep generated Playwright tests in a dedicated directory for better organization.
By following this guide, you can use TestDriver CLI to generate and manage Playwright tests in your GitHub repository through automated workflows.