Free tools Windows power users keep installed
One-click scans. No signup required.
The fastest reliable way to learn Playwright with Java is to progress from a minimal Maven program to locator-driven tests, isolated browser contexts, a test runner, debugging tools, API setup, and finally CI. Start by launching one browser and reading a title; only then build a suite. This sequence follows the current Playwright Java documentation, whose installation page lists Java 8 or later and currently shows Playwright dependency version 1.63.0 (verify the page before starting because versions and supported operating systems change).
1. Check Java, Maven, and your operating system
Playwright Java is a Maven-based workflow. Install a supported JDK (Java 8 or later according to the current documentation) and Maven, then verify both from a terminal:
java -version
mvn -version
The installation guide currently lists Windows 11 and Windows Server 2019 or later (or WSL), macOS 14 Sonoma or later, and Debian 12/13 or Ubuntu 22.04/24.04/26.04 on x86-64 or arm64. Check that page for changes before choosing a machine or CI image.
What you should already know
- Java classes, methods, exceptions, and try-with-resources.
- Basic Maven commands and the purpose of
pom.xml. - HTML concepts such as links, buttons, labels, and form fields.
- How assertions work in your chosen test framework, eventually JUnit or TestNG.
2. Create a Maven project and add Playwright
Create a standard Maven project, then add the Playwright dependency shown by Microsoft. The documentation currently displays version 1.63.0; use the current value on the page when you create your project.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchPC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11<dependency>
<groupId>com.microsoft.playwright</groupId>
<artifactId>playwright</artifactId>
<version>1.63.0</version>
</dependency>
For a first executable class, configure the Maven Exec plugin or use the command documented by Playwright:
mvn compile exec:java -D exec.mainClass="org.example.App"
Do not treat the displayed version as permanent. A Playwright update can require new browser binaries, so update the dependency and installation together.
3. Run the smallest useful Java program
Your first milestone is not a full test suite. It is a program that creates Playwright, launches Chromium, opens a page, and proves that navigation worked.
package org.example;
import com.microsoft.playwright.*;
public class App {
public static void main(String[] args) {
try (Playwright playwright = Playwright.create()) {
Browser browser = playwright.chromium().launch();
Page page = browser.newPage();
page.navigate("https://playwright.dev");
System.out.println(page.title());
browser.close();
}
}
}
Playwright runs headless by default. To watch the browser while learning, launch with setHeadless(false):
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Browser browser = playwright.chromium().launch(
new BrowserType.LaunchOptions().setHeadless(false));
Once this works, save a screenshot and try another engine:
Browser browser = playwright.webkit().launch();
Page page = browser.newPage();
page.navigate("https://playwright.dev");
page.screenshot(new Page.ScreenshotOptions().setPath(java.nio.file.Paths.get("home.png")));
browser.close();
4. Install and understand browser binaries
Playwright does not simply drive whatever browser happens to be installed. Each Playwright release expects matching browser builds. Install the defaults with the Java CLI:
Rank #2
mvn exec:java -e
-D exec.mainClass=com.microsoft.playwright.CLI
-D exec.args="install"
You can install a named engine when needed, for example chromium, firefox, or webkit. Playwright supports all three; its Firefox and WebKit builds are Playwright-managed builds, not branded Firefox or Safari. If your target environment specifically requires branded Chrome or Edge, consult the browser-channel documentation and select the appropriate channel.
After changing the Playwright dependency, run browser installation again. In Linux CI, the documented pattern is install --with-deps, which installs browser dependencies as well as the browser. Pin your Maven version and cache downloaded binaries only when your CI policy can invalidate the cache after upgrades.
5. Learn locators and web-first assertions
Locators are the core Playwright skill. They identify elements and automatically wait for them to become usable. Prefer user-facing contracts over DOM details: role, accessible name, label, text, and a deliberate test ID. CSS and XPath are fallback tools, not your starting point.
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
page.navigate("https://playwright.dev");
assertThat(page).hasTitle("Playwright");
Locator getStarted = page.getByRole(
AriaRole.LINK,
new Page.GetByRoleOptions().setName("Get started"));
assertThat(getStarted).hasAttribute("href", "/docs/intro");
getStarted.click();
assertThat(page.getByRole(
AriaRole.HEADING,
new Page.GetByRoleOptions().setName("Installation"))).isVisible();
assertThat performs a web-first assertion: it retries until the condition is met or the timeout expires. That is safer than reading a value once and immediately asserting it. The Java writing-tests guide shows this style and additional locator examples.
Locator choice in practice
- Role and name: use for buttons, links, headings, checkboxes, and other accessible controls.
- Label: use for form inputs associated with a visible label.
- Text: useful for stable, user-visible copy, but avoid long sentences likely to change.
- Test ID: add a dedicated attribute when a control has no stable user-facing identity.
- CSS or XPath: reserve for genuinely structural cases; generated class names and deep paths are brittle.
6. Make every test isolated
A BrowserContext is an in-memory, isolated browser profile containing cookies, local storage, permissions, and related state. Reuse a browser process if desired, but create and close a new context and page for each test. This prevents a login, cookie, or storage value from leaking into another test.
try (Playwright playwright = Playwright.create()) {
Browser browser = playwright.chromium().launch();
BrowserContext context = browser.newContext();
Page page = context.newPage();
page.navigate("https://playwright.dev");
// test actions and assertions
context.close();
browser.close();
}
Keep cleanup in framework lifecycle methods or try-with-resources so failures do not leave processes running.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →7. Move from a script to JUnit or TestNG
A standalone class is ideal for your first hour. A suite needs discovery, setup and teardown, reporting, and a policy for parallel execution. Playwright documents both JUnit and TestNG routes in its test-runner guide; choose the framework your team already maintains rather than assuming one is universally better.
Typical JUnit lifecycle
- Create one Playwright and browser at suite or class scope.
- Before each test, create a fresh context and page.
- Run actions and web-first assertions.
- After each test, close the context; after the suite, close the browser and Playwright.
The dedicated @UsePlaywright fixture integration is marked experimental. Conventional JUnit lifecycle methods, or the documented TestNG equivalents, make ownership and cleanup explicit.
Parallel tests
Do not share Playwright objects across threads without synchronization. The Java guidance recommends one Playwright instance per thread. Context isolation is necessary but does not make a single Playwright instance automatically thread-safe.
8. Use Codegen to learn, then rewrite the result
Codegen opens a browser and Playwright Inspector, records interactions, and can add visibility, text, and value assertions. Its locator suggestions prioritize role, text, and test ID. Treat generated code as a learning aid:
- Record the shortest realistic user journey.
- Inspect every generated locator and replace accidental CSS or XPath with a stable role, label, or test ID.
- Add assertions that express the business outcome, not just that a click occurred.
- Remove redundant waits and actions, then place the test in your normal runner.
Read the current command and language options in Generating tests. Maintaining the resulting test still requires Java and locator knowledge.
9. Add API testing after browser fundamentals
APIRequestContext lets a Java test call REST endpoints directly. Use it after you understand browser tests, mainly to prepare server state quickly or verify a server-side result after a UI action. This avoids forcing every setup step through the interface while keeping the user-visible workflow under test.
Rank #4
The API testing guide covers request contexts, authentication, responses, and cleanup. Keep API setup data isolated just as you isolate browser contexts, and avoid coupling tests to undocumented internal endpoints.
10. Debug with traces, then run in CI
When a test fails, first run it headed and inspect the locator. Then use Playwright’s trace tooling to review actions, snapshots, and network information after the run. Traces are especially useful for failures that cannot be reproduced locally.
In CI, install the exact browsers required by the project and include operating-system dependencies where the runner needs them:
mvn exec:java -e
-D exec.mainClass=com.microsoft.playwright.CLI
-D exec.args="install --with-deps"
- Keep browser installation tied to the Playwright dependency version.
- Set CI secrets through environment variables, never source code.
- Upload screenshots, videos, and traces as artifacts on failure.
- Start with serial execution; add parallelism only after each test owns its context and data.
- Use retries sparingly. A retry can expose a flaky dependency but should not hide a deterministic defect.
Or skip the browser setup
If your goal is to obtain a clean screenshot rather than learn browser automation internals, ScreenshotNeo provides a single website-screenshot API request. Before capture it accepts cookie or consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each behavior can be turned off. 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.
Use the API directly from Java or any shell. The complete documentation is at screenshotneo.com/docs/.
cURL
curl -G "https://api.screenshotneo.com/v1/shot"
-d access_key=YOUR_API_KEY
--data-urlencode url=https://stripe.com
-o shot.webp
Python
import requests
r = requests.get(
"https://api.screenshotneo.com/v1/shot",
params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"},
timeout=90,
)
r.raise_for_status()
open("shot.webp", "wb").write(r.content)
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}`);
if (!res.ok) throw new Error(`${res.status} ${res.statusText}`);
const fs = await import('node:fs/promises');
await fs.writeFile('shot.webp', Buffer.from(await res.arrayBuffer()));
ScreenshotNeo also supports full-page and element captures, 12 device presets or custom viewports, dark mode, retina scale, PDF output, custom CSS and JavaScript, clicks, selector or network-idle waits, request blocking, headers, cookies, authorization, timezone, geolocation, transparent backgrounds, resizing, TTL caching, signed links, asynchronous webhooks, bulk capture of up to 100 URLs per call, usage reporting, and an OpenAPI specification. Its parameter names are compatible with those used by other screenshot APIs, which can simplify migration. An MCP server exposes take_screenshot, get_page_info, and capture_pdf to Claude, Cursor, and other MCP clients, so an AI agent can capture pages without you writing browser lifecycle code.
Recommended Free Tools
| Plan | Included screenshots | Price |
|---|---|---|
| Free | 1,000 per month | $0; no card |
| Starter | 3,000 | $5 |
| Growth | 15,000 | $15 |
| Pro | 60,000 | $39 |
| Scale | 250,000 | $99 |
| Business | 1,000,000 | $249 |
Every feature is included on every plan, and yearly billing gives two months free. Create a free ScreenshotNeo account to use 1,000 screenshots a month without a card.
Best Value
Troubleshooting common learning failures
“Executable doesn’t exist” or browser launch fails
The browser binaries are missing or do not match the dependency. Run the Playwright CLI install command again; on Linux CI use install --with-deps. Repeat after upgrading Playwright.
A locator times out
Check the accessible role and name in the Inspector, confirm the page actually reached the expected URL, and replace a generated CSS path with a role, label, text, or test ID. Do not solve a synchronization problem with arbitrary sleeps; wait for a meaningful locator or assertion.
Tests pass alone but fail in the suite
State is leaking between tests. Create a new BrowserContext for each test, clear test data on the server, and verify that parallel workers do not share accounts or mutable fixtures.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →It works locally but fails in CI
Compare Java, Playwright, browser, and operating-system versions; install dependencies in the image; collect a trace and screenshot; and check viewport, timezone, credentials, and network access. A headed run may also fail on a machine without a display, so keep CI headless unless a virtual display is configured.
A study plan you can follow
- Session 1: install Java, Maven, Playwright, and browsers; run the title-and-screenshot program.
- Session 2: practice role, label, text, and test-ID locators with web-first assertions.
- Session 3: convert the script into two isolated JUnit or TestNG tests.
- Session 4: record a flow with Codegen, review every locator, and debug a deliberate failure with traces.
- Session 5: use APIRequestContext to seed data and verify a server response.
- Session 6: install browsers in CI, publish artifacts, and introduce parallel workers only after isolation is reliable.
Frequently Asked Questions
Can I use Playwright Java without Maven?
The official Java examples use Maven to declare the dependency and run the CLI. Other build systems may be possible, but the documented learning path is Maven.
Should I learn Selenium before Playwright?
No. Basic Java, Maven, HTML, and test concepts are enough to begin; Playwright’s own Java examples provide the browser automation progression.
Is Playwright WebKit the same as Safari?
No. Playwright distributes a WebKit build based on upstream WebKit with Playwright patches; use a branded browser channel when your testing requirement is specifically Chrome or Edge.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Repair Windows errors before they cause bigger problems3Scan for outdated or missing drivers - takes under a minuteQuick 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.

