3.5 Clock
Clock keywords allow accurate simulation of time‑dependent behavior, for example when a user closes a laptop lid but does not log out. The keywords are based on the Playwright Clock API.
There are ways to adjust the time, like Set Time or Advance Clock. Many keywords support a mode that defines how the clock is advanced:
- Underlying timers are fired, meaning the clock is fast‑forwarded to the time.
- Timers are not fired, meaning the clock jumps to the time.
The former simulates time passing (just faster). The latter is more like closing the laptop lid, where the application does not run.
Exercise
Let’s look at a basic example of clock keywords. There is a clock.html page which allows you
to test different
clock
keywords. To use the page your test should do setup like this:
*** Settings ***
Library Browser
Library DateTime
Test Setup Clock Setup
*** Test Cases ***
Set Time Continues To Run Clock
Log Your test here
*** Keywords ***
Clock Setup
VAR ${file} file://${CURDIR}/clock.html
New Browser chromium False
New Page ${file}
Set clock
Write a test that fast‑forwards time 60 minutes into the future. The clock should remain running after time is adjusted. Write an assertion that verifies that time is correctly set.
Pause, advance, and resume clock
Write a test that pauses time 90 minutes in the future and verifies that time is set. Then advance time 30 minutes into the future and verify that time is set. Lastly, resume the clock and observe that time is passing.
Solution
Solution can be found in the clock.robot file.