mirror of
https://github.com/microsoft/playwright-java.git
synced 2026-02-12 08:24:27 +00:00
fix: serialize LocalDateTime parameters as Date (#1048)
This commit is contained in:
parent
4a0ff6ef5c
commit
cf73a8d525
@ -33,6 +33,8 @@ import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Path;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@ -150,6 +152,8 @@ class Serialization {
|
||||
result.s = (String) value;
|
||||
} else if (value instanceof Date) {
|
||||
result.d = ((Date)value).toInstant().toString();
|
||||
} else if (value instanceof LocalDateTime) {
|
||||
result.d = ((LocalDateTime)value).atZone(ZoneId.systemDefault()).toInstant().toString();
|
||||
} else if (value instanceof URL) {
|
||||
result.u = ((URL)value).toString();
|
||||
} else if (value instanceof Pattern) {
|
||||
|
||||
@ -19,12 +19,12 @@ package com.microsoft.playwright;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.DisabledIf;
|
||||
|
||||
import java.time.*;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.Date;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
import static com.microsoft.playwright.Utils.mapOf;
|
||||
import static java.util.Arrays.asList;
|
||||
@ -629,4 +629,13 @@ public class TestPageEvaluate extends TestBase {
|
||||
assertEquals(1, map.size());
|
||||
assertTrue(map == map.get("b"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldAcceptParameter() {
|
||||
Instant instant = Instant.now();
|
||||
LocalDateTime localDateTime = instant.atZone(ZoneId.systemDefault()).toLocalDateTime();
|
||||
Object object = page.evaluate("p => p", localDateTime);
|
||||
assertTrue(object instanceof Date);
|
||||
assertEquals(Date.from(instant), object);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user