From d9a07c8013333b8e7afd48830b29880a0e9084d3 Mon Sep 17 00:00:00 2001 From: Develop-KIM Date: Fri, 10 Jul 2026 01:31:20 +0900 Subject: [PATCH 1/2] fix(screencast): register AnnotatePosition enum serializer AnnotatePosition had no Gson serializer registered, so Screencast.showActions() sent the raw enum constant (e.g. TOP_RIGHT) to the driver, which rejected it with "position: expected one of (top-left|top|top-right|...)". Register it with ToLowerCaseAndDashSerializer so values serialize as top-right, matching the other dashed enums. Fixes: https://github.com/microsoft/playwright-java/issues/1912 --- .../playwright/impl/Serialization.java | 1 + .../playwright/impl/TestSerialization.java | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 playwright/src/test/java/com/microsoft/playwright/impl/TestSerialization.java diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java b/playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java index 34899dfbb..4aa6e793f 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java @@ -45,6 +45,7 @@ class Serialization { .registerTypeAdapter(Date.class, new DateSerializer()) .registerTypeAdapter(LocalDateTime.class, new LocalDateTimeSerializer()) .registerTypeAdapter(SameSiteAttribute.class, new SameSiteAdapter().nullSafe()) + .registerTypeAdapter(AnnotatePosition.class, new ToLowerCaseAndDashSerializer()) .registerTypeAdapter(BrowserChannel.class, new ToLowerCaseAndDashSerializer()) .registerTypeAdapter(ColorScheme.class, new ToLowerCaseAndDashSerializer()) .registerTypeAdapter(Contrast.class, new ToLowerCaseAndDashSerializer()) diff --git a/playwright/src/test/java/com/microsoft/playwright/impl/TestSerialization.java b/playwright/src/test/java/com/microsoft/playwright/impl/TestSerialization.java new file mode 100644 index 000000000..b8adef4dd --- /dev/null +++ b/playwright/src/test/java/com/microsoft/playwright/impl/TestSerialization.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) Microsoft Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.microsoft.playwright.impl; + +import com.microsoft.playwright.options.AnnotatePosition; +import org.junit.jupiter.api.Test; + +import static com.microsoft.playwright.impl.Serialization.gson; +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class TestSerialization { + @Test + void annotatePositionSerializesToLowerCaseAndDash() { + assertEquals("top-left", gson().toJsonTree(AnnotatePosition.TOP_LEFT).getAsString()); + assertEquals("top", gson().toJsonTree(AnnotatePosition.TOP).getAsString()); + assertEquals("top-right", gson().toJsonTree(AnnotatePosition.TOP_RIGHT).getAsString()); + assertEquals("bottom-left", gson().toJsonTree(AnnotatePosition.BOTTOM_LEFT).getAsString()); + assertEquals("bottom", gson().toJsonTree(AnnotatePosition.BOTTOM).getAsString()); + assertEquals("bottom-right", gson().toJsonTree(AnnotatePosition.BOTTOM_RIGHT).getAsString()); + } +} From 61a0857b22b43d260642071fca82c4a154aeba8c Mon Sep 17 00:00:00 2001 From: Develop-KIM Date: Tue, 4 Aug 2026 11:36:00 +0900 Subject: [PATCH 2/2] test: verify AnnotatePosition through the Screencast API --- .../microsoft/playwright/TestScreencast.java | 18 ++++++++++ .../playwright/impl/TestSerialization.java | 35 ------------------- 2 files changed, 18 insertions(+), 35 deletions(-) delete mode 100644 playwright/src/test/java/com/microsoft/playwright/impl/TestSerialization.java diff --git a/playwright/src/test/java/com/microsoft/playwright/TestScreencast.java b/playwright/src/test/java/com/microsoft/playwright/TestScreencast.java index 2d81b3d47..f36d1b977 100644 --- a/playwright/src/test/java/com/microsoft/playwright/TestScreencast.java +++ b/playwright/src/test/java/com/microsoft/playwright/TestScreencast.java @@ -16,6 +16,7 @@ package com.microsoft.playwright; +import com.microsoft.playwright.options.AnnotatePosition; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; @@ -247,4 +248,21 @@ void screencastShowAndHideActions() throws Exception { context.close(); } } + + @Test + void screencastShowActionsShouldAcceptEveryPosition() throws Exception { + BrowserContext context = browser.newContext(); + Page page = context.newPage(); + try { + page.navigate(server.EMPTY_PAGE); + for (AnnotatePosition position : AnnotatePosition.values()) { + AutoCloseable disposable = page.screencast().showActions( + new Screencast.ShowActionsOptions().setPosition(position)); + assertNotNull(disposable); + disposable.close(); + } + } finally { + context.close(); + } + } } diff --git a/playwright/src/test/java/com/microsoft/playwright/impl/TestSerialization.java b/playwright/src/test/java/com/microsoft/playwright/impl/TestSerialization.java deleted file mode 100644 index b8adef4dd..000000000 --- a/playwright/src/test/java/com/microsoft/playwright/impl/TestSerialization.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) Microsoft Corporation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.microsoft.playwright.impl; - -import com.microsoft.playwright.options.AnnotatePosition; -import org.junit.jupiter.api.Test; - -import static com.microsoft.playwright.impl.Serialization.gson; -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class TestSerialization { - @Test - void annotatePositionSerializesToLowerCaseAndDash() { - assertEquals("top-left", gson().toJsonTree(AnnotatePosition.TOP_LEFT).getAsString()); - assertEquals("top", gson().toJsonTree(AnnotatePosition.TOP).getAsString()); - assertEquals("top-right", gson().toJsonTree(AnnotatePosition.TOP_RIGHT).getAsString()); - assertEquals("bottom-left", gson().toJsonTree(AnnotatePosition.BOTTOM_LEFT).getAsString()); - assertEquals("bottom", gson().toJsonTree(AnnotatePosition.BOTTOM).getAsString()); - assertEquals("bottom-right", gson().toJsonTree(AnnotatePosition.BOTTOM_RIGHT).getAsString()); - } -}