1. Introduction to Playwright Java CI/CD with Jenkins
Modern software development teams need to test applications continuously to deliver reliable software. Manual testing alone cannot provide fast feedback whenever developers make code changes. This is why automation testing and Continuous Integration (CI) and Continuous Delivery (CD) have become important parts of software development.
Playwright Java is a popular browser automation library that helps QA engineers automate web applications using Java. Jenkins is an open-source automation server that can execute automated test scripts whenever developers push code changes to a Git repository.
Combining Playwright Java with Jenkins allows QA teams to execute end-to-end tests automatically, identify application defects, generate test reports, and share execution results with development teams.
For example, imagine a development team working on an e-commerce application. Whenever a developer pushes new code to GitHub, Jenkins can automatically:
- Download the latest project code.
- Install the required Playwright browsers.
- Execute Java automation scripts.
- Validate important application workflows.
- Generate test execution reports.
- Publish screenshots and failure details.
This process reduces manual effort and helps teams identify defects earlier.
In this Playwright Java CI CD Jenkins tutorial, you will learn how to configure a Maven project, connect Jenkins with GitHub, create a Jenkinsfile, execute Playwright tests, and publish test reports.
2. Prerequisites and Maven Project Setup
Before implementing Playwright Java Jenkins Integration, prepare the required development environment.
Prerequisites
| Tool | Purpose |
| Java JDK 17 | Execute Java programs |
| Maven | Build and manage dependencies |
| IntelliJ IDEA | Develop Java automation scripts |
| Playwright Java | Browser automation |
| Jenkins | CI/CD automation |
| Git | Source code management |
| GitHub | Store automation framework code |
| JUnit 5 | Execute automated test cases |
Important: Playwright Java is a browser automation library, not a complete test runner. Java projects typically use JUnit or TestNG to execute test cases.
Step 1: Create a Maven Project
Create a Maven project named:
PlaywrightJenkinsProject
Add the following dependency to pom.xml:
<properties>
<maven.compiler.release>17</maven.compiler.release>
<playwright.version>1.64.0</playwright.version>
<junit.version>5.14.4</junit.version>
</properties>
<dependencies>
<dependency>
<groupId>com.microsoft.playwright</groupId>
<artifactId>playwright</artifactId>
<version>${playwright.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
These are example pinned dependency versions. Confirm compatibility with your Java environment before using them in production.
Step 2: Configure Maven Surefire
Add the following plugin inside the Maven build section:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.5.2</version>
</plugin>
</plugins>
</build>
Maven Surefire executes JUnit tests during the Maven test lifecycle.
Step 3: Create a Sample Java Test
Create LoginTest.java inside src/test/java/tests.
package tests;
import com.microsoft.playwright.*;
import org.junit.jupiter.api.Test;
import static com.microsoft.playwright.assertions
.PlaywrightAssertions.assertThat;
public class LoginTest {
@Test
void verifyWebsiteTitle() {
try (Playwright playwright = Playwright.create()) {
Browser browser = playwright.chromium().launch(
new BrowserType.LaunchOptions()
.setHeadless(true)
);
try {
Page page = browser.newPage();
page.navigate(“https://example.com”);
assertThat(page)
.hasTitle(“Example Domain”);
} finally {
browser.close();
}
}
}
}
This test launches Chromium in headless mode, opens a website, and validates the page title.
Run the test locally:
mvn clean test
If the test passes locally, you are ready to configure Jenkins.
3. Jenkins Installation and Configuration
Jenkins is an automation server used to build, test, and deploy applications.
It supports pipeline-based automation and integrates with GitHub, Maven, Java, Docker, and other development tools.
Step 1: Install Jenkins
Download Jenkins from the official website:
For a Windows environment:
- Download the Jenkins Windows installer.
- Run the installer.
- Configure the Jenkins service.
- Open Jenkins in your browser.
- Complete the initial administrator setup.
The default local address is:
http://localhost:8080
Follow the installation instructions to retrieve the initial administrator password and install the suggested plugins.
Step 2: Install Required Plugins
Open:
Manage Jenkins → Plugins
Install the following plugins:
| Plugin | Purpose |
| Git | Connect Git repositories |
| Pipeline | Create Jenkins pipelines |
| Maven Integration | Maven build integration |
| JUnit | Publish JUnit test results |
| Allure Jenkins Plugin | Display Allure reports, if using Allure |
Restart Jenkins if required.
Step 3: Configure JDK and Maven
Navigate to:
Manage Jenkins → Tools
Configure:
- JDK installation.
- Maven installation.
- Git installation, if required.
For example:
JDK Name: JDK17
Maven Name: Maven
If Jenkins agents already have the tools installed, configure their paths or use managed installations according to your infrastructure.
4. Connect a Git Repository to Jenkins
Jenkins needs access to the automation project before it can execute tests.
Step 1: Push the Maven Project to GitHub
Open your project terminal and execute:
git init
git add .
git commit -m “Initial Playwright Java framework”
git branch -M main
git remote add origin https://github.com/username/PlaywrightJenkinsProject.git
git push -u origin main
Replace the example repository URL with your actual GitHub repository.
Step 2: Create Jenkins Credentials
For a private repository, configure an appropriate GitHub access credential.
Navigate to:
Manage Jenkins → Credentials → System → Global credentials
Add a credential with the minimum permissions required to access the repository.
Avoid storing GitHub passwords or access tokens directly inside the Jenkinsfile.
Step 3: Create a Jenkins Pipeline Job
- Open the Jenkins dashboard.
- Click New Item.
- Enter PlaywrightJavaPipeline.
- Select Pipeline.
- Click OK.
- Configure the pipeline source.
You can use Pipeline script from SCM and select Git as the source control system.
Enter the repository URL, branch name, credentials, and Jenkinsfile path.
This connects your Git repository with Jenkins.
5. Create a Jenkins Pipeline Using a Jenkinsfile
A Jenkinsfile is a text file that defines the complete CI/CD pipeline.
It allows teams to maintain pipeline configuration along with application code in Git.
There are two common pipeline approaches:
- Declarative Pipeline: Uses a structured syntax with stages and steps. Recommended for beginners.
- Scripted Pipeline: Uses Groovy programming and provides more flexibility.
For this Playwright Java CI/CD Jenkins example, we will use a Declarative Pipeline.
Step 1: Create a Jenkinsfile
Create a file named Jenkinsfile in the root directory of your Maven project.
pipeline {
agent any
tools {
jdk ‘JDK17’
maven ‘Maven’
}
environment {
BASE_URL = ‘https://example.com’
}
stages {
stage(‘Checkout’) {
steps {
checkout scm
}
}
stage(‘Build’) {
steps {
sh ‘mvn clean compile’
}
}
stage(‘Install Playwright Browsers‘) {
steps {
sh ”’
mvn exec:java \
-Dexec.mainClass=com.microsoft.playwright.CLI \
-Dexec.args=”install –with-deps chromium”
”’
}
}
stage(‘Execute Tests’) {
steps {
sh ‘mvn test’
}
}
stage(‘Publish Test Results’) {
steps {
junit ‘target/surefire-reports/*.xml’
}
}
}
post {
always {
archiveArtifacts artifacts:
‘target/surefire-reports/**,test-results/**’,
allowEmptyArchive: true
}
success {
echo ‘Playwright automation tests passed!
}
failure {
echo ‘Playwright automation tests failed. Check the test results.’
}
cleanup {
echo ‘Pipeline execution completed.
}
}
}
This pipeline contains five important stages:
| Stage | Activity |
| Checkout | Downloads source code |
| Build | Compiles Java code |
| Install Browsers | Installs Chromium and Linux dependencies |
| Execute Tests | Runs Playwright automated scripts |
| Publish Results | Publishes JUnit XML reports |
Important configuration: The mvn exec:java command requires the Maven Exec Plugin. Add it to your pom.xml:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.5.0</version>
</plugin>
Also ensure that the JDK17 and Maven names match the tool names configured in Jenkins.
The checkout scm command is suitable for a Pipeline job configured from SCM or a Multibranch Pipeline.
6. Install Playwright Browsers and Run Java Tests
One of the most important steps in Playwright Java Jenkins Integration is browser installation.
Playwright requires specific browser binaries compatible with its library version. Installing Playwright’s Maven dependency alone does not guarantee that the required browsers and operating-system dependencies are available.
Install Chromium
Execute:
mvn exec:java \
-Dexec.mainClass=com.microsoft.playwright.CLI \
-Dexec.args=”install chromium”
For Linux Jenkins agents, install browser dependencies as well:
mvn exec:java \
-Dexec.mainClass=com.microsoft.playwright.CLI \
-Dexec.args=”install –with-deps chromium”
This command installs Chromium and the required Linux dependencies.
Playwright Java+1
Why is headless mode important?
Jenkins agents commonly execute automated tests without a graphical desktop.
Playwright runs browsers in headless mode by default.
For example:
Browser browser = playwright.chromium().launch(
new BrowserType.LaunchOptions()
.setHeadless(true)
);
Headless mode allows automated browser testing without opening a visible browser window.
If you need to debug a test locally, use:
.setHeadless(false)
On Linux agents, headed execution generally requires a display server or Xvfb.
Use environment variables for application URLs
Avoid hardcoding environment-specific URLs in test scripts.
Example:
String baseUrl = System.getenv(“BASE_URL”);
if (baseUrl == null || baseUrl.isBlank()) {
throw new IllegalStateException(
“BASE_URL environment variable is missing”
);
}
page.navigate(baseUrl);
Jenkins can supply different URLs for development, QA, and staging environments.
For example:
environment {
BASE_URL = ‘https://qa.example.com’
}
For passwords and tokens, use Jenkins Credentials rather than ordinary environment declarations or source-code literals.
Execute tests manually from Jenkins
After committing your Jenkinsfile:
- Open your Jenkins pipeline job.
- Click Build Now.
- Open the latest build.
- Select Console Output.
- Review each pipeline stage.
- Check the test results.
You should see the Maven execution logs and the final build status.
7. Publish Test Reports and Screenshots
Test execution is only one part of a successful CI/CD pipeline. QA engineers must also make execution results available to the team.
JUnit and Allure are common reporting choices for Playwright Java projects.
A. Publish JUnit reports
Maven Surefire generates XML reports inside:
target/surefire-reports/
Use the Jenkins JUnit plugin:
post {
always {
junit(
testResults: ‘target/surefire-reports/*.xml’,
allowEmptyResults: true
)
}
}
Jenkins displays the number of passed, failed, and skipped tests.
B. Publish Allure reports
For more detailed reports, integrate Allure with JUnit 5.
Add the Allure JUnit 5 dependency to Maven:
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-junit5</artifactId>
<version>2.35.4</version>
<scope>test</scope>
</dependency>
Add allure.properties inside src/test/resources:
allure.results.directory=target/allure-results
Add this stage to your Jenkinsfile after test execution:
stage(‘Generate Allure Report’) {
steps {
allure([
results: [[path: ‘target/allure-results’]]
])
}
}
First install and configure the Allure Jenkins plugin and its report-generation tool under Jenkins global tools.
Jenkins plugin+1
C. Capture screenshots when tests fail
Screenshots help identify UI failures.
For example:
byte[] screenshot = page.screenshot(
new Page.ScreenshotOptions()
.setFullPage(true)
);
You can save the screenshot inside a test-results directory:
java.nio.file.Path path =
java.nio.file.Paths.get(“test-results/failure.png”);
java.nio.file.Files.createDirectories(path.getParent());
java.nio.file.Files.write(path, screenshot);
In a real framework, place this logic in a reusable failure-handling utility or JUnit extension.
Then archive screenshots in Jenkins:
post {
always {
archiveArtifacts(
artifacts: ‘test-results/**/*.png’,
allowEmptyArchive: true
)
}
}
Remember to preserve the original test exception so that Jenkins correctly identifies failed tests.
8. Troubleshoot Common Pipeline Errors
While working with Playwright Java CI CD Jenkins, you may encounter the following issues.
| Error | Possible reason | Solution |
| Browser executable not found | Browser not installed | Run Playwright install command |
| Failed to launch Chromium | Missing Linux dependencies | Use install –with-deps |
| Maven command not found | Maven not configured | Configure Jenkins Maven tools |
| Java version error | Incorrect JDK | Configure compatible JDK |
| Tests pass locally but fail in Jenkins | Different environment | Check URLs, permissions, and dependencies |
| No JUnit reports found | Tests did not execute or wrong path | Check Surefire output |
| Permission denied | Workspace permissions | Check Jenkins agent user permissions |
| Tests time out | Slow environment or network | Investigate loading conditions and timeout settings |
Common troubleshooting commands
java -version
Check Maven:
mvn -version
Install Chromium:
mvn exec:java \
-Dexec.mainClass=com.microsoft.playwright.CLI \
-Dexec.args=”install –with-deps chromium”
Execute tests with Maven debugging:
mvn clean test -e
For browser launch debugging on Linux:
DEBUG=pw:browser mvn test
The Playwright browser installation and debugging documentation provides additional guidance for CI environments.
Playwright Java+1
9. Best Practices for Playwright Java CI/CD Jenkins
Follow these practices when building a reliable automation pipeline.
1. Use a separate browser context for each test
Isolated browser contexts help prevent cookies, sessions, and application data from affecting other test cases.
2. Prefer headless execution in CI
Headless execution is suitable for Jenkins agents without graphical interfaces.
3. Keep credentials secure
Store usernames, passwords, API tokens, and other sensitive values in Jenkins Credentials.
4. Use Page Object Model
Keep locators and page actions separate from test logic. This improves framework maintainability.
5. Avoid unnecessary Thread.sleep()
Use Playwright’s automatic waiting and web-first assertions instead of fixed delays.
6. Publish reports even when tests fail
Use the Jenkins post { always { } } block to publish available reports and archive screenshots.
7. Control parallel execution
Start with sequential execution. Introduce parallel execution after confirming that browser instances, test data, and application environments are isolated.
8. Keep browser and library versions compatible
Install browsers using the Playwright version configured in Maven. Avoid manually downloading unrelated browser versions.
10. Frequently Asked Questions
What is Playwright Java CI CD Jenkins?
Playwright Java CI CD Jenkins is an automation workflow that combines Playwright’s Java browser automation library with Jenkins to execute web testing scripts automatically during software development and delivery.
What are the benefits of Playwright Java CI CD Jenkins?
The main benefits include:
- Automatic browser testing.
- Faster regression testing.
- Early defect identification.
- Reduced manual testing effort.
- Automated test reporting.
- Better collaboration between QA and development teams.
- Continuous feedback after code changes.
How do I get started with Playwright Java CI CD Jenkins?
Start by creating a Playwright Java Maven project, configuring JUnit or TestNG, installing Jenkins, connecting your Git repository, and creating a Jenkinsfile.
Then install Playwright browsers, execute tests, and publish JUnit or Allure reports.
Does Playwright Java support Jenkins?
Yes. Playwright Java can run inside Jenkins pipelines using Maven. Jenkins executes the test scripts and collects their results.
Can Playwright Java run in headless mode in Jenkins?
Yes. Playwright supports headless browser execution by default. It is suitable for Linux-based Jenkins agents without a graphical desktop.
Which test runner is used with Playwright Java?
Playwright Java commonly integrates with JUnit or TestNG. Unlike Playwright Test for JavaScript and TypeScript, it does not provide its own built-in Java test runner.
Can we execute Playwright Java tests in parallel?
Yes. You can configure parallel execution using JUnit or TestNG. Each test should use isolated browser contexts and independent test data.
How do I generate reports in Jenkins?
You can publish JUnit XML reports using the Jenkins JUnit plugin or generate interactive HTML reports using Allure and its Jenkins plugin.
