microsoft/playwright-java
 Watch   
 Star   
 Fork   
28 days ago
playwright-java

v1.43.0

New APIs

  • Method browserContext.clearCookies([options]) now supports filters to remove only some cookies.

    // Clear all cookies.
    context.clearCookies();
    // New: clear cookies with a particular name.
    context.clearCookies(new BrowserContext.ClearCookiesOptions().setName("session-id"));
    // New: clear cookies for a particular domain.
    context.clearCookies(new BrowserContext.ClearCookiesOptions().setDomain("my-origin.com"));
  • New method locator.contentFrame() converts a Locator object to a FrameLocator. This can be useful when you have a Locator object obtained somewhere, and later on would like to interact with the content inside the frame.

    Locator locator = page.locator("iframe[name='embedded']");
    // ...
    FrameLocator frameLocator = locator.contentFrame();
    frameLocator.getByRole(AriaRole.BUTTON).click();
  • New method frameLocator.owner() converts a FrameLocator object to a Locator. This can be useful when you have a FrameLocator object obtained somewhere, and later on would like to interact with the iframe element.

    FrameLocator frameLocator = page.frameLocator("iframe[name='embedded']");
    // ...
    Locator locator = frameLocator.owner();
    assertThat(locator).isVisible();

Browser Versions

  • Chromium 124.0.6367.8
  • Mozilla Firefox 124.0
  • WebKit 17.4

This version was also tested against the following stable channels:

  • Google Chrome 123
  • Microsoft Edge 123
2024-03-12 08:00:17
playwright-java

v1.42.0

JUnit integration

[!WARNING] This feature is experimental, we are actively looking for the feedback based on your scenarios.

Add new @UsePlaywright annotation to your test classes to start using Playwright fixtures for Page, BrowserContext, Browser, APIRequestContext and Playwright in the test methods.

package org.example;

import com.microsoft.playwright.Page;
import com.microsoft.playwright.junit.UsePlaywright;
import org.junit.jupiter.api.Test;

import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;

@UsePlaywright
public class TestExample {
  void shouldNavigateToInstallationGuide(Page page) {
    page.navigate("https://playwright.dev/java/");
    page.getByRole(AriaRole.LINK, new Page.GetByRoleOptions().setName("Docs")).click();
    assertThat(page.getByRole(AriaRole.HEADING, new Page.GetByRoleOptions().setName("Installation"))).isVisible();
  }

  @Test
  void shouldCheckTheBox(Page page) {
    page.setContent("<input id='checkbox' type='checkbox'></input>");
    page.locator("input").check();
    assertEquals(true, page.evaluate("window['checkbox'].checked"));
  }

  @Test
  void shouldSearchWiki(Page page) {
    page.navigate("https://www.wikipedia.org/");
    page.locator("input[name=\"search\"]").click();
    page.locator("input[name=\"search\"]").fill("playwright");
    page.locator("input[name=\"search\"]").press("Enter");
    assertThat(page).hasURL("https://en.wikipedia.org/wiki/Playwright");
  }
}

In the example above, all three test methods use the same Browser. Each test uses its own BrowserContext and Page.

Custom options

Implement your own OptionsFactory to initialize the fixtures with custom configuration.

import com.microsoft.playwright.junit.Options;
import com.microsoft.playwright.junit.OptionsFactory;
import com.microsoft.playwright.junit.UsePlaywright;

@UsePlaywright(MyTest.CustomOptions.class)
public class MyTest {

  public static class CustomOptions implements OptionsFactory {
    @Override
    public Options getOptions() {
      return new Options()
          .setHeadless(false)
          .setContextOption(new Browser.NewContextOptions()
              .setBaseURL("https://github.com"))
          .setApiRequestOptions(new APIRequest.NewContextOptions()
              .setBaseURL("https://playwright.dev"));
    }
  }

  @Test
  public void testWithCustomOptions(Page page, APIRequestContext request) {
    page.navigate("/");
    assertThat(page).hasURL(Pattern.compile("github"));

    APIResponse response = request.get("/");
    assertTrue(response.text().contains("Playwright"));
  }
}

Learn more about the fixtures in our JUnit guide.

New Locator Handler

New method page.addLocatorHandler(locator, handler, handler, handler) registers a callback that will be invoked when specified element becomes visible and may block Playwright actions. The callback can get rid of the overlay. Here is an example that closes a cookie dialog when it appears.

// Setup the handler.
page.addLocatorHandler(
    page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Hej! You are in control of your cookies.")),
    () - > {
        page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Accept all")).click();
    });
// Write the test as usual.
page.navigate("https://www.ikea.com/");
page.getByRole(AriaRole.LINK, new Page.GetByRoleOptions().setName("Collection of blue and white")).click();
assertThat(page.getByRole(AriaRole.HEADING, new Page.GetByRoleOptions().setName("Light and easy"))).isVisible();

New APIs

  • page.pdf() accepts two new options tagged and outline.

