arrow-left Back to topicQuizClockCheck yourself1.You need to test that a countdown timer shows '0 seconds' exactly at the deadline. Which approach is correct?Use await page.waitForTimeout(deadline - Date.now()) to wait for the real deadlineInstall the clock, then call page.clock.pauseAt(deadlineDate) to jump to that momentMock Date.now() with page.evaluate() to return the deadline timestampUse page.clock.fastForward() to skip time from the test start to the deadline2.Which browser APIs does page.clock control when installed?Only Date and Date.now()Date, Date.now(), setTimeout, setInterval, and requestAnimationFramesetTimeout and setInterval only — Date is not affectedOnly network-related timing APIs like fetch and XMLHttpRequest3.Your app shows 'Created 2 days ago' for orders. The test passes today but will fail tomorrow because the date changes. What is the correct fix?Use a regex assertion like /\d+ days? ago/ to avoid hardcoding the day countCall await page.clock.setFixedTime(new Date('2026-05-14T12:00:00')) before loading the page to freeze Date.now()Run the test at a fixed time of day using a cron jobSet the order creation date to always be 2 days before today in the test database4.What is the difference between page.clock.fastForward() and page.clock.runFor()?fastForward() works in seconds; runFor() works in millisecondsfastForward() jumps to the end of the time window, firing all timers; runFor() steps through time incrementally, letting you observe intermediate statesrunFor() fires real-time timers; fastForward() fires fake timersThey are identical — both advance the clock by the given number of milliseconds5.You need to test a debounced search that fires an API request 500ms after the user stops typing. Which clock approach is correct?await page.waitForTimeout(500) — wait for the real debounce to elapseInstall the clock, fill the search input, then call await page.clock.fastForward(500) to trigger the debounceUse page.clock.setFixedTime() to set the time 500ms ahead before filling the inputDebounced functions can't be tested with Playwright's clock API6.You must call page.clock.install() before navigating to the page. Why does the order matter?install() can only be called on a blank about:blank pageIf the page loads before the clock is installed, timers started during page initialization will fire with the real clock and the fake clock won't control themNavigating first causes install() to throw a 'clock already running' errorThe order doesn't matter — install() replaces the clock retroactively7.What does page.clock.install({ time: new Date('2026-05-14T08:00:00') }) do compared to page.clock.setFixedTime()?They are equivalent — both freeze the clock at the given time permanentlyinstall() with a time sets the starting point and enables timer control (fastForward, runFor, pauseAt); setFixedTime() only freezes Date.now() without enabling timer manipulationinstall() affects only setTimeout; setFixedTime() affects only Date.now()setFixedTime() requires calling install() first before it has any effect8.You're testing a progress bar that updates every second via setInterval. You want to verify the bar is at 50% after 5 seconds. Which call correctly advances the clock by 5 seconds?await page.clock.fastForward('5:00') — the '5:00' string means 5 minutesawait page.clock.runFor(5000) — advances 5000 milliseconds, firing each setInterval tick in orderawait page.clock.tick(5) — the argument is in secondsawait page.clock.pauseAt(startTime + 5000) — pauseAt accepts a millisecond offsetSubmit answersarrow-left PreviousSnapshot testingExtensibilityNext arrow-right