Developer bit
Playwright v1.45 makes you a Time Wizard
The latest release of Playwright, version 1.45, introduces a new feature called Clock . This feature allows you to manipulate the time in your tests, making...
The latest release of Playwright, version 1.45, introduces a new feature called Clock. This feature allows you to manipulate the time in your tests, making it easier to test time-sensitive scenarios.
import { , } from ;test,async({page})=>{// Initialize clock and let the page load naturally.await..install{:newDate};await.goto;awaitexpect.getByTestId.toHaveText;// Set a fixed time (Date.now and new Date() return fixed fake time at all times)await..setSystemTime;awaitexpect.getByTestId.toHaveText;// Pretend that the user closed the laptop lid and opened it again at 10am,// Pause the time once reached that point.await..pauseAtnewDate;awaitexpect.getByTestId.toHaveText;// Close the laptop lid again and open it at 10:30am.await..fastForward;awaitexpect.getByTestId.toHaveText;// Resume the time to normal flowawait..resume;// Fake Date value while keeping the timers goingawait..setFixedTime;awaitexpect.getByTestId.toHaveText;};
Additional Resources
Feel free to update this developer bit on GitHub, thanks in advance!