Controlling time: the clock
Install Playwright's fake clock to freeze the date or skip ahead, so a 9 a.m. reminder or a 30-minute timeout is tested in a blink.
L1–L4 are part of the Pro pass
L0 Explain simply
Analogy: a film remote that can skip a day in a second. You watch a long film. With the remote you can pause on one frame, or jump forward an hour. The story does not need to run in real time for you to see what happens at the end.
Daily List is a to-do list app. It shows a toast, a small pop-up message, at 9 in the morning: "3 tasks due today". It signs a person out after 30 minutes with no activity. Tom, the tester, does not want to wait until 9, or sit for 30 minutes. He wants a remote.
The picture has limits. The remote only changes the clock inside the browser. The server has its own clock. The remote does not touch that clock.
What it is: Playwright is a free library from Microsoft that drives a real browser from code. This topic is one slice of that library: the on page.clock. Tom installs it before he opens the page, with await page.clock.install({ time: new Date('2026-12-01T08:55:00') }). The page then thinks it is five to nine. jumps ahead, with await page.clock.fastForward('10:00'). In this string, 10:00 means ten minutes, not ten hours. The page then thinks it is five past nine, and the toast shows. The nearest neighbour is a real await page.waitForTimeout(600000), which really waits ten minutes. The fake clock does not.
Why it matters: Reminders and sign-out depend on the clock. Without a fake clock, a 30-minute idle test takes 30 minutes, and a 9 a.m. toast can be checked only in the morning. With it, Tom asserts "3 tasks due today" in about a second, and he gets the same result every run. A hold is the control working. The test is not broken because it refused to sit and wait.
(SYNTHETIC / TRAINING ONLY: Daily List and every person named in this lesson are invented.)
PLAIN WORDS · 1 in this section
- playwright
- a free Microsoft tool that drives a browser for tests
PICTURE IT
The picture is the one the lesson above opens with. The table below shows how each part of it matches the software.
THE REAL JOB Skipping ahead in time, or freezing it, inside the browser, so a delay is tested in a blink.
- Install first
- Pause or skip
- Let the timers fire
- Check the screen
HOW THE PICTURE MAPS
| In the picture | In the software |
|---|---|
| The film remote | The fake clock |
| Pausing on one frame | Fixed time |
| Jumping forward an hour | The fast-forward |
| The film in the next room | The server, with its own clock |
WHERE THIS PICTURE STOPS
- The remote changes the picture you watch. It does not change the film in another room.
- A film has one clock. A test can use fixed time and a fast-forward in turn.
- A remote works at once. The clock must be installed before the page loads.
HOOK
Pause or skip, then look.
REMEMBER IT THIS WAY
A sequence: the real steps, in order.
Pause or skip, then look: install the first, set the time, then jump forward and check the toast.
| In the trick | What it stands for |
|---|---|
| pause | fixed time |
| skip | the fast-forward |
| look | check the toast |
The fake clock does not change the server, which keeps its own clock.
TELL A FRIEND
A film remote that pauses on one frame or jumps ahead an hour.
OFTEN MIXED UP WITH Dates, times and time zones. The general lesson explains why dates and time zones cause bugs. This lesson shows how to control time in a .
Sources & standards — 5 sources
- Market practice
Clock (Playwright documentation) ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: Complete extracted primary article; examples inspected, not executed. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.
Primary source opened and operative text inspected on 6 November 2026. Scope: Complete extracted primary article; examples inspected, not executed. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.
- Market practice
Auto-waiting (Playwright documentation) ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: Complete extracted primary article; examples inspected, not executed. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.
Primary source opened and operative text inspected on 6 November 2026. Scope: Complete extracted primary article; examples inspected, not executed. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.
- Market practice
Configuration (use) (Playwright documentation) ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: Complete extracted primary article; examples inspected, not executed. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.
Primary source opened and operative text inspected on 6 November 2026. Scope: Complete extracted primary article; examples inspected, not executed. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.
- Market practice
Hypertext Transfer Protocol (HTTP) request methods (Mozilla developer docs) ↗ — Mozilla (MDN Web Docs) · Background on how a page asks a server for data (search excerpt, page not opened)
Found through a web search; the page was not opened (search excerpt, page not opened). Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.
- Market practice
Clock | Playwright ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: Clock methods and timer behavior. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.
Primary source opened and operative text inspected on 6 November 2026. Scope: Clock methods and timer behavior. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.
PRACTISE AND KEEP
Sources for this topic — 5 sources
- Market practice
Clock (Playwright documentation) ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: Complete extracted primary article; examples inspected, not executed. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.
Primary source opened and operative text inspected on 6 November 2026. Scope: Complete extracted primary article; examples inspected, not executed. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.
- Market practice
Auto-waiting (Playwright documentation) ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: Complete extracted primary article; examples inspected, not executed. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.
Primary source opened and operative text inspected on 6 November 2026. Scope: Complete extracted primary article; examples inspected, not executed. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.
- Market practice
Configuration (use) (Playwright documentation) ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: Complete extracted primary article; examples inspected, not executed. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.
Primary source opened and operative text inspected on 6 November 2026. Scope: Complete extracted primary article; examples inspected, not executed. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.
- Market practice
Hypertext Transfer Protocol (HTTP) request methods (Mozilla developer docs) ↗ — Mozilla (MDN Web Docs) · Background on how a page asks a server for data (search excerpt, page not opened)
Found through a web search; the page was not opened (search excerpt, page not opened). Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.
- Market practice
Clock | Playwright ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: Clock methods and timer behavior. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.
Primary source opened and operative text inspected on 6 November 2026. Scope: Clock methods and timer behavior. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.
Deepest material on this page: L4 — Standards & sources. Where a topic stops short of implementation depth, that is a deliberate coverage decision, not an oversight — see coverage.