Created
June 28, 2024 16:21
-
-
Save up1/37e5cb5a46ece32150616a636517f386 to your computer and use it in GitHub Desktop.
Playwright + Clock API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Initialize clock and let the page load naturally. | |
await page.clock.install({ time: new Date('2024-02-02T08:00:00') }); | |
await page.goto('http://localhost:3333'); | |
// Pretend that the user closed the laptop lid and opened it again at 10am, | |
// Pause the time once reached that point. | |
await page.clock.pauseAt(new Date('2024-02-02T10:00:00')); | |
// Assert the page state. | |
await expect(page.getByTestId('current-time')).toHaveText('2/2/2024, 10:00:00 AM'); | |
// Close the laptop lid again and open it at 10:30am. | |
await page.clock.fastForward('30:00'); | |
await expect(page.getByTestId('current-time')).toHaveText('2/2/2024, 10:30:00 AM'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment