Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ Playwright is a Java library to automate [Chromium](https://www.chromium.org/Hom

| | Linux | macOS | Windows |
| :--- | :---: | :---: | :---: |
| Chromium <!-- GEN:chromium-version -->159.0.8154.13<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| Chromium <!-- GEN:chromium-version -->159.0.8154.33<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| WebKit <!-- GEN:webkit-version -->27.2<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| Firefox <!-- GEN:firefox-version -->159.0<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| Firefox <!-- GEN:firefox-version -->160.0<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |

## Documentation

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ private BrowserImpl browserFromConnectResult(BrowserTypeConnectOverCDPResult res
BrowserImpl browser = result.browser;
browser.connectToBrowserType(this, new LaunchOptions(), null);
if (result.defaultContext != null) {
instrumentation.runAfterCreateBrowserContext(result.defaultContext);
BrowserContextImpl context = result.defaultContext;
playwright.selectors.registerOnContext(context);
instrumentation.runAfterCreateBrowserContext(context);
}
return browser;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ private void registerImpl(String name, Object script, RegisterOptions options) {
selectorEngines.add(engine);
}

void registerOnContext(BrowserContextImpl context) {
for (SelectorEngine selectorEngine : selectorEngines) {
BrowserContextRegisterSelectorEngineParams params = new BrowserContextRegisterSelectorEngineParams();
params.selectorEngine = selectorEngine;
context.channel.registerSelectorEngine(params, NO_TIMEOUT);
}
if (testIdAttributeName != null) {
BrowserContextSetTestIdAttributeNameParams params = new BrowserContextSetTestIdAttributeNameParams();
params.testIdAttributeName = testIdAttributeName;
context.channel.setTestIdAttributeName(params, NO_TIMEOUT);
}
}

@Override
public void setTestIdAttribute(String attributeName) {
if (attributeName == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.microsoft.playwright.Browser;
import com.microsoft.playwright.BrowserContext;
import com.microsoft.playwright.BrowserType;
import com.microsoft.playwright.FileChooser;
import com.microsoft.playwright.Frame;
import com.microsoft.playwright.Locator;
Expand All @@ -30,14 +31,18 @@
import com.microsoft.playwright.fixtures.DisabledOnBrowser;
import com.microsoft.playwright.fixtures.EnabledOnBrowser;
import com.microsoft.playwright.fixtures.Env;
import com.microsoft.playwright.fixtures.Fixture;
import com.microsoft.playwright.fixtures.HttpsTestServer;
import com.microsoft.playwright.fixtures.PlaywrightTest;
import com.microsoft.playwright.fixtures.Scope;
import com.microsoft.playwright.fixtures.TestServer;
import com.microsoft.playwright.options.BoundingBox;
import org.junit.jupiter.api.DisplayName;

import java.nio.file.Path;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.regex.Pattern;

Expand All @@ -51,6 +56,20 @@

/** Port of tests/library/capabilities.spec.ts. */
public class TestCapabilities {
@Fixture(scope = Scope.WORKER)
static BrowserType.LaunchOptions launchOptions(BrowserType.LaunchOptions launchOptions, BrowserName browserName) {
if (browserName == BrowserName.FIREFOX) {
Map<String, Object> firefoxUserPrefs = new HashMap<>();
if (launchOptions.firefoxUserPrefs != null) {
firefoxUserPrefs.putAll(launchOptions.firefoxUserPrefs);
}
// Test DOM fullscreen without requiring a window manager under Xvfb.
firefoxUserPrefs.put("full-screen-api.ignore-widgets", true);
return com.microsoft.playwright.impl.Utils.clone(launchOptions).setFirefoxUserPrefs(firefoxUserPrefs);
}
return launchOptions;
}

@PlaywrightTest
@DisplayName("CA-001 SharedArrayBuffer should work @smoke")
void sharedArrayBufferShouldWork(ContextFactory contextFactory, HttpsTestServer httpsServer) {
Expand Down Expand Up @@ -316,8 +335,7 @@ void windowGestureEventInWebKit(Page page, TestServer server, BrowserName browse

@PlaywrightTest
@DisplayName("CA-020 requestFullscreen")
@DisabledOnBrowser(value = BrowserName.FIREFOX, headed = true, reason = "fixme: Error: Request for fullscreen was denied because requesting element is not in the currently focused tab")
void requestFullscreen(Page page, TestServer server) {
void requestFullscreen(Page page, TestServer server, BrowserName browserName) {
page.navigate(server.EMPTY_PAGE);
page.evaluate("() => {\n" +
" const result = new Promise(resolve => document.addEventListener('fullscreenchange', resolve));\n" +
Expand All @@ -332,6 +350,8 @@ void requestFullscreen(Page page, TestServer server) {
"}");
assertEquals(false, page.evaluate("() => !!document.fullscreenElement"));

assumeFalse(browserName == BrowserName.WEBKIT && !Env.isLinux,
"fixme: requestFullscreen() in a popup rejects with InvalidStateError on Windows and hangs the context teardown on macOS");
Page popup = page.waitForPopup(() -> page.evaluate("url => window.open(url, 'popup', 'popup')", server.EMPTY_PAGE));
popup.waitForLoadState();
popup.evaluate("() => {\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,46 @@ void shouldReturnValidBrowserFromContextBrowser(BrowserType browserType) {
}
}

@PlaywrightTest
@DisplayName("CD-055 should work with registered selector engines")
void shouldWorkWithRegisteredSelectorEngines(Playwright playwright, BrowserType browserType) {
int port = findFreePort();
Browser browserServer = browserType.launch(remoteDebuggingPort(port));
try {
// Java: invoke the factory, since register accepts script source rather than a JavaScript function.
playwright.selectors().register("cdpTag", "(() => ({\n" +
" query: (root, selector) => root.querySelector(selector),\n" +
" queryAll: (root, selector) => Array.from(root.querySelectorAll(selector)),\n" +
"}))()");
Browser cdpBrowser = browserType.connectOverCDP("http://127.0.0.1:" + port + "/");
Page page = cdpBrowser.contexts().get(0).newPage();
page.setContent("<div>hello</div>");
assertEquals("hello", page.locator("cdpTag=div").textContent());
cdpBrowser.close();
} finally {
browserServer.close();
}
}

@PlaywrightTest
@DisplayName("CD-056 should respect the test id attribute in strict mode errors")
void shouldRespectTheTestIdAttributeInStrictModeErrors(Playwright playwright, BrowserType browserType) {
int port = findFreePort();
Browser browserServer = browserType.launch(remoteDebuggingPort(port));
try {
playwright.selectors().setTestIdAttribute("data-foo");
Browser cdpBrowser = browserType.connectOverCDP("http://127.0.0.1:" + port + "/");
Page page = cdpBrowser.contexts().get(0).newPage();
page.setContent("<button data-foo=\"a\">x</button><button data-foo=\"b\">x</button>");
PlaywrightException error = assertThrows(PlaywrightException.class, () -> page.locator("button").click());
assertTrue(error.getMessage().contains("aka getByTestId(\"a\")"));
cdpBrowser.close();
} finally {
playwright.selectors().setTestIdAttribute("data-testid");
browserServer.close();
}
}

@PlaywrightTest
@DisplayName("CD-020 should report an expected error when the endpointURL returns a non-expected status code")
void shouldReportAnExpectedErrorWhenTheEndpointURLReturnsANonExpectedStatusCode(BrowserType browserType, TestServer server) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,7 @@ void shouldRemoveElementsBasedOnAttr(Page page, TestServer server, TestInfo test
}

@Nested
@DisabledOnBrowser(value = BrowserName.FIREFOX, headed = true, reason = "Firefox headed produces a different image: https://github.com/microsoft/playwright-browsers/issues/2714")
class PageScreenshotAnimations {
@PlaywrightTest
@DisplayName("SS-098 should preserve scroll animation progress during screenshots")
Expand Down
2 changes: 1 addition & 1 deletion playwright/src/test/upstream_base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
# git log <commit>..main --oneline -- tests/page tests/library tests/registry.md
# git diff <commit>..main -- tests/page tests/library tests/registry.md
# and move this line forward together with the registry copy and the ports.
b0e0b7b555e637cc8c0ce94dd98c3be153861333 2026-11-24 fix(test): watch external dependencies of test directories (#44317)
a804c193562095b0da20e5d4679fa87e4c8e5563 2026-11-27 docs(python): fix async/sync mistakes in Python code snippets (#44410)
2 changes: 2 additions & 0 deletions playwright/src/test/upstream_registry.md
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,8 @@ subsystem, add a row to the Subsystems table. Then update this file:
| `CD-052` | `library/chromium/session.spec.ts` | should work with newBrowserCDPSession |
| `CD-053` | `library/chromium/connect-over-cdp.spec.ts` | should connect when another client inspects a terminated shared worker |
| `CD-054` | `library/chromium/connect-over-cdp.spec.ts` | should not wait for a busy page longer than maxPageAttachTime |
| `CD-055` | `library/chromium/connect-over-cdp.spec.ts` | should work with registered selector engines |
| `CD-056` | `library/chromium/connect-over-cdp.spec.ts` | should respect the test id attribute in strict mode errors |

### CF — Code frame

Expand Down
2 changes: 1 addition & 1 deletion scripts/DRIVER_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
b0e0b7b555e637cc8c0ce94dd98c3be153861333
a804c193562095b0da20e5d4679fa87e4c8e5563
Loading