Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

Playwright supports both Java and JavaScript, with the same core browser automation capabilities in each language. Choose Java when it fits your application stack and team, then pair it with a test framework such as JUnit or TestNG. Choose JavaScript or TypeScript when you want to use Node.js and, optionally, Playwright Test, which includes its own runner and test tooling.

The distinction matters: Playwright Java is a Java API, not JavaScript code translated into Java. A Java test can also execute JavaScript inside a browser page, but that page code runs in a different environment from the Java process.

Choose the language and test setup

Both bindings let you automate Chromium, Firefox and WebKit. The decision is usually about the host language, dependency management and test ecosystem—not a different set of basic browser capabilities.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Consideration Java JavaScript or TypeScript
Host language Java; a natural fit for teams already working in Java. JavaScript or TypeScript running on Node.js.
Dependency management Maven modules in the official getting-started path. npm packages.
Test framework Choose a framework such as JUnit or TestNG; the Java binding does not impose one. Playwright Test offers a dedicated runner, assertions, parallelization, reporting and tracing.
Browser automation Core capabilities include navigation, page interaction and browser control. The same central browser automation capabilities are available.
Browser upkeep Install browser binaries that match the Playwright version in the project. Install browser binaries that match the Playwright version in the project.

For current setup requirements, use the official Playwright Java guide and the Playwright Test guide. Requirements and versions change; verify them when setting up a new project.

How to install Playwright in Java

1. Add the Maven dependency

Playwright for Java is distributed as Maven modules. Add the current compatible version shown by the official Java guide to your project’s pom.xml; avoid copying a version from an old tutorial without checking it.

<dependency>
  <groupId>com.microsoft.playwright</groupId>
  <artifactId>playwright</artifactId>
  <version>CURRENT_COMPATIBLE_VERSION</version>
</dependency>

Replace CURRENT_COMPATIBLE_VERSION with the published version. The official getting-started example specifies Java 8 or higher.

2. Install the browser binaries

After resolving the Maven dependency, use the Java CLI to install Playwright’s browsers. The Java guide documents installing all default browsers, a selected browser, or browser system dependencies. Run the relevant install command documented for your project and operating system. Browser binaries are tied to Playwright releases, so rerun browser installation if a library upgrade leaves the expected browser unavailable.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

3. Launch, navigate and close resources

This standalone Java flow creates Playwright, launches Chromium in headless mode, opens a page, navigates to a URL and closes browser resources:

import com.microsoft.playwright.Browser;
import com.microsoft.playwright.Page;
import com.microsoft.playwright.Playwright;

public class CapturePage {
  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();
    }
  }
}

The try-with-resources block closes the Playwright instance even if the work inside it fails. Close the browser as well when the program is finished with it. To inspect the browser UI while developing, configure launch options with setHeadless(false):

Browser browser = playwright.chromium().launch(
    new com.microsoft.playwright.BrowserType.LaunchOptions().setHeadless(false)
);

Use playwright.firefox().launch() or playwright.webkit().launch() to launch the other supported engines. For test suites, put setup and cleanup in the lifecycle hooks provided by the JUnit or TestNG integration you choose rather than creating a browser separately for every assertion.

4. Use a Java test framework

The Java binding does not require a particular runner. Playwright’s language guidance identifies JUnit and TestNG as options. Choose the one already used by the project, then organize browser creation, test setup, assertions and cleanup using that framework’s conventions.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Can I use Playwright with JavaScript?

Yes. The JavaScript ecosystem offers both the lower-level Playwright browser library and Playwright Test. If you want the integrated runner and test tooling, start with Playwright Test. Its installer prompts for JavaScript or TypeScript, a test directory, an optional CI workflow and browser installation.

Start a Playwright Test project

  1. Install a supported Node.js release. The official guide currently lists Node.js 22.x, 24.x or 26.x; confirm the live requirement before setup because supported releases can change.
  2. In the project directory, run npm init playwright@latest.
  3. Answer the prompts for JavaScript or TypeScript, the test folder, CI workflow and browser installation.
  4. Write a test in the generated test directory and run it with the command generated for the project, commonly npx playwright test.

A representative JavaScript test using the Playwright Test runner looks like this:

import { test, expect } from '@playwright/test';

test('Playwright home page has a title', async ({ page }) => {
  await page.goto('https://playwright.dev/');
  await expect(page).toHaveTitle(/Playwright/);
});

The page fixture is managed by Playwright Test. The runner supplies test discovery, assertions and reporting, and can run tests in parallel or collect traces. For an existing project, use the official guide’s instructions for adding Playwright rather than assuming a new-project scaffold is required.

Use the lower-level Node.js library instead

If you need browser automation in a script rather than the Playwright Test runner, install the Playwright package with npm, install the desired browser binaries and use the library directly. The browser lifecycle is explicit in this example:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
import { chromium } from 'playwright';

