Class ControlClock
java.lang.Object
net.serenitybdd.screenplay.playwright.interactions.ControlClock
Control the browser's clock for testing time-dependent features.
This interaction uses Playwright's Clock API to manipulate Date, setTimeout, setInterval, and other time-related functions in the browser.
Sample usage:
// Install fake timers and freeze at a specific time
actor.attemptsTo(ControlClock.freezeAt(LocalDateTime.of(2024, 12, 25, 10, 30)));
// Install fake timers at specific time (allows time to pass)
actor.attemptsTo(ControlClock.installAt(LocalDateTime.of(2024, 1, 1, 0, 0)));
// Advance time by duration
actor.attemptsTo(ControlClock.fastForward(5000)); // 5 seconds
actor.attemptsTo(ControlClock.fastForwardMinutes(30));
actor.attemptsTo(ControlClock.fastForwardHours(2));
// Pause and resume
actor.attemptsTo(ControlClock.pause());
actor.attemptsTo(ControlClock.resume());
// Set system time (without installing fake timers)
actor.attemptsTo(ControlClock.setSystemTimeTo(LocalDateTime.of(2024, 6, 15, 14, 0)));
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic net.serenitybdd.screenplay.PerformablefastForward(long milliseconds) Advance time by the specified number of milliseconds.static net.serenitybdd.screenplay.PerformablefastForwardHours(long hours) Advance time by the specified number of hours.static net.serenitybdd.screenplay.PerformablefastForwardMinutes(long minutes) Advance time by the specified number of minutes.static net.serenitybdd.screenplay.PerformablefastForwardSeconds(long seconds) Advance time by the specified number of seconds.static net.serenitybdd.screenplay.PerformablefreezeAt(long epochMillis) Install fake timers and freeze time at the specified timestamp.static net.serenitybdd.screenplay.PerformablefreezeAt(LocalDateTime dateTime) Install fake timers and freeze time at the specified instant.static net.serenitybdd.screenplay.PerformableInstall fake timers and freeze time at the specified date.static net.serenitybdd.screenplay.PerformableinstallAt(long epochMillis) Install fake timers starting at the specified timestamp.static net.serenitybdd.screenplay.PerformableinstallAt(LocalDateTime dateTime) Install fake timers starting at the specified time.static net.serenitybdd.screenplay.Performablepause()Pause the clock.static net.serenitybdd.screenplay.Performableresume()Resume the clock after pausing.static net.serenitybdd.screenplay.PerformablesetSystemTimeTo(long epochMillis) Set the system time without installing fake timers.static net.serenitybdd.screenplay.PerformablesetSystemTimeTo(LocalDateTime dateTime) Set the system time without installing fake timers.
-
Method Details
-
freezeAt
Install fake timers and freeze time at the specified instant. Time will not advance until explicitly moved forward.- Parameters:
dateTime- The time to freeze at
-
freezeAt
public static net.serenitybdd.screenplay.Performable freezeAt(long epochMillis) Install fake timers and freeze time at the specified timestamp.- Parameters:
epochMillis- The Unix timestamp in milliseconds
-
freezeAt
Install fake timers and freeze time at the specified date.- Parameters:
date- The date to freeze at
-
installAt
Install fake timers starting at the specified time. Time will advance normally from this point.- Parameters:
dateTime- The initial time
-
installAt
public static net.serenitybdd.screenplay.Performable installAt(long epochMillis) Install fake timers starting at the specified timestamp.- Parameters:
epochMillis- The Unix timestamp in milliseconds
-
fastForward
public static net.serenitybdd.screenplay.Performable fastForward(long milliseconds) Advance time by the specified number of milliseconds.- Parameters:
milliseconds- Time to advance in milliseconds
-
fastForwardSeconds
public static net.serenitybdd.screenplay.Performable fastForwardSeconds(long seconds) Advance time by the specified number of seconds.- Parameters:
seconds- Time to advance in seconds
-
fastForwardMinutes
public static net.serenitybdd.screenplay.Performable fastForwardMinutes(long minutes) Advance time by the specified number of minutes.- Parameters:
minutes- Time to advance in minutes
-
fastForwardHours
public static net.serenitybdd.screenplay.Performable fastForwardHours(long hours) Advance time by the specified number of hours.- Parameters:
hours- Time to advance in hours
-
pause
public static net.serenitybdd.screenplay.Performable pause()Pause the clock. Time will not advance until resumed. -
resume
public static net.serenitybdd.screenplay.Performable resume()Resume the clock after pausing. -
setSystemTimeTo
Set the system time without installing fake timers. This only affects Date.now() and new Date(), not setTimeout/setInterval.- Parameters:
dateTime- The time to set
-
setSystemTimeTo
public static net.serenitybdd.screenplay.Performable setSystemTimeTo(long epochMillis) Set the system time without installing fake timers.- Parameters:
epochMillis- The Unix timestamp in milliseconds
-