Implementation:MarketSquare Robotframework browser Clock Grpc Handlers
| Knowledge Sources | |
|---|---|
| Domains | Browser Automation, Clock Manipulation |
| Last Updated | 2026-02-12 05:40 GMT |
Overview
gRPC service handlers for Playwright clock manipulation operations including setting time, resuming, pausing, and advancing the browser clock.
Description
This module provides four async exported functions that handle gRPC requests for controlling the Playwright page clock API. Each handler retrieves the active page from PlaywrightState, validates it exists, and then delegates to the corresponding Playwright clock method.
setTime supports three clock types: fixed (freezes time at a specific point via setFixedTime), system (overrides system time via setSystemTime), and install (installs fake timers starting at the given time via clock.install). The input time is received in seconds and converted to milliseconds internally.
clockResume resumes a previously paused clock. clockPauseAt pauses the clock at a specified time (also converted from seconds to milliseconds). advanceClock advances the clock by a given duration using either fast_forward (jumps timers instantly) or run_for (fires timers sequentially as time passes).
Usage
These handlers are the Node.js-side implementation behind Robot Framework Browser library keywords for clock manipulation. They enable deterministic time-based testing by allowing tests to freeze, advance, pause, and resume the browser's internal clock, which is essential for testing animations, timeouts, scheduled tasks, and time-dependent UI behavior.
Code Reference
Source Location
- Repository: MarketSquare_Robotframework_browser
- File: node/playwright-wrapper/clock.ts
- Lines: 1-76
Signature
export async function setTime(request: Request.ClockSetTime, state: PlaywrightState): Promise<Response.Empty>
export async function clockResume(request: Request.Empty, state: PlaywrightState): Promise<Response.Empty>
export async function clockPauseAt(request: Request.ClockSetTime, state: PlaywrightState): Promise<Response.Empty>
export async function advanceClock(request: Request.ClockAdvance, state: PlaywrightState): Promise<Response.Empty>
Import
import { setTime, clockResume, clockPauseAt, advanceClock } from './clock';
I/O Contract
| Function | Request Type | Response Type | Description |
|---|---|---|---|
| setTime | Request.ClockSetTime (time in seconds, settype: 'fixed' / 'system' / 'install') | Response.Empty | Sets the page clock using the specified strategy; time is converted to milliseconds |
| clockResume | Request.Empty | Response.Empty | Resumes a previously paused clock on the active page |
| clockPauseAt | Request.ClockSetTime (time in seconds) | Response.Empty | Pauses the clock at the specified time; time is converted to milliseconds |
| advanceClock | Request.ClockAdvance (time in seconds, advancetype: 'fast_forward' / 'run_for') | Response.Empty | Advances the clock by the specified duration using the chosen strategy |
| Clock Type | Playwright Method | Behavior |
|---|---|---|
| fixed | page.clock.setFixedTime() | Freezes time at a specific point; Date.now() always returns this value |
| system | page.clock.setSystemTime() | Overrides system time but timers continue running |
| install | page.clock.install() | Installs fake timers starting at the given time |
| fast_forward | page.clock.fastForward() | Jumps clock forward, firing only due timers at the end |
| run_for | page.clock.runFor() | Advances clock step by step, firing timers sequentially as they become due |
Usage Examples
*** Settings ***
Library Browser
*** Test Cases ***
Clock Manipulation Example
New Browser chromium headless=true
New Page https://example.com
# Freeze time at a specific date
Set Clock fixed 2024-01-15T10:00:00Z
# Advance the clock by 60 seconds
Advance Clock 60 fast_forward
# Pause clock at a specific time
Pause Clock At 2024-01-15T11:00:00Z
# Resume the clock
Resume Clock