1. Introduction to Playwright C# CI/CD with Azure DevOps
Test automation plays an important role in modern software development. Development teams frequently release application updates, and QA engineers must verify that new changes do not introduce defects into existing functionality.
Running automated tests manually after every code change can consume considerable time. This is where Continuous Integration and Continuous Delivery (CI/CD) become useful.
Playwright C# CI CD Azure DevOps is a practical combination for automating browser testing and executing regression test suites whenever developers commit or merge code.
Microsoft Playwright provides browser automation capabilities using C# and .NET. Azure DevOps provides tools for source code management, pipeline automation, build execution, and test result publishing.
By integrating these technologies, QA engineers can automatically execute Playwright tests whenever application code changes.
In this Playwright C# CI CD Azure DevOps tutorial, we will learn how to create a Playwright automation project, configure NUnit, create an Azure Pipelines YAML file, install browsers, execute automated tests, and publish test results and failure artifacts.
We will also explore pipeline triggers, environment variables, parallel execution, troubleshooting, and CI/CD best practices.
2. What Is CI/CD and Why Use Azure DevOps?
CI/CD stands for Continuous Integration and Continuous Delivery or Deployment.
What Is Continuous Integration?
Continuous Integration is the practice of frequently merging code changes into a shared repository.
Whenever a developer pushes code, an automated pipeline can:
- Download the latest source code.
- Restore project dependencies.
- Build the application.
- Execute automated tests.
- Publish test results.
This helps identify defects earlier in the development lifecycle.
What Is Continuous Delivery?
Continuous Delivery ensures that validated application changes are ready for deployment.
Teams can automate application packaging and deployment to development, QA, staging, or production environments.
What Is Azure DevOps?
Microsoft Azure DevOps is a platform that provides services for managing software development workflows.
Its important services include:
- Azure Repos: Source code management.
- Azure Pipelines: Automated build and test execution.
- Azure Boards: Work item and project tracking.
- Azure Test Plans: Test planning and management.
- Azure Artifacts: Package management.
For Playwright automation, Azure Pipelines is particularly useful because it can execute NUnit tests automatically and publish their results.
3. Benefits of Automating Playwright C# Tests in CI/CD
Integrating Playwright C# with Azure DevOps offers several advantages.
1. Automated test execution: Tests execute automatically after code changes without requiring manual intervention.
2. Faster regression testing: Teams can run multiple automated tests during every pipeline execution.
3. Early defect detection: Failures are identified before application changes reach production.
4. Centralized test reports: Azure DevOps displays published test results in the pipeline.
5. Browser automation: Playwright can execute tests using Chromium, Firefox, and WebKit.
6. Improved collaboration: Developers and QA engineers can review pipeline failures and investigate defects together.
7. Scalable test automation: Teams can expand their regression suites and use parallel execution when sufficient resources are available.
These benefits make CI/CD integration an important skill for QA engineering and software quality assurance professionals.
4. Prerequisites and Project Setup
Before implementing Playwright C# CI CD Azure DevOps, install the following tools.
| Tool | Purpose |
| .NET SDK | Build and execute C# projects |
| Visual Studio or VS Code | Write automation scripts |
| Microsoft.Playwright.NUnit | Playwright and NUnit integration |
| NUnit | Test execution |
| Git | Source code management |
| Azure DevOps account | Pipeline configuration |
| Playwright browsers | Browser automation |
Useful official resources:
- .NET SDK: https://dotnet.microsoft.com/download
- Visual Studio: https://visualstudio.microsoft.com/
- Azure DevOps: https://azure.microsoft.com/products/devops
- Playwright .NET: https://playwright.dev/dotnet/
Verify your .NET installation:
dotnet –version
You should see the installed .NET SDK version.
5. Creating a Playwright C# Automation Project
Let’s create a practical NUnit automation project.
Step 1: Create an NUnit project
Open PowerShell or the Visual Studio terminal.
dotnet new nunit -n PlaywrightAzureTests
Step 2: Navigate to the project directory
cd PlaywrightAzureTests
Step 3: Install Microsoft Playwright NUnit
dotnet add package Microsoft.Playwright.NUnit
This package provides Playwright integration with NUnit, including the PageTest base class.
Step 4: Build the project
dotnet build
Step 5: Install Playwright browsers locally
For a project targeting .NET 8, execute:
pwsh bin/Debug/net8.0/playwright.ps1 install chromium
Replace net8.0 with your actual target framework.
Step 6: Create the project structure
Organize your project as follows:
PlaywrightAzureTests
│
├── Tests
│ ├── LoginTests.cs
│ └── HomePageTests.cs
│
├── Pages
│ └── LoginPage.cs
│
├── Utilities
│ └── TestData.cs
│
├── .gitignore
│
└── PlaywrightAzureTests.csproj
This structure separates page objects, test cases, and test data.
6. Configuring NUnit Test Execution
NUnit is the test runner used in this example.
Let’s create a simple Playwright test.
Inside the Tests folder, create LoginTests.cs.
using Microsoft.Playwright.NUnit;
using NUnit.Framework;
namespace PlaywrightAzureTests.Tests
{
[TestFixture]
public class LoginTests : PageTest
{
[Test]
public async Task VerifyLoginPage()
{
await Page.GotoAsync(
“https://www.saucedemo.com/”
);
await Expect(
Page.Locator(“#login-button”)
).ToBeVisibleAsync();
}
[Test]
public async Task VerifyPageTitle()
{
await Page.GotoAsync(
“https://www.saucedemo.com/”
);
await Expect(Page).ToHaveTitleAsync(
new System.Text.RegularExpressions.Regex(
“Swag Labs”
)
);
}
}
}
Understanding PageTest
PageTest is provided by Microsoft.Playwright.NUnit.
It manages the Playwright browser and page lifecycle for individual tests.
You do not need to manually create and close a browser for every test.
The framework provides:
- Page initialization.
- Browser context isolation.
- Test-level cleanup.
- Playwright assertions.
Run tests locally
Execute:
dotnet test
If everything works correctly, NUnit executes the test cases and displays the results in the terminal.
7. Setting Up an Azure DevOps Project and Pipeline
Now let’s configure Azure DevOps.
Step 1: Create an Azure DevOps organization
Visit:
Sign in and create an organization if you do not already have one.
Step 2: Create a new project
- Open Azure DevOps.
- Select New Project.
- Enter the project name PlaywrightAutomation.
- Select Private or Public visibility as appropriate.
- Click Create.
Step 3: Push your Playwright project to Git
Initialize Git inside your project directory:
git init
git add .
git commit -m “Add Playwright CSharp automation”
git branch -M main
Connect your Azure Repos remote:
git remote add origin https://dev.azure.com/ORG/PROJECT/_git/REPOSITORY
git push -u origin main
Replace the organization, project, and repository placeholders with your actual Azure DevOps details.
You can also use a connected GitHub repository instead of Azure Repos.
Step 4: Create an Azure Pipeline
Inside Azure DevOps:
- Open Pipelines.
- Select New Pipeline.
- Choose Azure Repos Git or your connected Git provider.
- Select the repository.
- Choose Starter Pipeline.
- Replace the generated YAML with your pipeline configuration.
- Save and run.
The YAML file should be stored in the root directory of your repository as azure-pipelines.yml.
8. Creating an Azure Pipelines YAML File
Azure Pipelines YAML defines the steps required to restore dependencies, build the project, install browsers, execute tests, and publish results.
Create azure-pipelines.yml in your repository root.
Complete Azure DevOps pipeline example
The following configuration uses a Microsoft-hosted Ubuntu agent and .NET 8.
trigger:
– main
pr:
– main
pool:
vmImage: ‘ubuntu-latest’
variables:
buildConfiguration: ‘Release’
testProject: ‘PlaywrightAzureTests/PlaywrightAzureTests.csproj’
testResultsDirectory: ‘$(Agent.TempDirectory)/TestResults’
artifactsDirectory: ‘$(Build.ArtifactStagingDirectory)/playwright-artifacts’
steps:
# Install .NET SDK
– task: UseDotNet@2
displayName: ‘Install .NET SDK’
inputs:
packageType: ‘sdk’
version: ‘8.0.x’
# Restore NuGet packages
– task: DotNetCoreCLI@2
displayName: ‘Restore dependencies’
inputs:
command: ‘restore’
projects: ‘$(testProject)’
# Build automation project
– task: DotNetCoreCLI@2
displayName: ‘Build Playwright project
inputs:
command: ‘build’
projects: ‘$(testProject)’
arguments: ‘–configuration $(buildConfiguration) –no-restore’
# Install Playwright browsers
– task: PowerShell@2
displayName: ‘Install Playwright Chromium’
inputs:
targetType: ‘inline’
pwsh: true
script: |
$projectDir = “$(Build.SourcesDirectory)/PlaywrightAzureTests”
$framework = “net8.0”
$script = “$projectDir/bin/Release/$framework/playwright.ps1”
pwsh $script install –with-deps chromium
# Run NUnit tests
– task: DotNetCoreCLI@2
displayName: ‘Run Playwright NUnit tests
inputs:
command: ‘test’
projects: ‘$(testProject)’
publishTestResults: false
arguments: >
–configuration $(buildConfiguration)
–no-build
–results-directory “$(testResultsDirectory)”
–logger “trx;LogFileName=playwright-results.trx”
— NUnit.NumberOfTestWorkers=2
env:
PLAYWRIGHT_ARTIFACTS_DIR: $(artifactsDirectory)
# Publish NUnit test results
– task: PublishTestResults@2
displayName: ‘Publish test results’
condition: succeededOrFailed()
inputs:
testResultsFormat: ‘VSTest’
testResultsFiles: ‘**/playwright-results.trx’
searchFolder: ‘$(testResultsDirectory)’
mergeTestResults: true
failTaskOnFailedTests: true
testRunTitle: ‘Playwright C# Automation Tests
# Publish screenshots and traces
– task: PublishPipelineArtifact@1
displayName: ‘Publish Playwright failure artifacts
condition: succeededOrFailed()
inputs:
targetPath: ‘$(artifactsDirectory)’
artifactName: ‘Playwright-Failure-Artifacts’
publishLocation: ‘pipeline’
Note: This example assumes the project directory is PlaywrightAzureTests and its target framework is net8.0. Adjust both values if your project differs.
Understanding the pipeline stages
1. Trigger configuration
trigger:
– main
pr:
– main
The pipeline runs when changes are pushed to the main branch and when pull requests target that branch.
2. Microsoft-hosted agent
pool:
vmImage: ‘ubuntu-latest’
Azure DevOps provides a temporary hosted machine to execute the automation pipeline.
3. SDK installation
UseDotNet@2 installs the required .NET SDK.
4. Dependency restoration
DotNetCoreCLI@2 restores the required NuGet packages.
5. Build execution
The project is compiled in Release configuration.
6. Browser installation
The generated Playwright installation script downloads Chromium and installs its required operating-system dependencies.
7. Test execution
NUnit executes the Playwright tests using two workers.
8. Result publishing
The pipeline publishes the TRX test report so QA engineers can review passed and failed tests in Azure DevOps.
9. Artifact publishing
Screenshots and traces are uploaded as downloadable pipeline artifacts.
The condition: succeededOrFailed() setting ensures that publishing tasks can execute even when the test step fails.
Azure DevOps supports TRX through the VSTest result format, and PublishTestResults@2 displays results in the pipeline’s Tests tab.
Microsoft Learn+2
9. Installing .NET Dependencies and Playwright Browsers
Browser installation is an important part of Playwright CI/CD configuration.
Installing the NuGet package alone does not install the browser binaries.
After building the project, Playwright generates an installation script inside the output directory.
For example:
dotnet build –configuration Release
pwsh bin/Release/net8.0/playwright.ps1 install chromium
For Ubuntu hosted agents, use:
pwsh bin/Release/net8.0/playwright.ps1 install –with-deps chromium
The –with-deps option installs the operating-system dependencies needed by the selected browser.
You can install all supported browser engines using:
pwsh bin/Release/net8.0/playwright.ps1 install –with-deps
However, installing only the browser engines required by your test suite can reduce pipeline execution time.
Important: The browser installation script must correspond to the Playwright package version used by the project. Do not use a browser binary downloaded for an unrelated Playwright version.
Playwright .NET+1
10. Running Tests and Publishing Test Results
After configuring the YAML pipeline, save and commit your changes.
git add .
git commit -m “Add Azure DevOps Playwright pipeline”
git push origin main
Azure DevOps automatically detects the pipeline configuration and starts execution when the configured trigger conditions are met.
Understanding TRX test results
TRX is a test result file format supported by Azure DevOps.
The following command generates a TRX report:
dotnet test –logger “trx;LogFileName=playwright-results.trx”
You can also specify an output directory:
dotnet test `
–results-directory TestResults `
–logger “trx;LogFileName=playwright-results.trx”
After execution, Azure DevOps publishes the results using:
– task: PublishTestResults@2
inputs:
testResultsFormat: ‘VSTest’
testResultsFiles: ‘**/*.trx’
Once published, open your pipeline run and select the Tests tab.
You can review:
- Total test cases.
- Passed tests.
- Failed tests.
- Execution duration.
- Failure messages.
- Stack traces.
This makes debugging easier for developers and QA engineers.
11. Capturing Screenshots, Traces, and Failure Artifacts
One major advantage of Playwright is its debugging support.
When an automated test fails in CI/CD, screenshots and traces help identify the problem without reproducing every failure locally.
Capturing screenshots
You can capture a screenshot using the Playwright Page object.
await Page.ScreenshotAsync(
new PageScreenshotOptions
{
Path = “failure.png”,
FullPage = true
}
);
Capturing Playwright traces
Tracing records browser activity, including screenshots, snapshots, and source information.
You can enable tracing in your test setup.
[SetUp]
public async Task StartTracing()
{
await Context.Tracing.StartAsync(
new TracingStartOptions
{
Screenshots = true,
Snapshots = true,
Sources = true
}
);
}
After test execution, save the trace when the test fails.
[TearDown]
public async Task StopTracing()
{
if (TestContext.CurrentContext.Result.Outcome.Status
== NUnit.Framework.Interfaces.TestStatus.Failed)
{
await Context.Tracing.StopAsync(
new TracingStopOptions
{
Path = “failure-trace.zip”
}
);
}
else
{
await Context.Tracing.StopAsync();
}
}
For production projects, use unique artifact filenames for each test and ensure the artifact directory exists before saving files.
The pipeline’s artifact publishing step makes these files available for download after execution.
Publishing failure artifacts
You can publish screenshots, trace files, and logs using:
– task: PublishPipelineArtifact@1
condition: succeededOrFailed()
inputs:
targetPath: ‘$(Build.ArtifactStagingDirectory)/playwright-artifacts’
artifactName: ‘Playwright-Reports’
Download the artifact from the completed Azure DevOps pipeline and open the trace using Playwright Trace Viewer.
Documentation: https://playwright.dev/dotnet/docs/trace-viewer
12. Troubleshooting, Best Practices, and Interview Questions
Common Azure DevOps Pipeline Errors
| Error | Possible reason | Solution |
| Browser executable not found | Browser binaries are missing | Run Playwright install script |
| Missing browser dependencies | OS packages are unavailable | Use install –with-deps on supported Linux agents |
| .NET SDK error | Incorrect SDK version | Configure UseDotNet |
| Tests not discovered | NUnit or adapter configuration issue | Check NuGet dependencies and test project |
| Test timeout | Slow application or unstable network | Investigate navigation and locator conditions |
| Pipeline cannot publish results | Incorrect TRX path | Verify results directory and filename |
| Flaky tests | Shared state or unstable test data | Improve test isolation |
Microsoft-Hosted vs Self-Hosted Agents
Microsoft-hosted agents are managed by Azure DevOps. They are convenient for beginners because you do not need to maintain the machine.
Self-hosted agents run on machines maintained by your organization.
They are useful when:
- Tests require access to private networks.
- Special software dependencies are required.
- Browser installation needs customization.
- Teams need persistent machine configuration.
However, self-hosted agents require maintenance, security updates, and resource monitoring.
Best Practices for Playwright C# CI/CD
- Keep the pipeline YAML file in source control.
- Use the same .NET SDK version locally and in CI.
- Install only the browsers required by the test suite.
- Use independent browser contexts for independent tests.
- Store credentials in Azure DevOps secret variables or variable groups.
- Never commit passwords or API tokens.
- Publish TRX test results after every test run.
- Capture screenshots and traces for failed tests.
- Use appropriate NUnit worker counts.
- Avoid unnecessary fixed waits.
- Separate smoke tests from full regression suites.
- Monitor execution time and flaky test frequency.
Interview Questions on Playwright C# CI/CD Azure DevOps
Q1. What is CI/CD in test automation?
CI/CD automates build, testing, and delivery processes whenever code changes are committed.
Q2. Why do we use Azure DevOps with Playwright C#?
Azure DevOps automates test execution, manages pipelines, and publishes test results and artifacts.
Q3. What is an Azure Pipelines YAML file?
It is a configuration file that defines the pipeline triggers, agents, variables, and execution tasks.
Q4. How do you install Playwright browsers in Azure DevOps?
Use the generated Playwright installation script after building the project.
Q5. How do you publish NUnit test results?
Generate a TRX report using dotnet test –logger “trx” and publish it using PublishTestResults@2 with the VSTest format.
Q6. How do you capture screenshots when a test fails?
Use Page.ScreenshotAsync() and publish the generated files as pipeline artifacts.
Q7. What is the difference between hosted and self-hosted agents?
Hosted agents are managed by Microsoft, while self-hosted agents are maintained by the organization.
Q8. How do you run Playwright C# tests in parallel?
Use NUnit’s supported parallelization configuration and configure the worker count with NUnit.NumberOfTestWorkers.
Career Guidance for Indian QA Engineers and SDETs
For QA Automation Engineers and SDETs in India, understanding Playwright C# CI/CD Azure DevOps can strengthen your technical profile.
Companies increasingly expect automation engineers to understand both test development and pipeline execution.
Focus on learning:
- C# and .NET fundamentals.
- Playwright browser automation.
- NUnit test runner.
- Azure Repos and Git.
- Azure Pipelines YAML.
- CI/CD concepts.
- Parallel execution.
- Test reporting and debugging.
- Secure environment configuration.
- Regression testing strategies.
During interviews, be prepared to explain how you created a YAML pipeline, installed Playwright browsers, executed NUnit tests, published TRX reports, and investigated pipeline failures.
Building a practical project with a working Azure DevOps pipeline is an effective way to demonstrate these skills.
FAQs
1. Can we integrate Playwright C# with Azure DevOps?
Yes. You can execute Playwright NUnit tests using Azure Pipelines YAML and publish test results and artifacts.
2. Which package is required for Playwright C# Azure DevOps integration?
Use Microsoft.Playwright.NUnit for the NUnit-based automation framework.
3. How do we install Playwright browsers in Azure DevOps?
Run the generated playwright.ps1 installation script after building the project.
4. How do we publish Playwright test results in Azure DevOps?
Generate TRX files and publish them using the PublishTestResults@2 task with the VSTest result format.
5. Can Playwright tests run on Microsoft-hosted agents?
Yes. Ubuntu, Windows, and macOS hosted agents can run Playwright tests when the required .NET SDK, browser binaries, and dependencies are installed.
6. Can we execute Playwright C# tests in parallel in Azure DevOps?
Yes. NUnit supports parallel execution, and you can configure the worker count according to available resources.
7. How do we debug failed Playwright tests in Azure DevOps?
Capture screenshots, traces, logs, and test results, then publish them as pipeline artifacts.