Announcements

  • ⚠️ Ubuntu 18 is not supported anymore.

Browser Versions

  • Chromium 123.0.6312.4
  • Mozilla Firefox 123.0
  • WebKit 17.4

This version was also tested against the following stable channels:

  • Google Chrome 122
  • Microsoft Edge 123
2024-02-02 08:42:13
playwright-java

v1.41.2

Highlights

https://github.com/microsoft/playwright/issues/29123 - [REGRESSION] route.continue: Protocol error (Fetch.continueRequest): Invalid InterceptionId. https://github.com/microsoft/playwright-java/issues/1468 - [BUG] File Upload leads to "Exactly one of payloads, localPaths and streams must be provided"

Browser Versions

  • Chromium 121.0.6167.57
  • Mozilla Firefox 121.0
  • WebKit 17.4

This version was also tested against the following stable channels:

  • Google Chrome 120
  • Microsoft Edge 120
2024-01-26 05:08:40
playwright-java

v1.41.1

Highlights

https://github.com/microsoft/playwright/issues/29067 - [REGRESSION] Codegen/Recorder: not all clicks are being actioned nor recorded https://github.com/microsoft/playwright/issues/29019 - [REGRESSION] trace.playwright.dev does not currently support the loading from URL

Browser Versions

  • Chromium 121.0.6167.57
  • Mozilla Firefox 121.0
  • WebKit 17.4

This version was also tested against the following stable channels:

  • Google Chrome 120
  • Microsoft Edge 120
2024-01-18 07:57:30
playwright-java

v1.41.0

New APIs

Browser Versions

  • Chromium 121.0.6167.57
  • Mozilla Firefox 121.0
  • WebKit 17.4

This version was also tested against the following stable channels:

  • Google Chrome 120
  • Microsoft Edge 120
2023-11-21 03:36:57
playwright-java

v1.40.0

Test Generator Update

Playwright Test Generator

New tools to generate assertions:

Here is an example of a generated test with assertions:

page.navigate("https://playwright.dev/");
page.getByRole(AriaRole.LINK, new Page.GetByRoleOptions().setName("Get started")).click();
assertThat(page.getByLabel("Breadcrumbs").getByRole(AriaRole.LIST)).containsText("Installation");
assertThat(page.getByLabel("Search")).isVisible();
page.getByLabel("Search").click();
page.getByPlaceholder("Search docs").fill("locator");
assertThat(page.getByPlaceholder("Search docs")).hasValue("locator");

New APIs

Other Changes

Browser Versions

  • Chromium 120.0.6099.28
  • Mozilla Firefox 119.0
  • WebKit 17.4

This version was also tested against the following stable channels:

  • Google Chrome 119
  • Microsoft Edge 119
2023-10-14 05:01:59
playwright-java

v1.39.0

Evergreen browsers update.

Browser Versions

  • Chromium 119.0.6045.9
  • Mozilla Firefox 118.0.1
  • WebKit 17.4

This version was also tested against the following stable channels:

  • Google Chrome 118
  • Microsoft Edge 118
2023-09-19 08:32:02
playwright-java

v1.38.0

Trace Viewer Updates

Playwright Trace Viewer

  1. Zoom into time range.
  2. Network panel redesign.

New APIs

Browser Versions

  • Chromium 117.0.5938.62
  • Mozilla Firefox 117.0
  • WebKit 17.0

This version was also tested against the following stable channels:

  • Google Chrome 116
  • Microsoft Edge 116
2023-08-15 00:08:57
playwright-java

v1.37.0

New APIs

  • New methods BrowserContext.newCDPSession() and Browser.newBrowserCDPSession() create a Chrome DevTools Protocol session for the page and browser respectively.

    CDPSession cdpSession = page.context().newCDPSession(page);
    cdpSession.send("Runtime.enable");
    
    JsonObject params = new JsonObject();
    params.addProperty("expression", "window.foo = 'bar'");
    cdpSession.send("Runtime.evaluate", params);
    
    Object foo = page.evaluate("window['foo']");
    assertEquals("bar", foo);

📚 Debian 12 Bookworm Support

Playwright now supports Debian 12 Bookworm on both x86_64 and arm64 for Chromium, Firefox and WebKit. Let us know if you encounter any issues!

Linux support looks like this:

Ubuntu 20.04 Ubuntu 22.04 Debian 11 Debian 12
Chromium
WebKit
Firefox

Browser Versions

  • Chromium 116.0.5845.82
  • Mozilla Firefox 115.0
  • WebKit 17.0

This version was also tested against the following stable channels:

  • Google Chrome 115
  • Microsoft Edge 115
2023-07-15 05:50:24
playwright-java

v1.36.0

Highlights

🏝️ Summer maintenance release.

Browser Versions

  • Chromium 115.0.5790.75
  • Mozilla Firefox 115.0
  • WebKit 17.0

This version was also tested against the following stable channels:

  • Google Chrome 114
  • Microsoft Edge 114