java.lang.Object
net.serenitybdd.screenplay.playwright.interactions.ControlClock

public class ControlClock extends Object
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 Type
    Method
    Description
    static net.serenitybdd.screenplay.Performable
    fastForward(long milliseconds)
    Advance time by the specified number of milliseconds.
    static net.serenitybdd.screenplay.Performable
    fastForwardHours(long hours)
    Advance time by the specified number of hours.
    static net.serenitybdd.screenplay.Performable
    fastForwardMinutes(long minutes)
    Advance time by the specified number of minutes.
    static net.serenitybdd.screenplay.Performable
    fastForwardSeconds(long seconds)
    Advance time by the specified number of seconds.
    static net.serenitybdd.screenplay.Performable
    freezeAt(long epochMillis)
    Install fake timers and freeze time at the specified timestamp.
    static net.serenitybdd.screenplay.Performable
    Install fake timers and freeze time at the specified instant.
    static net.serenitybdd.screenplay.Performable
    freezeAt(Date date)
    Install fake timers and freeze time at the specified date.
    static net.serenitybdd.screenplay.Performable
    installAt(long epochMillis)
    Install fake timers starting at the specified timestamp.
    static net.serenitybdd.screenplay.Performable
    Install fake timers starting at the specified time.
    static net.serenitybdd.screenplay.Performable
    Pause the clock.
    static net.serenitybdd.screenplay.Performable
    Resume the clock after pausing.
    static net.serenitybdd.screenplay.Performable
    setSystemTimeTo(long epochMillis)
    Set the system time without installing fake timers.
    static net.serenitybdd.screenplay.Performable
    Set the system time without installing fake timers.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • freezeAt

      public static net.serenitybdd.screenplay.Performable freezeAt(LocalDateTime dateTime)
      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

      public static net.serenitybdd.screenplay.Performable freezeAt(Date date)
      Install fake timers and freeze time at the specified date.
      Parameters:
      date - The date to freeze at
    • installAt

      public static net.serenitybdd.screenplay.Performable installAt(LocalDateTime dateTime)
      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

      public static net.serenitybdd.screenplay.Performable setSystemTimeTo(LocalDateTime dateTime)
      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