Integrating Playwright With CI - CD Pipelines (Chat GPT)
Integrating Playwright With CI - CD Pipelines (Chat GPT)
Integrating Playwright into a CI/CD pipeline ensures that your end-to-end tests run automatically
during the software development lifecycle, providing continuous feedback on the health of your
application. Here’s a step-by-step guide to integrating Playwright with a CI/CD pipeline:
---
Install Playwright:
// example.spec.js
const { test, expect } = require('@playwright/test');
---
on:
push:
branches:
- main
pull_request:
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
stages:
- test
playwright_tests:
image: mcr.microsoft.com/playwright:v1.40.0-focal
stage: test
script:
- npm ci
- npx playwright install --with-deps
- npx playwright test
Example 3: Jenkins
pipeline {
agent any
stages {
stage('Install Dependencies') {
steps {
sh 'npm ci'
sh 'npx playwright install --with-deps'
}
}
stage('Run Tests') {
steps {
sh 'npx playwright test'
}
}
}
}
---
module.exports = {
reporter: [['html', { outputFolder: 'playwright-report', open: 'never' }]],
};
artifacts:
paths:
- playwright-report/
---
Optimize execution by running tests in parallel using Playwright’s built-in parallelism or CI/CD
platform-specific features:
In playwright.config.js:
module.exports = {
workers: 4, // Adjust based on your CI/CD environment
};
strategy:
matrix:
node: [16, 18]
---
5. Debugging Failures
module.exports = {
use: {
video: 'retain-on-failure',
screenshot: 'only-on-failure',
},
};
---
---
By following these steps, Playwright can seamlessly integrate with your CI/CD pipeline, helping
you maintain high-quality software through automated testing.