const browser = await chromium.launch();
try {
  const page = await browser.newPage();
  await page.goto('https://playwright.dev/');
  console.log(await page.title());
} finally {
  await browser.close();
}

Use the package and import style that matches the project. The lower-level library does not turn a script into a Playwright Test suite; add @playwright/test when you want the dedicated runner and its integrated test features.

Run JavaScript from Playwright Java

A Java test can execute JavaScript in the page with Page.evaluate. The Java process is the host environment; the evaluated function runs in the browser page environment. Ordinary Java variables are not automatically available in the page, and page variables are not automatically Java objects.

String title = page.evaluate("() => document.title").toString();
System.out.println(title);

For values coming from Java, use the evaluation argument supported by the Java API and return a result explicitly. For example, pass a string into a browser-side function rather than referring to a Java local variable from inside the function. Check the Java evaluation documentation for supported signatures and value conversion details. If an evaluated expression returns a promise or is asynchronous, Playwright waits for its completion before returning the result.

This feature is useful for reading or changing page state that the normal locator and interaction APIs do not expose directly. It does not mean that JavaScript is required to write the rest of a Java test.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Which browsers does Playwright support?

Playwright supports Chromium, Firefox and WebKit. It manages browser binaries corresponding to Playwright releases, which helps keep the automation library and browser builds compatible.

  • Use Playwright-managed browsers for the standard setup; install them after adding the dependency and again when needed after upgrading Playwright.
  • Select an engine through the language binding: for example, playwright.chromium() in Java or chromium in the Node.js library.
  • Use branded Chrome or Microsoft Edge through supported browser channels when that is a requirement. Playwright does not install those branded browsers by default, and organizational browser policies can limit automation.

See the browser management guide for Java browser installation and channel details.

Advanced: connect Java to a Node.js browser server

The Java API can connect to an existing browser server launched by Node.js using BrowserType.connect. The connecting and launching Playwright versions must match in major and minor numbers. Treat this as an interoperability path for a deliberate shared-browser architecture, not as a requirement for a normal Java setup. The Java BrowserType.connect API reference documents the connection API.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Keep the setup reliable and diagnose common failures

Browser executable is missing

Symptom: Playwright reports that an executable is missing or the browser cannot be launched. Cause: the browser binaries were not installed, or the project was upgraded to a Playwright release whose matching binaries are absent. Fix: rerun the browser installation command for that language and project, and make sure it installs the browser engine your code launches.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Browser launch fails on a machine or CI runner

Symptom: the browser exits immediately or reports missing system libraries. Cause: required operating-system dependencies are unavailable, or the environment restricts browser execution. Fix: follow the official browser installation instructions for the operating system and install the required system dependencies. In managed environments, check whether policy or sandbox restrictions permit browser automation.

Tests pass locally but fail in another browser

Symptom: a test succeeds in Chromium but fails in Firefox or WebKit. Cause: browser behavior or page timing may differ, or the test may rely on an engine-specific assumption. Fix: run the relevant test against each engine you support and use Playwright’s normal waiting and locator APIs rather than fixed delays where possible. The engine selection is explicit, so ensure the test configuration actually includes the intended browsers.

JavaScript evaluation returns the wrong value or times out

Symptom: an evaluation result is missing, unexpected or not ready. Cause: code is reading a host-language variable as though it existed in the page, or an asynchronous browser operation has not been represented as a returned promise. Fix: pass input through the supported evaluation argument, return the desired value, and make asynchronous page code return or await its promise.

Node.js project setup or imports fail

Symptom: an import cannot be resolved or the test command is unavailable. Cause: the package was not installed in the project, the code uses an import style inconsistent with its module configuration, or the test runner was not added. Fix: verify the package installation and use the command and module conventions generated by the Playwright initializer. Use the browser library for scripts and Playwright Test when the project needs its runner.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Version mismatch in a remote connection

Symptom: Java cannot connect to a Node-launched browser server. Cause: the Playwright versions do not satisfy the required major-and-minor match. Fix: align the versions on both sides before connecting.

Or skip the browser setup

If your goal is a screenshot rather than an automated browser test, [https://screenshotneo.com](https://screenshotneo.com) provides a website screenshot API and MCP server. Make one GET request with a URL:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for request options. Cookie banners, popups and chat widgets are removed before the shot; bot checks, blank pages and failed loads are never billed. An MCP server lets AI agents use screenshot tools. The Free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000.

Sign up for ScreenshotNeo free: 1,000 screenshots a month, no card required.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Frequently Asked Questions

Does Playwright Java require JavaScript?

No. Java is the host language for the test; JavaScript is only needed if you deliberately evaluate code inside the browser page.

Can Java and Node.js connect to the same Playwright browser?

The Java API supports connecting to a browser server launched by Node.js, provided the Playwright versions match in major and minor numbers.

Do Java and JavaScript Playwright tests support the same browser engines?

Both bindings support Chromium, Firefox and WebKit through Playwright-managed browser binaries.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.