Browser time
DrevOps\BehatSteps\Steps\Web\BrowserTimeTrait - Source, Example, Helpers
Set the time and the timezone a page's JavaScript reads in the browser.
- Set the time 'Date' reads in each page loaded after the step.
- Set the timezone the browser formats and reports dates in.
- Reset both to the real time and the browser's own timezone.
The time applies from the next page load, so set it before visiting the page under test. It ticks on from the given value and stays continuous across page loads. The timezone applies at once.
The steps send Chrome DevTools Protocol commands, so they run on a Chromium browser through the Selenium2 or the Chrome browser driver.
Skip processing with tag:@behat-steps-skip:BrowserTimeTrait.
Options
| Option | Type | Default | Tag | Description |
|---|---|---|---|---|
browser_time.enabled | boolean | TRUE | @behat-steps-skip:BrowserTimeTrait | If TRUE, restores the real browser time and timezone after a scenario that set either. If FALSE, the browser keeps them. |
Steps
@Given the browser time is set to :value
Set the browser time for the pages loaded after this step
Given the browser time is set to "2026-12-24 23:59:00"
Given the browser time is set to "1798156740"
@Given the browser time is set to :value in the timezone :name
Set the browser time and timezone for the pages loaded after this step
Given the browser time is set to "2026-12-24 23:59:00" in the timezone "Australia/Melbourne"
@Given the browser timezone is set to :name
Set the browser timezone without changing the browser time
Given the browser timezone is set to "America/New_York"
@When the browser time is reset
Reset the browser timezone now, and the time from the next page load
When the browser time is reset