class Playwright::Clock
in all the pages and iframes is controlled by the same clock.
Note that clock is installed for the entire ‘BrowserContext`, so the time
Accurately simulating time-dependent behavior is essential for verifying the correctness of applications. Learn more about [clock emulation](../clock.md).
def fast_forward(ticks)
page.clock.fast_forward("30:00")
page.clock.fast_forward(1000)
```python sync
**Usage**
reopening it later, after given time.
Advance the clock by jumping forward in time. Only fires due timers at most once. This is equivalent to user closing the laptop lid for a while and
def fast_forward(ticks) wrap_impl(@impl.fast_forward(unwrap_impl(ticks))) end
def install(time: nil)
- `performance`
- `cancelIdleCallback`
- `requestIdleCallback`
- `cancelAnimationFrame`
- `requestAnimationFrame`
- `clearInterval`
- `setInterval`
- `clearTimeout`
- `setTimeout`
- `Date`
Install fake implementations for the following time-related functions:
def install(time: nil) wrap_impl(@impl.install(time: unwrap_impl(time))) end
def pause_at(time)
page.clock.pause_at(datetime.datetime(2024, 12, 10, 10, 0, 0))
page.goto("http://localhost:3333")
page.clock.install(time=datetime.datetime(2024, 12, 10, 8, 0, 0))
# naturally. `Date.now` will progress as the timers fire.
# Initialize clock with some time before the test time and let the page load
```python sync
For best results, install the clock before navigating the page and set it to a time slightly before the intended test time. This ensures that all timers run normally during page loading, preventing the page from getting stuck. Once the page has fully loaded, you can safely use [`method: Clock.pauseAt`] to pause the clock.
```
page.clock.pause_at("2020-02-02")
page.clock.pause_at(datetime.datetime(2020, 2, 2))
```python sync
**Usage**
pausing.
This is equivalent to user closing the laptop lid for a while and reopening it at the specified time and
Only fires due timers at most once.
are fired unless [`method: Clock.runFor`], [`method: Clock.fastForward`], [`method: Clock.pauseAt`] or [`method: Clock.resume`] is called.
Advance the clock by jumping forward in time and pause the time. Once this method is called, no timers
def pause_at(time) wrap_impl(@impl.pause_at(unwrap_impl(time))) end
def resume
def resume wrap_impl(@impl.resume) end
def run_for(ticks)
page.clock.run_for("30:00")
page.clock.run_for(1000);
```python sync
**Usage**
Advance the clock, firing all the time-related callbacks.
def run_for(ticks) wrap_impl(@impl.run_for(unwrap_impl(ticks))) end
def set_fixed_time(time)
page.clock.set_fixed_time("2020-02-02")
page.clock.set_fixed_time(datetime.datetime(2020, 2, 2))
page.clock.set_fixed_time(datetime.datetime.now())
```python sync
**Usage**
Use this method for simple scenarios where you only need to test with a predefined time. For more advanced scenarios, use [`method: Clock.install`] instead. Read docs on [clock emulation](../clock.md) to learn more.
keeps all the timers running.
Makes `Date.now` and `new Date()` return fixed fake time at all times,
def set_fixed_time(time) wrap_impl(@impl.set_fixed_time(unwrap_impl(time))) end
def set_system_time(time)
page.clock.set_system_time("2020-02-02")
page.clock.set_system_time(datetime.datetime(2020, 2, 2))
page.clock.set_system_time(datetime.datetime.now())
```python sync
**Usage**
Sets system time, but does not trigger any timers. Use this to test how the web page reacts to a time shift, for example switching from summer to winter time, or changing time zones.
def set_system_time(time) wrap_impl(@impl.set_system_time(unwrap_impl(time))) end