docs(java): correctly parse time (#31420)
This commit is contained in:
parent
74976b1da8
commit
865f0d8221
|
|
@ -136,7 +136,8 @@ page.clock.pause_at("2020-02-02")
|
||||||
```
|
```
|
||||||
|
|
||||||
```java
|
```java
|
||||||
page.clock().pauseAt(Instant.parse("2020-02-02"));
|
SimpleDateFormat format = new SimpleDateFormat("yyy-MM-dd");
|
||||||
|
page.clock().pauseAt(format.parse("2020-02-02"));
|
||||||
page.clock().pauseAt("2020-02-02");
|
page.clock().pauseAt("2020-02-02");
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -182,8 +183,8 @@ page.clock.set_fixed_time("2020-02-02")
|
||||||
```
|
```
|
||||||
|
|
||||||
```java
|
```java
|
||||||
page.clock().setFixedTime(Instant.now());
|
page.clock().setFixedTime(new Date());
|
||||||
page.clock().setFixedTime(Instant.parse("2020-02-02"));
|
page.clock().setFixedTime(new SimpleDateFormat("yyy-MM-dd").parse("2020-02-02"));
|
||||||
page.clock().setFixedTime("2020-02-02");
|
page.clock().setFixedTime("2020-02-02");
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -225,8 +226,8 @@ page.clock.set_system_time("2020-02-02")
|
||||||
```
|
```
|
||||||
|
|
||||||
```java
|
```java
|
||||||
page.clock().setSystemTime(Instant.now());
|
page.clock().setSystemTime(new Date());
|
||||||
page.clock().setSystemTime(Instant.parse("2020-02-02"));
|
page.clock().setSystemTime(new SimpleDateFormat("yyy-MM-dd").parse("2020-02-02"));
|
||||||
page.clock().setSystemTime("2020-02-02");
|
page.clock().setSystemTime("2020-02-02");
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -118,13 +118,14 @@ expect(page.get_by_test_id("current-time")).to_have_text("2/2/2024, 10:30:00 AM"
|
||||||
```java
|
```java
|
||||||
// Initialize clock with some time before the test time and let the page load
|
// Initialize clock with some time before the test time and let the page load
|
||||||
// naturally. `Date.now` will progress as the timers fire.
|
// naturally. `Date.now` will progress as the timers fire.
|
||||||
page.clock().install(new Clock.InstallOptions().setTime(Instant.parse("2024-02-02T08:00:00")));
|
SimpleDateFormat format = new SimpleDateFormat("yyy-MM-dd'T'HH:mm:ss");
|
||||||
|
page.clock().install(new Clock.InstallOptions().setTime(format.parse("2024-02-02T08:00:00")));
|
||||||
page.navigate("http://localhost:3333");
|
page.navigate("http://localhost:3333");
|
||||||
Locator locator = page.getByTestId("current-time");
|
Locator locator = page.getByTestId("current-time");
|
||||||
|
|
||||||
// Pretend that the user closed the laptop lid and opened it again at 10am.
|
// Pretend that the user closed the laptop lid and opened it again at 10am.
|
||||||
// Pause the time once reached that point.
|
// Pause the time once reached that point.
|
||||||
page.clock().pauseAt(Instant.parse("2024-02-02T10:00:00"));
|
page.clock().pauseAt(format.parse("2024-02-02T10:00:00"));
|
||||||
|
|
||||||
// Assert the page state.
|
// Assert the page state.
|
||||||
assertThat(locator).hasText("2/2/2024, 10:00:00 AM");
|
assertThat(locator).hasText("2/2/2024, 10:00:00 AM");
|
||||||
|
|
@ -315,15 +316,16 @@ expect(locator).to_have_text("2/2/2024, 10:00:02 AM")
|
||||||
```
|
```
|
||||||
|
|
||||||
```java
|
```java
|
||||||
|
SimpleDateFormat format = new SimpleDateFormat("yyy-MM-dd'T'HH:mm:ss");
|
||||||
// Initialize clock with a specific time, let the page load naturally.
|
// Initialize clock with a specific time, let the page load naturally.
|
||||||
page.clock().install(new Clock.InstallOptions()
|
page.clock().install(new Clock.InstallOptions()
|
||||||
.setTime(Instant.parse("2024-02-02T08:00:00")));
|
.setTime(format.parse("2024-02-02T08:00:00")));
|
||||||
page.navigate("http://localhost:3333");
|
page.navigate("http://localhost:3333");
|
||||||
Locator locator = page.getByTestId("current-time");
|
Locator locator = page.getByTestId("current-time");
|
||||||
|
|
||||||
// Pause the time flow, stop the timers, you now have manual control
|
// Pause the time flow, stop the timers, you now have manual control
|
||||||
// over the page time.
|
// over the page time.
|
||||||
page.clock().pauseAt(Instant.parse("2024-02-02T10:00:00"));
|
page.clock().pauseAt(format.parse("2024-02-02T10:00:00"));
|
||||||
assertThat(locator).hasText("2/2/2024, 10:00:00 AM");
|
assertThat(locator).hasText("2/2/2024, 10:00:00 AM");
|
||||||
|
|
||||||
// Tick through time manually, firing all timers in the process.
|
// Tick through time manually, firing all timers in the process.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue