Skip to content

Latest commit

 

History

History
175 lines (123 loc) · 8.78 KB

CONTRIBUTING.md

File metadata and controls

175 lines (123 loc) · 8.78 KB

Contributing

Choosing an Issue

To maintain project quality and focus, Playwright requires a corresponding issue for every contribution, with the exception of minor documentation fixes.

If you would like to address a bug or feature that isn't currently listed, please file a new issue first. This allows the community and maintainers to provide early feedback and facilitates a discussion before you invest time in developing a pull request.

When submitting an issue, please state clearly if you intend to work on it. Once triaged and approved, the maintainers will determine the best path forward—whether the task should be handled by the core team, an automated agent, or a community contributor. If the issue is assigned to you, you may then proceed with your changes and submit a PR.

Submission Policy

To ensure the maintainability of the project, please note the following:

  • Unsolicited PRs: Pull requests submitted without a linked issue or prior approval will be closed.
  • Low-Quality AI Contributions: PRs that do not meet our quality standards or lack human oversight (including low-quality agentic submissions) will be closed without explanation.
  • Approval Required: Only proceed with a PR once the issue has been officially assigned to you or approved for community contribution.

How to Contribute

Installing Developer Tools

Install git, Java JDK (version >= 8), Maven (tested with version 3.6.3), on Ubuntu 20.04 just run the following command:

sudo apt-get install git openjdk-11-jdk maven unzip

Getting the Code

  1. Clone this repository
git clone https://github.com/microsoft/playwright-java
cd playwright-java
  1. Run the following script to build and assemble the Playwright driver; it needs git and Node.js with npm. The platform-independent playwright-core package is assembled once into driver/src/main/resources/driver/package/, and the Node.js binary for each platform into driver-bundle/src/main/resources/driver/<platform>/ (browser binaries for Chromium, Firefox and WebKit will be automatically downloaded later on first Playwright run).
scripts/build_driver.sh

The driver is built from source: the script clones microsoft/playwright into .upstream/ (gitignored), checks out the commit pinned in scripts/DRIVER_VERSION and builds the playwright-core package from it (npm ci, npm run build, npm pack). The build of .upstream/ is reused until the commit changes. Each driver also gets the Node.js binary of the version pinned in scripts/NODE_VERSION from https://nodejs.org, the same way the upstream Playwright build does it. Run the script again when scripts/DRIVER_VERSION or scripts/NODE_VERSION changes, for example after a pull. scripts/roll_driver.sh updates the pinned Node.js version to the latest release of the same major version on each roll. To update only Node.js, run scripts/roll_node.sh and then scripts/build_driver.sh.

Building and running the tests with Maven

mvn compile
# Runs every test in Chromium, Firefox and WebKit
mvn test
# Selecting browsers
BROWSER=chromium mvn test
BROWSER=firefox,webkit mvn test
# Executing a single test
BROWSER=chromium mvn test -Dtest=TestPageNetworkSizes#shouldHaveTheCorrectResponseBodySize
# Executing a single test class
BROWSER=chromium mvn test -Dtest=TestPageNetworkSizes

Set HEADED=1 to watch the browsers and BROWSER_CHANNEL=chrome (or msedge, ...) to test a stable channel.

Writing tests

Tests use the fixtures from playwright/src/test/java/com/microsoft/playwright/fixtures, modeled after the upstream Playwright Test fixtures. A test is a @PlaywrightTest method that declares the fixtures it needs as parameters; it runs once per selected browser, in a fresh context:

@PlaywrightTest
void shouldWork(Page page, Server server) {
  page.navigate(server.EMPTY_PAGE);
}

The built-in fixtures are Playwright, BrowserName, BrowserType, BrowserType.LaunchOptions, Browser, Browser.NewContextOptions, BrowserContext, Page, Server and HttpsServer. Playwright, the browser and the test servers are shared by the tests that run one after another on the same thread; the context and the page are created for each test and closed afterwards. A test class adds or overrides fixtures with @Fixture methods, whose parameters are the fixtures they depend on:

@Fixture
Browser.NewContextOptions contextOptions() {
  return new Browser.NewContextOptions().setHasTouch(true);
}

@Fixture(scope = Scope.WORKER)
static BrowserType.LaunchOptions launchOptions(BrowserType.LaunchOptions defaults) {
  return defaults.setArgs(asList("--enable-features=WebMCP"));
}

Use @DisabledOnBrowser / @EnabledOnBrowser for browser-specific tests, and a @Nested @ParameterizedClass with a @Fixture method reading its @Parameter field to run the same tests with different options.

Generating API

Public Java API is generated by scripts/generate_java_api.mts from the API docs (docs/src/api/*.md) in .upstream/, the microsoft/playwright checkout at the commit in scripts/DRIVER_VERSION that the driver is built from (run scripts/build_driver.sh first). Set PW_SRC_DIR to generate from another microsoft/playwright checkout instead, to try a change to the upstream docs; the committed files must come from .upstream/. The generator is a TypeScript file that Node.js runs as is, so it needs Node.js 22.18 or newer. To regenerate Java interfaces for the current driver run:

./scripts/generate_api.sh

Updating driver version

The driver does not depend on a published Playwright version. To roll the driver to a newer commit of microsoft/playwright, run the following command:

scripts/roll_driver.sh [main|release-1.<minor>|<commit>]

main (the default) is the tip of upstream main, release-1.<minor> is the tip of that upstream release branch, and <commit> is a full commit hash. The script writes the commit to scripts/DRIVER_VERSION, builds the driver from it and regenerates the API. The driver reports the version of packages/playwright-core/package.json at that commit: 1.67.0-next on main, 1.66.0 on release-1.66.

Code Style

  • We try to follow Google Java Style Guide
  • Comments should be generally avoided. If the code would not be understood without comments, consider re-writing the code to make it self-explanatory.

Code reviews

All submissions, including submissions by project members, require review. We use GitHub pull requests for this purpose. Consult GitHub Help for more information on using pull requests.

Commit Messages

Commit messages should follow the Semantic Commit Messages format:

label(namespace): title

description

footer
  1. label is one of the following:
    • fix - playwright bug fixes.
    • feat - playwright features.
    • docs - changes to docs, e.g. docs(api.md): .. to change documentation.
    • test - changes to playwright tests infrastructure.
    • devops - build-related work, e.g. CI related patches and general changes to the browser build infrastructure
    • chore - everything that doesn't fall under previous categories
  2. namespace is put in parenthesis after label and is optional. Must be lowercase.
  3. title is a brief summary of changes.
  4. description is optional, new-line separated from title and is in present tense.
  5. footer is optional, new-line separated from description and contains "fixes" / "references" attribution to github issues.

Example:

fix(firefox): make sure session cookies work

This patch fixes session cookies in firefox browser.

Fixes #123, fixes #234

Contributor License Agreement

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

Code of Conduct

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.