1. Introduction
Playwright is a modern browser automation framework used by software testers and developers to automate web applications. It supports multiple browsers, including Chromium, Firefox, and WebKit.
For Java automation engineers, Playwright provides an official Java library that can be integrated with Maven, JUnit, and TestNG.
A proper Playwright Java installation guide is useful for beginners who want to build browser automation frameworks without facing dependency, browser installation, or environment configuration problems.
For example, after completing the installation, you can write a Java program to:
- Launch Chromium, Firefox, or WebKit.
- Open a web application.
- Enter login credentials.
- Click buttons and interact with elements.
- Validate page titles and application content.
- Execute automated regression tests.
- Integrate tests with Jenkins and GitHub Actions.
Important: Playwright Java is a browser automation library, not the same as Playwright Test. Playwright Test is a separate test runner primarily designed for JavaScript and TypeScript. Java projects commonly use JUnit or TestNG to execute automated tests.
In this tutorial, you will learn how to install Java, configure Maven, add Playwright dependencies, install browsers, create your first Maven project, and execute a working automation test.
2. Prerequisites for Playwright Java Installation
Before following this Playwright Java installation guide, make sure your system meets the basic requirements.
Required software
| Software | Recommended version | Purpose |
| Java JDK | 17 or later | Java development |
| Maven | 3.9.x | Dependency management |
| IntelliJ IDEA | Current version | Java IDE |
| Playwright Java | 1.64.0 example | Browser automation |
| JUnit | 5.x | Test execution |
| Chromium | Playwright-compatible | Browser testing |
| Windows/macOS/Linux | Supported desktop OS | Development environment |
The examples use Java 17 and pinned Maven dependencies. Always check the compatibility requirements of the Playwright release you select.
System requirements
- A working internet connection for downloading dependencies and browsers.
- Sufficient disk space for browser binaries.
- Permission to install software.
- A terminal or command prompt.
- Access to Maven Central or your organization’s Maven repository.
You do not need Node.js to write and execute a normal Playwright Java automation project.
3. Install and Configure Java JDK
Java is the primary requirement for Playwright Java development.
Step 1: Download Java JDK
Visit the official Eclipse Temurin JDK download page.
How to Install Eclipse Temurin JDK on Windows 11 [Step-by-Step Guide]
Choose:
- Operating system: Windows, macOS, or Linux.
- Architecture: x64 or ARM64, depending on your machine.
- Version: JDK 17 or later.
- Package: JDK.
Download and install the package.
Step 2: Configure JAVA_HOME in Windows
After installing Java, configure the environment variables.
- Open Windows Search.
- Search for Environment Variables.
- Select Edit the system environment variables.
- Click Environment Variables.
- Under System Variables, select New.
- Enter the following:
Variable name: JAVA_HOME
Variable value:
C:\Program Files\Eclipse Adoptium\jdk-17
Use the actual installation directory on your computer.
- Find the Path variable.
- Click Edit.
- Add:
%JAVA_HOME%\bin
10. Save the changes.
Step 3: Verify Java installation
Open a new Command Prompt and execute:
java -version
Also execute:
javac -version
Expected output will resemble:
openjdk version “17.x.x”
javac 17.x.x
Java installation verified
macOS and Linux configuration
On macOS, you can use Homebrew:
brew install openjdk@17
On Ubuntu or Debian:
sudo apt update
sudo apt install openjdk-17-jdk
Set JAVA_HOME according to your installed JDK location and add its bin directory to PATH.
Verify using java -version and javac -version.
4. Install Apache Maven
Maven is a build automation and dependency management tool.
It helps download Playwright Java, JUnit, and other libraries required by the automation framework.
Step 1: Download Maven
Visit the official Apache Maven download page.
Create a Java project using an external dependency with Maven
Download the binary ZIP archive for Windows.
Extract it to a directory such as:
C:\apache-maven
Step 2: Configure Maven environment variables
Create a system variable:
Variable name: MAVEN_HOME
Variable value:
C:\apache-maven
Add the following to the system Path:
%MAVEN_HOME%\bin
Step 3: Verify Maven installation
Open a new terminal:
mvn -version
Expected output:
Apache Maven 3.9.x
Java version: 17
The Java version shown by Maven should match the JDK you intend to use.
Maven installation verified
On macOS, install Maven using:
brew install maven
On Ubuntu or Debian:
sudo apt install maven
Verify with mvn -version.
5. Create a Maven Project
You can create a Maven project using IntelliJ IDEA or the command line.
Option A: Create a project using IntelliJ IDEA
Maven | IntelliJ IDEA Documentation
Follow these steps:
- Open IntelliJ IDEA.
- Click New Project.
- Select Java.
- Choose JDK 17.
- Select Maven as the build system.
- Enter the project name PlaywrightJavaDemo.
- Click Create.
Option B: Create a project using the command line
Execute:
mvn archetype:generate ^
-DgroupId=com.techsarvam ^
-DartifactId=PlaywrightJavaDemo ^
-DarchetypeArtifactId=maven-archetype-quickstart ^
-DinteractiveMode=false
On macOS or Linux, replace the Windows ^ line continuations with \.
Navigate into the project:
cd PlaywrightJavaDemo
You should now have a basic Maven project.
Understand the Maven folder structure
PlaywrightJavaDemo
│
├── pom.xml
│
└── src
├── main
│ └── java
│ └── com
│ └── techsarvam
│ └── App.java
│
└── test
└── java
└── com
└── techsarvam
└── AppTest.java
The pom.xml file manages dependencies, while src/main/java contains application code and src/test/java contains automated tests.
6. Add Playwright Java Dependency
Now add Playwright Java to the Maven project.
Open pom.xml and add the following complete configuration:
pom.xml
<project xmlns=”http://maven.apache.org/POM/4.0.0″
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation=”http://maven.apache.org/POM/4.0.0
<modelVersion>4.0.0</modelVersion>
<groupId>com.techsarvam</groupId>
<artifactId>PlaywrightJavaDemo</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.release>17</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<playwright.version>1.64.0</playwright.version>
<junit.version>5.13.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>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.14.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.5.4</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.5.0</version>
</plugin>
</plugins>
</build>
</project>
The Playwright dependency provides the official Java browser automation APIs. JUnit provides the test runner, and Maven Surefire executes JUnit tests.
These are pinned example versions; update them together after checking compatibility.
The official Playwright Java installation documentation also provides the Maven dependency configuration.
Playwright Java
Download Maven dependencies
Execute:
mvn clean install
Alternatively, refresh Maven dependencies in IntelliJ IDEA by clicking the Maven Reload button.
Verify that the dependencies are downloaded without errors.
7. Install Playwright Browsers
Installing the Playwright Java dependency does not mean that the browser installation is complete.
Playwright requires compatible browser binaries to execute automation scripts.
It supports three major browser engines:
Chrome now includes HTTPS-first mode to enhance security | Top Ten Reviews
Chromium
Useful for Chrome-based browser automation.
firefox-logo-small – Mozilla Add-ons Community Blog
Firefox
Useful for cross-browser compatibility testing.
Download Safari Browser Icon | Wallpapers.com
WebKit
Tests the browser engine used by Safari.
Install all supported browsers
Open the terminal inside your Maven project:
mvn exec:java -Dexec.mainClass=com.microsoft.playwright.CLI -Dexec.args=”install”
Install Chromium only
mvn exec:java -Dexec.mainClass=com.microsoft.playwright.CLI -Dexec.args=”install chromium”
Install Firefox only
mvn exec:java -Dexec.mainClass=com.microsoft.playwright.CLI -Dexec.args=”install firefox”
Install WebKit only
mvn exec:java -Dexec.mainClass=com.microsoft.playwright.CLI -Dexec.args=”install webkit”
Install browser dependencies on Linux
For Linux environments, use:
mvn exec:java -Dexec.mainClass=com.microsoft.playwright.CLI -Dexec.args=”install –with-deps”
The –with-deps option installs required operating-system dependencies as well as the requested browsers.
Important: Playwright browser binaries are version-specific. When you upgrade the Playwright Java dependency, run the browser installation command again if required.
Playwright Java
Where are browsers installed?
Playwright normally stores browser binaries in operating-system-specific locations.
| Operating system | Browser cache |
| Windows | %USERPROFILE%\AppData\Local\ms-playwright |
| macOS | ~/Library/Caches/ms-playwright |
| Linux | ~/.cache/ms-playwright |
After installation, your Playwright Java setup is ready for browser automation.
8. Configure the Project with JUnit
JUnit 5 is a popular choice for executing Playwright Java automated tests.
Create a test class inside:
src/test/java/com/techsarvam/
Name it:
PlaywrightInstallationTest.java
The Maven Surefire plugin discovers and executes JUnit Jupiter tests.
You do not need Playwright Test configuration files such as playwright.config.ts in a normal Java project.
If your organization uses TestNG instead, you can replace JUnit with TestNG and configure the Maven Surefire plugin accordingly.
9. Write Your First Playwright Java Program
Now let’s create your first Java automation program.
This example will:
- Launch Chromium.
- Open a browser page.
- Navigate to a website.
- Retrieve the page title.
- Print the title in the console.
- Close the browser.
Create App.java inside:
src/main/java/com/techsarvam/
App.java
package com.techsarvam;
import com.microsoft.playwright.*;
public class App {
public static void main(String[] args) {
Playwright playwright = null;
Browser browser = null;
try {
playwright = Playwright.create();
browser = playwright.chromium().launch(
new BrowserType.LaunchOptions()
.setHeadless(false)
);
Page page = browser.newPage();
page.navigate(“https://example.com”);
String title = page.title();
System.out.println(
“Page Title: ” + title
);
} finally {
if (browser != null) {
browser.close();
}
if (playwright != null) {
playwright.close();
}
}
}
}
Understanding the Java code
| Method | Purpose |
| Playwright.create() | Initializes Playwright |
| chromium().launch() | Launches Chromium |
| browser.newPage() | Creates a browser page |
| page.navigate() | Opens the website |
| page.title() | Retrieves the page title |
| browser.close() | Closes the browser |
| playwright.close() | Releases Playwright resources |
Execute the program
Run:
mvn compile exec:java -Dexec.mainClass=”com.techsarvam.App”
Expected console output:
Page Title: Example Domain
First Playwright Java program executed
10. Run Your First Playwright Java Test
Now let’s execute browser automation using JUnit 5.
Create:
PlaywrightInstallationTest.java
Location:
src/test/java/com/techsarvam/
Java test example
package com.techsarvam;
import com.microsoft.playwright.*;
import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.*;
public class PlaywrightInstallationTest {
private Playwright playwright;
private Browser browser;
private Page page;
@BeforeEach
void setUp() {
playwright = Playwright.create();
browser = playwright.chromium().launch(
new BrowserType.LaunchOptions()
.setHeadless(true)
);
page = browser.newPage();
}
@Test
void verifyPageTitle() {
page.navigate(“https://example.com”);
String actualTitle = page.title();
assertEquals(
“Example Domain”,
actualTitle
);
System.out.println(
“Playwright installation successful
);
}
@AfterEach
void tearDown() {
try {
if (browser != null) {
browser.close();
}
} finally {
if (playwright != null) {
playwright.close();
}
}
}
}
Execute the test using Maven
Open the terminal and execute:
mvn clean test
Expected result:
Running com.techsarvam.PlaywrightInstallationTest
Tests run: 1
Failures: 0
Errors: 0
BUILD SUCCESS
Playwright Java setup completed
Useful Maven commands
| Command | Purpose |
| mvn clean | Removes previous build output |
| mvn compile | Compiles main Java code |
| mvn test | Executes automated tests |
| mvn clean test | Cleans and executes tests |
| mvn package | Creates the project package |
| mvn verify | Runs verification lifecycle checks |
Maven follows a standard build lifecycle, making it easy to execute automation projects locally and through CI/CD.
Maven+1
11. Troubleshooting Common Playwright Java Installation Errors
Beginners sometimes encounter installation problems while configuring Playwright Java.
Here are common errors and their solutions.
| Error | Possible reason | Solution |
| java is not recognized | Java is missing from PATH | Configure JAVA_HOME and PATH |
| mvn is not recognized | Maven PATH is incorrect | Add Maven bin directory |
| Dependency resolution failed | Maven repository or network issue | Check internet and Maven settings |
| Executable doesn’t exist | Browser binaries are missing | Run Playwright browser installation |
| Browser launch failed | Missing OS dependencies | Install Linux browser dependencies |
| Unsupported class version | JDK mismatch | Configure the correct JDK |
| Browser download timeout | Proxy or firewall restriction | Configure download proxy |
| Browser version mismatch | Playwright dependency upgraded | Reinstall compatible browsers |
Problem 1: Java is not recognized
Error:
‘java’ is not recognized as an internal
or external command
Solution:
- Verify JDK installation.
- Configure JAVA_HOME.
- Add %JAVA_HOME%\bin to PATH.
- Restart the terminal.
- Execute java -version.
Problem 2: Maven dependencies are not downloading
Possible reasons include:
- Internet connectivity problems.
- Incorrect Maven configuration.
- Corporate proxy restrictions.
- Repository access problems.
Try:
mvn -U clean install
The -U option forces Maven to check for updated dependencies.
Problem 3: Browser executable not found
Error:
Executable doesn’t exist
Solution:
Execute:
mvn exec:java -Dexec.mainClass=com.microsoft.playwright.CLI -Dexec.args=”install”
This installs the browser binaries required by your Playwright version.
Problem 4: Browser installation fails behind a proxy
Some corporate networks block browser downloads.
Configure the appropriate HTTPS proxy before running the installation command.
For Windows PowerShell:
$env:HTTPS_PROXY=”http://proxy.example.com:8080″
mvn exec:java -Dexec.mainClass=com.microsoft.playwright.CLI -Dexec.args=”install”
Use your organization’s actual proxy address and port. Playwright also documents custom certificate configuration for restricted corporate networks.
Playwright Java
12. Best Practices and Frequently Asked Questions
Best practices for Playwright Java setup
- Use a supported and consistent JDK version.
- Keep Playwright and browser binaries compatible.
- Manage dependencies through Maven.
- Use JUnit or TestNG for test execution.
- Keep browser setup separate from test logic.
- Close browser and Playwright resources after execution.
- Use Git to maintain automation code.
- Avoid hardcoding environment-specific URLs.
- Verify installation with a simple browser test before building a framework.
- Configure CI/CD after local execution is stable.
Frequently asked questions
Q1. What is Playwright Java installation guide?
It is a step-by-step setup process for installing Java, Maven, Playwright dependencies, and compatible browser binaries to build Java-based browser automation projects.
Q2. Is Playwright Java installation guide suitable for beginners?
Yes. Beginners can follow the installation steps individually, verify each tool, and execute a simple browser automation program.
Q3. What are the benefits of Playwright Java installation guide?
It helps avoid configuration errors, establishes a consistent automation environment, simplifies dependency management, and provides a foundation for building reusable automation frameworks.
Q4. Do I need Node.js for Playwright Java?
No. A normal Playwright Java project uses the official Java library and Maven. Node.js is not a prerequisite for the standard Java installation workflow.
Q5. Which IDE is best for Playwright Java?
IntelliJ IDEA is a popular choice. Eclipse is also suitable for Java automation development.
Q6. Can I use Selenium and Playwright in the same Java project?
Yes. Both libraries can exist in the same Maven project, although they use different browser automation APIs and resource management approaches.
Q7. Does Playwright Java support Chrome and Firefox?
Yes. Playwright supports Chromium, Firefox, and WebKit browser engines.
Q8. Do I need JUnit or TestNG?
You need a test execution framework if you want structured automated test execution. JUnit and TestNG are common choices.
