Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
.registerTypeAdapter(Date.class, new DateSerializer())
.registerTypeAdapter(LocalDateTime.class, new LocalDateTimeSerializer())
.registerTypeAdapter(SameSiteAttribute.class, new SameSiteAdapter().nullSafe())
.registerTypeAdapter(AnnotatePosition.class, new ToLowerCaseAndDashSerializer<AnnotatePosition>())
.registerTypeAdapter(BrowserChannel.class, new ToLowerCaseAndDashSerializer<BrowserChannel>())
.registerTypeAdapter(ColorScheme.class, new ToLowerCaseAndDashSerializer<ColorScheme>())
.registerTypeAdapter(Contrast.class, new ToLowerCaseAndDashSerializer<Contrast>())
Expand Down Expand Up @@ -82,7 +83,7 @@
.registerTypeAdapter(OffsetDateTime.class, new OffsetDateTimeSerializer())
.serializeNulls().create();

static SerializedError serializeError(Throwable e) {

Check failure on line 86 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / dev (ubuntu-latest, chromium)

cannot find symbol

Check failure on line 86 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / stable (ubuntu-latest, chrome)

cannot find symbol

Check failure on line 86 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / dev (macos-15-xlarge, webkit)

cannot find symbol

Check failure on line 86 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / dev (macos-latest, chromium)

cannot find symbol

Check failure on line 86 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / dev (ubuntu-latest, webkit)

cannot find symbol

Check failure on line 86 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / dev (macos-latest, firefox)

cannot find symbol

Check failure on line 86 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / dev (ubuntu-latest, firefox)

cannot find symbol

Check failure on line 86 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / stable (macos-latest, chrome)

cannot find symbol

Check failure on line 86 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / stable (macos-latest, msedge)

cannot find symbol
SerializedError result = new SerializedError();
result.error = new SerializedError.Error();
result.error.message = e.getMessage();
Expand Down Expand Up @@ -116,13 +117,13 @@
private final Map<HashableValue, Integer> valueToId = new HashMap<>();
private int lastId = 0;
private final List<JSHandleImpl> handles = new ArrayList<>();
private final SerializedValue serializedValue;

Check failure on line 120 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / dev (ubuntu-latest, chromium)

cannot find symbol

Check failure on line 120 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / stable (ubuntu-latest, chrome)

cannot find symbol

Check failure on line 120 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / dev (macos-15-xlarge, webkit)

cannot find symbol

Check failure on line 120 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / dev (macos-latest, chromium)

cannot find symbol

Check failure on line 120 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / dev (ubuntu-latest, webkit)

cannot find symbol

Check failure on line 120 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / dev (macos-latest, firefox)

cannot find symbol

Check failure on line 120 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / dev (ubuntu-latest, firefox)

cannot find symbol

Check failure on line 120 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / stable (macos-latest, chrome)

cannot find symbol

Check failure on line 120 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / stable (macos-latest, msedge)

cannot find symbol

ValueSerializer(Object value) {
serializedValue = serializeValue(value);
}

SerializedArgument toSerializedArgument() {

Check failure on line 126 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / dev (ubuntu-latest, chromium)

cannot find symbol

Check failure on line 126 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / stable (ubuntu-latest, chrome)

cannot find symbol

Check failure on line 126 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / dev (macos-15-xlarge, webkit)

cannot find symbol

Check failure on line 126 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / dev (macos-latest, chromium)

cannot find symbol

Check failure on line 126 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / dev (ubuntu-latest, webkit)

cannot find symbol

Check failure on line 126 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / dev (macos-latest, firefox)

cannot find symbol

Check failure on line 126 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / dev (ubuntu-latest, firefox)

cannot find symbol

Check failure on line 126 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / stable (macos-latest, chrome)

cannot find symbol

Check failure on line 126 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / stable (macos-latest, msedge)

cannot find symbol
SerializedArgument result = new SerializedArgument();
result.value = serializedValue;
result.handles = new Channel[handles.size()];
Expand All @@ -135,7 +136,7 @@
return result;
}

private SerializedValue serializeValue(Object value) {

Check failure on line 139 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / dev (ubuntu-latest, chromium)

cannot find symbol

Check failure on line 139 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / stable (ubuntu-latest, chrome)

cannot find symbol

Check failure on line 139 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / dev (macos-15-xlarge, webkit)

cannot find symbol

Check failure on line 139 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / dev (macos-latest, chromium)

cannot find symbol

Check failure on line 139 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / dev (ubuntu-latest, webkit)

cannot find symbol

Check failure on line 139 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / dev (macos-latest, firefox)

cannot find symbol

Check failure on line 139 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / dev (ubuntu-latest, firefox)

cannot find symbol

Check failure on line 139 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / stable (macos-latest, chrome)

cannot find symbol

Check failure on line 139 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / stable (macos-latest, msedge)

cannot find symbol
SerializedValue result = new SerializedValue();
if (value instanceof JSHandleImpl) {
result.h = handles.size();
Expand Down Expand Up @@ -223,16 +224,16 @@
}
}

static SerializedArgument serializeArgument(Object arg) {

Check failure on line 227 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / dev (ubuntu-latest, chromium)

cannot find symbol

Check failure on line 227 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / stable (ubuntu-latest, chrome)

cannot find symbol

Check failure on line 227 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / dev (macos-15-xlarge, webkit)

cannot find symbol

Check failure on line 227 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / dev (macos-latest, chromium)

cannot find symbol

Check failure on line 227 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / dev (ubuntu-latest, webkit)

cannot find symbol

Check failure on line 227 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / dev (macos-latest, firefox)

cannot find symbol

Check failure on line 227 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / dev (ubuntu-latest, firefox)

cannot find symbol

Check failure on line 227 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / stable (macos-latest, chrome)

cannot find symbol

Check failure on line 227 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / stable (macos-latest, msedge)

cannot find symbol
return new ValueSerializer(arg).toSerializedArgument();
}

static <T> T deserialize(SerializedValue value) {

Check failure on line 231 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / dev (ubuntu-latest, chromium)

cannot find symbol

Check failure on line 231 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / stable (ubuntu-latest, chrome)

cannot find symbol

Check failure on line 231 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / dev (macos-15-xlarge, webkit)

cannot find symbol

Check failure on line 231 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / dev (macos-latest, chromium)

cannot find symbol

Check failure on line 231 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / dev (ubuntu-latest, webkit)

cannot find symbol

Check failure on line 231 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / dev (macos-latest, firefox)

cannot find symbol

Check failure on line 231 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / dev (ubuntu-latest, firefox)

cannot find symbol

Check failure on line 231 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / stable (macos-latest, chrome)

cannot find symbol

Check failure on line 231 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / stable (macos-latest, msedge)

cannot find symbol
return deserialize(value, new HashMap<>());
}

@SuppressWarnings("unchecked")
private static <T> T deserialize(SerializedValue value, Map<Integer, Object> idToValue) {

Check failure on line 236 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / dev (ubuntu-latest, chromium)

cannot find symbol

Check failure on line 236 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / stable (ubuntu-latest, chrome)

cannot find symbol

Check failure on line 236 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / dev (macos-15-xlarge, webkit)

cannot find symbol

Check failure on line 236 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / dev (macos-latest, chromium)

cannot find symbol

Check failure on line 236 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / dev (ubuntu-latest, webkit)

cannot find symbol

Check failure on line 236 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / dev (macos-latest, firefox)

cannot find symbol

Check failure on line 236 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / dev (ubuntu-latest, firefox)

cannot find symbol

Check failure on line 236 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / stable (macos-latest, chrome)

cannot find symbol

Check failure on line 236 in playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java

View workflow job for this annotation

GitHub Actions / stable (macos-latest, msedge)

cannot find symbol
if (value.ref != null) {
return (T) idToValue.get(value.ref);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's turn it into and e2e test and check that actual playwright api call doesn't throw page.screencast().showActions(new Screencast.ShowActionsOptions().setPosition(AnnotatePosition.TOP_RIGHT))

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());
}
}
Loading