Test Locale, Time Zone and Location with Playwright
Locale, time zone and geolocation affect different parts of an application. Set them deliberately in an authorized test, then verify the output that each setting is meant to change.
Pick the behavior before the settings
A useful test starts with one question: does the date format match the selected locale, does an event appear on the correct local day, or does a nearby-store control handle a location? These are separate assertions. Record the application input and expected output so the test doesn't simply confirm that a configuration option was set.
Apply options to the context
Playwright's emulation documentation describes context options for locale, timezoneId, geolocation and permissions. For a location test, set coordinates and grant the appropriate geolocation permission in the test context. Also test denial or unavailable location if the application must handle those cases.
Locale doesn't automatically select a user's time zone, and a time zone doesn't supply geographic coordinates. Use explicit values appropriate to each test. Keep fixtures and test accounts separate when changing location-sensitive data, and close the context after the run.
Watch the boundaries
Emulated browser settings don't change the machine's physical location or necessarily change how an external service identifies the network. A desktop context with a mobile viewport isn't a physical phone test. If a service uses server-side location or account settings, control those inputs separately in an environment you own.
Check dates around a daylight-saving transition and near midnight when the product's rules make those boundaries relevant. Compare displayed values to the documented business rule rather than assuming the operating system's default locale. Avoid collecting real location data just to build a repeatable test.
Example: a separate London test context
context = browser.new_context(
locale="en-GB",
timezone_id="Europe/London",
geolocation={"latitude": 51.5072, "longitude": -0.1276},
permissions=["geolocation"],
)
try:
page = context.new_page()
page.goto("http://127.0.0.1:8000/")
# Assert the application output for the controlled fixture.
finally:
context.close()
This Python example assumes a running browser and a local fixture. Test permission denial in a separate context without the grant, and assert the application’s displayed result for a fixed input. The coordinates and time zone are test inputs, not proof of a physical device or a user’s actual location.
If you need help planning an authorized automation workflow, ask for a scoped assessment. Share the documented limits and a redacted example, without credentials or private data.