A comprehensive starter template for setting up Playwright Node.js test automation with seamless Azure DevOps integration using the @alex_neo/playwright-azure-reporter package.
Setting up Playwright is straightforward, but integrating test results with Azure DevOps can be complex. This template solves that problem by providing a pre-configured setup that handles the heavy lifting for you.
What this template provides:
- Pre-configured Azure DevOps integration
- JUnit XML reporting for CI/CD compatibility
- Multi-browser configuration support
- Automated test result publishing
- Screenshot, video, and trace attachment handling
The integration works by using Playwright's built-in JUnit reporter alongside the @alex_neo/playwright-azure-reporter package to automatically publish test results to your Azure DevOps test plans.
- Node.js (v14 or newer)
- npm (included with Node.js)
- Git
- Azure DevOps account with appropriate permissions
# Clone the template
git clone https://github.com/chuls5/Playwright-template
cd playwright-template
# Remove original remote and add your own
git remote remove origin
git remote add origin <YOUR_REPOSITORY_URL>
# Install dependencies
npm install
# Copy the example environment file
cp .env.example .env
Edit the .env
file with your Azure DevOps details:
AZURE_TOKEN=your_personal_access_token_here
In playwright.config.js
, update the Azure reporter configuration with your specific details:
// Uncomment and configure when ready to use Azure integration
/*
[
"@alex_neo/playwright-azure-reporter",
{
orgUrl: "https://dev.azure.com/<your-organization-name>",
token: process.env.AZURE_TOKEN,
planId: <your-test-plan-id>,
projectName: "<your-project-name>",
environment: "QA",
logging: true,
testRunTitle: "Playwright Test Run",
publishTestResultsMode: "testRun",
uploadAttachments: true,
attachmentsType: ["screenshot", "video", "trace"],
testCaseIdMatcher: /@\[(\d+)\]/,
// ... rest of configuration
},
]
*/
You'll need these four pieces of information:
- Personal Access Token (PAT) - Create one in Azure DevOps with Test Plan permissions
- Organization URL - Format:
https://dev.azure.com/your-organization-name
- Project Name - Your Azure DevOps project name
- Test Plan ID - The numeric ID of your test plan
To link your Playwright tests to Azure DevOps test cases, include the test case ID in your test title:
test('Should login successfully @[123456]', async ({ page }) => {
// Your test code here
});
# Run all tests
npx playwright test
# Run specific browser
npx playwright test --project=chromium
# Debug mode
npx playwright test --debug
# View HTML report
npx playwright show-report
βββ tests/ # Your test files go here
βββ tests-examples/ # Example test files for reference
βββ .github/workflows/ # CI/CD pipeline configurations
βββ playwright.config.js # Main Playwright configuration
βββ package.json # Dependencies and scripts
βββ .env # Your environment variables (gitignored)
βββ .env.example # Template for environment variables
βββ README.md # This documentation
# Generated during test runs:
βββ playwright-report/ # HTML test reports
βββ test-results/ # Screenshots, videos, traces
βββ playwright/ # Playwright internal files
import { test, expect } from "@playwright/test";
test('User can reset password @[114944]', async ({ page }) => {
// Navigate and interact with the page
await page.goto('/login');
await page.getByRole('textbox', { name: 'Enter email' }).fill('user@example.com');
await page.getByRole('button', { name: 'Next' }).click();
// Click forgot password link
await page.getByRole('link', { name: 'Forgot Password' }).click();
await page.getByRole('button', { name: 'Send Email' }).click();
// Verify the result
await expect(page).toHaveURL(/.*\/password-reset-confirmation/);
await expect(page.getByRole('heading', { name: 'Your reset password link was' })).toBeVisible();
});
- Use descriptive test names that explain what you're testing
- Make tests independent - each test should work on its own
- Use reliable selectors - prefer
getByRole()
,getByText()
, andgetByTestId()
- Include test case IDs in titles when linking to Azure DevOps
- Group related tests in the same file or describe blocks
- Run your tests locally with the Azure reporter enabled
- The reporter automatically creates a test run in your specified Azure DevOps test plan
- Test results are published with full details including:
- Pass/fail status
- Execution time
- Screenshots on failure
- Video recordings
- Trace files for debugging
The template includes configuration mapping for different browsers:
- Chromium/Chrome β Maps to "Browser Web" configuration
- Chrome Mobile β Maps to "Browser Chrome Mobile" configuration
- Safari Mobile β Maps to "Browser Safari Mobile" configuration
This allows you to run the same tests across multiple browser configurations and see separate results in Azure DevOps.
The Azure reporter is commented out by default. To enable it:
- Ensure your
.env
file has the correctAZURE_TOKEN
- Update the configuration values in
playwright.config.js
- Uncomment the Azure reporter section
- Run your tests normally - results will automatically publish to Azure DevOps
The template includes GitHub Actions workflows for:
- Automated test execution on pull requests
- Parallel test runs across multiple browsers
- Automatic report generation and publishing
- Integration with Azure DevOps for result tracking
Tests not linking to Azure DevOps:
- Verify your test case ID format:
@[123456]
- Ensure the test case exists in your test plan
- Check your Personal Access Token permissions
Reporter not publishing results:
- Confirm all four required configuration values are correct
- Verify your PAT has "Test Plans (read & write)" permissions
- Check the Azure reporter is uncommented in the config
Tests failing to run:
- Run
npx playwright install
to ensure browsers are installed - Check your base URL configuration matches your test environment
- Getting Started with Playwright and VS Code
- Generating Playwright Tests in VS Code
- Advanced Playwright Tutorial Playlist
- Official Playwright Documentation
- Azure Test Plans Documentation
- Microsoft Learn: Build with Playwright
- Playwright Best Practices
If you run into issues or have questions:
- Check the troubleshooting section above
- Review the example tests in the
tests-examples/
folder - Consult the official Playwright documentation
- Open an issue in this repository
Happy testing! πβ¨
Happy Testing! ππ©βπ»π¨βπ» Remember to always obey the testing GOAT! π