The Clock class allows you to control time in your tests by manipulating browser timers. This is useful for testing time-dependent behavior without actually waiting.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/microsoft/playwright/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Access the clock through the browser context:Methods
install
Installs fake timers and controls time.Time to initialize the clock. Can be:
number: Unix timestamp in millisecondsstring: Date stringDate: Date object
Promise<void>
fastForward
Advances the clock by the specified amount of time.Amount of time to advance. Can be:
number: Time in millisecondsstring: Duration string (e.g., ‘01:00:00’ for 1 hour)
Promise<void>
pauseAt
Pauses time at the specified moment.Time to pause at. Can be:
number: Unix timestamp in millisecondsstring: Date stringDate: Date object
Promise<void>
resume
Resumes normal time flow after it was paused.Promise<void>
runFor
Advances the clock by running all pending timers for the specified duration.Amount of time to run. Can be:
number: Time in millisecondsstring: Duration string (e.g., ‘00:05:00’ for 5 minutes)
Promise<void>
setFixedTime
Sets the clock to a fixed time. All subsequent time queries return this time.Time to fix the clock at. Can be:
number: Unix timestamp in millisecondsstring: Date stringDate: Date object
Promise<void>
setSystemTime
Sets the current system time without affecting timers.Time to set. Can be:
number: Unix timestamp in millisecondsstring: Date stringDate: Date object
Promise<void>
