Free tools Windows power users keep installed
One-click scans. No signup required.
The quickest useful Java Playwright project has four parts: a build file that adds the Playwright library, a browser installation step, a small Java program or test, and a command that runs it. The examples below show both Maven and Gradle layouts, a web-first assertion, browser selection, and the extra setup required in continuous integration (CI).
What you need before creating a project
- Java 8 or newer. Playwright Java supports current Windows, Linux, and macOS releases; check the live Playwright requirements for the exact operating-system and architecture list because it changes.
- A build tool. Use Maven if your repository already has a
pom.xml, or Gradle if it usesbuild.gradleorbuild.gradle.kts. Do not combine dependency and test-runner snippets from both systems in one project. - Playwright browser binaries. The binaries are tied to the Playwright library version. Installing or upgrading the Java dependency does not automatically make every browser executable available.
- A test runner (for a test project). The official Java examples show integration with common Java runners. The first sample below is a plain executable; the later sample uses JUnit-style tests.
Minimal Maven project that opens a page
1. Create the files
Make this directory structure:
playwright-java-sample/
├── pom.xml
└── src/
└── main/
└── java/
└── org/
└── example/
└── App.java
2. Add the Playwright dependency
The Java introduction used Playwright Java 1.63.0 at the time its example was captured. Treat that as an example, not a permanent recommendation: confirm the current version in the official documentation before creating a new project.
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>playwright-java-sample</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<playwright.version>1.63.0</playwright.version>
</properties>
<dependencies>
<dependency>
<groupId>com.microsoft.playwright</groupId>
<artifactId>playwright</artifactId>
<version>${playwright.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.5.0</version>
<configuration>
<mainClass>org.example.App</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
3. Write App.java
package org.example;
import com.microsoft.playwright.Browser;
import com.microsoft.playwright.BrowserType;
import com.microsoft.playwright.Page;
import com.microsoft.playwright.Playwright;
public class App {
public static void main(String[] args) {
try (Playwright playwright = Playwright.create()) {
Browser browser = playwright.chromium().launch(
new BrowserType.LaunchOptions().setHeadless(true));
Page page = browser.newPage();
page.navigate("https://playwright.dev/");
System.out.println(page.title());
browser.close();
}
}
}
The try-with-resources block closes Playwright even if navigation fails. headless=true is suitable for CI; set it to false while diagnosing a local interaction.
4. Install browsers and run it
Install the browser binaries for the version in your project with the Playwright CLI command documented for Java, then run:
mvn compile exec:java -Dexec.mainClass="org.example.App"
A title printed in the terminal confirms that Java started Playwright, launched its managed Chromium, navigated, and read the document. Playwright also supports managed Firefox and WebKit; select one explicitly when your test needs it.
Turn the program into a real test
Use locators and web-first assertions
Playwright waits for an element to become actionable and retries web-first assertions. That is more reliable than inserting arbitrary sleeps for every page transition.
package org.example;
import com.microsoft.playwright.*;
import org.junit.jupiter.api.*;
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
public class HomePageTest {
static Playwright playwright;
static Browser browser;
Page page;
@BeforeAll
static void startBrowser() {
playwright = Playwright.create();
browser = playwright.chromium().launch(
new BrowserType.LaunchOptions().setHeadless(true));
}
@BeforeEach
void createPage() {
page = browser.newPage();
}
@Test
void homePageHasExpectedHeading() {
page.navigate("https://playwright.dev/");
assertThat(page.locator("h1")).containsText("Playwright");
}
@AfterEach
void closePage() {
page.close();
}
@AfterAll
static void stopBrowser() {
browser.close();
playwright.close();
}
}
Prefer accessible roles, labels, and stable test IDs over brittle CSS chains. For example, page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Sign in")) documents the user-visible contract. Keep one browser process for a test class when appropriate, but isolate each test in its own page or browser context so cookies and local storage do not leak.
Maven test-runner setup
For a Maven test project, place the class under src/test/java and add the JUnit Jupiter API and engine versions selected by your organization. Configure Maven Surefire to run the tests. The exact runner versions are independent of Playwright; keep them aligned with your Java baseline and existing repository conventions. Then use:
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Clear out junk files and repair common Windows errors3Scan for outdated or missing drivers - takes under a minuteRank #2
mvn test
If your organization uses TestNG or another runner, keep the Playwright lifecycle pattern (one context per test or fixture) and replace only the runner annotations and Maven test configuration.
Equivalent Gradle project
Groovy DSL
plugins {
id 'java'
}
repositories {
mavenCentral()
}
def playwrightVersion = '1.63.0' // verify the current version before use
dependencies {
testImplementation "com.microsoft.playwright:playwright:${playwrightVersion}"
testImplementation 'org.junit.jupiter:junit-jupiter:5.12.2'
}
test {
useJUnitPlatform()
}
Put the test in src/test/java, install the matching Playwright browsers, and run:
./gradlew test
Choosing Maven or Gradle
| Situation | Better starting point | Run command |
|---|---|---|
Your repository already has a pom.xml and Maven conventions |
Maven | mvn test (or the executable command above) |
| Your repository already has Gradle tasks, a version catalog, or Kotlin/Groovy build logic | Gradle | ./gradlew test |
| You only need a one-file proof of navigation | Maven executable sample | mvn compile exec:java -Dexec.mainClass="org.example.App" |
Browser choices and installation
Playwright’s single Java API controls Chromium, Firefox, and WebKit. These are Playwright-managed browser builds, not automatically the same binaries as branded Chrome or Edge. Install only what your suite needs, using the CLI command from the browser-installation guide; when a dependency upgrade changes the Playwright version, run the installation again.
# Examples of the documented CLI forms; use the form matching your installed Playwright CLI
mvn exec:java -Dexec.mainClass="com.microsoft.playwright.CLI" -Dexec.args="install"
# Install a selected browser when your project requires only one engine
mvn exec:java -Dexec.mainClass="com.microsoft.playwright.CLI" -Dexec.args="install chromium"
In code, replace playwright.chromium() with playwright.firefox() or playwright.webkit() for cross-engine coverage. Keep the browser choice explicit in CI so a machine’s preinstalled browser cannot silently change the result.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Run the project in CI
- Install the required Java runtime and resolve Maven or Gradle dependencies.
- Install the Playwright browser binaries for the exact library version.
- Install operating-system libraries required by those browsers. Linux runners commonly need the dependency-install option supplied by the Playwright CLI.
- Run
mvn test,./gradlew test, or the executable Maven command. - Cache browser binaries only with a key that includes the Playwright version. Reuse a cache after a Playwright upgrade only if the key changes and the new binaries are installed.
Keep CI runs headless, publish traces or screenshots from failures when your runner supports artifacts, and avoid relying on a developer’s globally installed Chrome. The official CI guidance covers provider-specific examples; the invariant sequence is install Java dependencies, install browsers and OS dependencies, then execute the test task.
Troubleshooting common failures
“Executable doesn’t exist” or browser launch failure
The matching browser binary is missing or a cache contains an older Playwright version. Run the CLI browser installation for the dependency version actually resolved by Maven or Gradle, invalidate the old cache, and retry.
Linux reports missing shared libraries
Install the browser’s OS dependencies on the runner, using the dependency-install option documented by Playwright, or use a CI image that already provides them. Merely adding the Java dependency is not enough.
The test times out while clicking
Check the locator and the page state first. Use a role, label, or test ID; wait for a meaningful condition such as visibility or URL; and inspect the page headed by the failure. Do not replace every timeout with a long fixed sleep, which hides the real synchronization issue.
Recommended Free Tools
Rank #4
Assertions are flaky
Use Playwright’s retrying assertions such as assertThat(locator).hasText() rather than reading text once and comparing immediately. Isolate test data and browser context, and make network-dependent fixtures deterministic where possible.
Works locally but fails in CI
Compare Java, Playwright, browser, and operating-system versions; confirm the runner is not headed without a display; install Linux dependencies; and verify that environment variables, authentication, and viewport assumptions exist in CI.
Navigation reaches a bot check or blank page
That is an application or environment response, not a locator problem. Record the URL, response status, redirects, and CI egress policy. If the goal is a visual capture rather than an interactive test, an API can avoid maintaining browser infrastructure.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Or skip the browser setup
For a screenshot rather than a Java interaction test, ScreenshotNeo provides a single HTTP request. It accepts consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup step can be disabled. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing result. Its MCP server exposes take_screenshot, get_page_info, and capture_pdf to Claude, Cursor, and other MCP clients.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →See the full parameter list in the ScreenshotNeo documentation. This cURL request captures a WebP image:
Best Value
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
Equivalent Python:
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
Equivalent Node.js:
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
It also supports full-page and element captures, device presets, custom viewports, retina scale, PDFs, HTML/CSS rendering, custom JavaScript and CSS, clicks, waits, request blocking, headers, cookies, user agents, authorization, timezone, geolocation, transparent backgrounds, resizing, TTL caching, signed image links, asynchronous webhooks, bulk requests for up to 100 URLs, and a usage API. Every feature is on every plan. The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000. Create a free ScreenshotNeo account.
FAQ
Can one Java project test all three browser engines?
Yes. Use the same Playwright API and create Chromium, Firefox, and WebKit projects or parameterized runs, installing the corresponding managed binaries first.
Should I use a fixed delay after every navigation?
No. Locators and web-first assertions wait for actionable, expected states. Add a targeted wait only when it represents a real application condition, such as a specific response or selector.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Is Playwright Java a replacement for Selenium?
They solve overlapping browser-automation problems, but this article does not establish a feature-by-feature comparison. Choose based on your existing test ecosystem, browser policy, and team experience.
Frequently Asked Questions
Can one Java project test all three browser engines?
Yes. Use the same Playwright API and create Chromium, Firefox, and WebKit projects or parameterized runs, installing the corresponding managed binaries first.
Should I use a fixed delay after every navigation?
No. Locators and web-first assertions wait for actionable, expected states. Add a targeted wait only when it represents a real application condition, such as a specific response or selector.
Is Playwright Java a replacement for Selenium?
They solve overlapping browser-automation problems, but this article does not establish a feature-by-feature comparison. Choose based on your existing test ecosystem, browser policy, and team experience.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

