A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://playwright.dev/docs/api/class-clock below:

Clock | Playwright

Clock

Accurately simulating time-dependent behavior is essential for verifying the correctness of applications. Learn more about clock emulation.

Note that clock is installed for the entire BrowserContext, so the time in all the pages and iframes is controlled by the same clock.

Methods fastForwardAdded in: v1.45 clock.fastForward

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 reopening it later, after given time.

Usage

await page.clock.fastForward(1000);
await page.clock.fastForward('30:00');

Arguments

Returns

installAdded in: v1.45 clock.install

Install fake implementations for the following time-related functions:

Fake timers are used to manually control the flow of time in tests. They allow you to advance time, fire timers, and control the behavior of time-dependent functions. See clock.runFor() and clock.fastForward() for more information.

Usage

await clock.install();
await clock.install(options);

Arguments

Returns

pauseAtAdded in: v1.45 clock.pauseAt

Advance the clock by jumping forward in time and pause the time. Once this method is called, no timers are fired unless clock.runFor(), clock.fastForward(), clock.pauseAt() or clock.resume() is called.

Only fires due timers at most once. This is equivalent to user closing the laptop lid for a while and reopening it at the specified time and pausing.

Usage

await page.clock.pauseAt(new Date('2020-02-02'));
await page.clock.pauseAt('2020-02-02');

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 clock.pauseAt() to pause the clock.



await page.clock.install({ time: new Date('2024-12-10T08:00:00') });
await page.goto('http://localhost:3333');
await page.clock.pauseAt(new Date('2024-12-10T10:00:00'));

Arguments

Returns

resumeAdded in: v1.45 clock.resume

Resumes timers. Once this method is called, time resumes flowing, timers are fired as usual.

Usage

Returns

runForAdded in: v1.45 clock.runFor

Advance the clock, firing all the time-related callbacks.

Usage

await page.clock.runFor(1000);
await page.clock.runFor('30:00');

Arguments

Returns

setFixedTimeAdded in: v1.45 clock.setFixedTime

Makes Date.now and new Date() return fixed fake time at all times, keeps all the timers running.

Use this method for simple scenarios where you only need to test with a predefined time. For more advanced scenarios, use clock.install() instead. Read docs on clock emulation to learn more.

Usage

await page.clock.setFixedTime(Date.now());
await page.clock.setFixedTime(new Date('2020-02-02'));
await page.clock.setFixedTime('2020-02-02');

Arguments

Returns

setSystemTimeAdded in: v1.45 clock.setSystemTime

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.

Usage

await page.clock.setSystemTime(Date.now());
await page.clock.setSystemTime(new Date('2020-02-02'));
await page.clock.setSystemTime('2020-02-02');

Arguments

Returns


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4