QA Interview Hub · Knowledge base · Quizzes · Українська

Playwright › Emulation and environment

Geolocation, permissions, locale and time zone

Locale, time zone, geolocation and permissions are set with explicit context options so that a result does not depend on the machine. Without them the browser takes locale and time zone from the machine, so a test green in Kyiv can fail in UTC. timezoneId does not change the Node process time zone, so the expected date is computed with Intl and an explicit timeZone.

Playwright · Emulation

The test is green in Kyiv but fails in CI on a server. What differs there: the date, locale or time zone?

A transaction is made at 00:30 Kyiv time on 11 March. A developer writes the expectation "11.03.2026" and sees a green test. In CI on a server in UTC the same test fails: the page shows 10.03.2026. The bug is neither in the application nor in the test: the test silently depended on the settings of the machine it runs on. This lesson is about fixing the browser environment (locale, time zone, geolocation, permissions) so the result does not depend on where the run happens.

How it works and why. For each test Playwright creates a new browser context, and the environment in it is set by context options. If they are not specified, the browser takes the locale and the time zone from the machine, so a laptop and a CI image behave differently. Explicit options remove that:

  • locale affects navigator.language, the Accept-Language header and the formatting of numbers and dates through Intl;
  • timezoneId changes the browser's time zone (new Date(), Intl.DateTimeFormat), but not the zone of the Node process that runs the test code itself;
  • geolocation sets the coordinates that navigator.geolocation returns;
  • permissions allows browser APIs, for example geolocation or clipboard-read.

Geolocation without a permission does not work: the coordinates are set, but the application gets a refusal. So maps need both options. locale and timezoneId are set when the context is created: through test.use or a project, not in the middle of a test. Geolocation and permissions can also be changed during a test.

test.use({
  locale: 'uk-UA',
  timezoneId: 'Europe/Kyiv',
  geolocation: { latitude: 49.8397, longitude: 24.0297 },
  permissions: ['geolocation'],
});

test('the nearest branch depends on the position', async ({ page, context }) => {
  await page.goto('/branches');
  await expect(page.getByText('Lviv, Rynok Sq.')).toBeVisible();
  await context.setGeolocation({ latitude: 50.4501, longitude: 30.5234 });
  await page.getByRole('button', { name: 'Refresh' }).click();
  await expect(page.getByText('Kyiv')).toBeVisible();
});

Permissions are granted through permissions in the config or a test, or through context.grantPermissions(['clipboard-read'], { origin }), and reset with context.clearPermissions(). The set of supported permissions differs slightly between browsers. The scenario "the user denied geolocation" is checked by simply not granting the permission: the application must show a clear message and not hang.

One moment, different calendar days

paidAt: 2026-03-10T22:30:00Z UTC22:30 · 10.03 Europe/Kyiv00:30 · 11.03 America/New_York18:30 · 10.03 Pacific/Auckland11:30 · 11.03 The date in a row depends on the zone
Figure 1. The same moment in different zones gives a different calendar date: a test with a hard-coded date fits only one of them.

Example: the Kyiv test fails in UTC. Suppose the statement page builds the date on the client through Intl in the browser's time zone, and the transaction arrives from the server as paidAt: 2026-03-10T22:30:00Z (fixed test data or a mock).

// before: the expectation is written for Kyiv
test('transaction date', async ({ page }) => {
  await page.goto('/statement');
  await expect(page.getByRole('row', { name: /Transfer/ }))
    .toContainText('11.03.2026');
});
Error: expect(locator).toContainText(expected)
Expected substring: "11.03.2026"
Received string:    "Transfer ... 10.03.2026 22:30"

This is a shortened output. Read it like this: the application did not break, the browser in CI simply runs in UTC, and for it the moment is still "10 March". The right fix has two parts. First, the zone is fixed so that the run is reproducible. Then the expected value is calculated for that zone through Intl with an explicit timeZone rather than typed as text.

// after: the zone is set, the expectation is derived from it
const paidAt = new Date('2026-03-10T22:30:00Z');
const fmt = { day: '2-digit', month: '2-digit', year: 'numeric' } as const;
const zones = ['Europe/Kyiv', 'America/New_York', 'Pacific/Auckland'];

for (const timezoneId of zones) {
  test.describe('statement in the zone ' + timezoneId, () => {
    test.use({ timezoneId, locale: 'uk-UA' });

    test('the date matches the user zone', async ({ page }) => {
      const expected = new Intl.DateTimeFormat('uk-UA', {
        ...fmt,
        timeZone: timezoneId,
      }).format(paidAt);
      await page.goto('/statement');
      await expect(page.getByRole('row', { name: /Transfer/ }))
        .toContainText(expected);
    });
  });
}

Kyiv expects 11.03.2026, New York 10.03.2026, Auckland 11.03.2026. If the application wrongly shows the date in UTC, at least Kyiv fails, and the bug does not hide behind a coincidence of zones.

Locale and number formats. With locale: 'uk-UA' an amount looks like "1 000,50 ₴", and with en-US like "$1,000.50". The thousands separator in a formatted string can be a non-breaking space, so comparing with a literal space is unreliable. A regular expression with \s matches both an ordinary and a non-breaking space:

test.use({ locale: 'uk-UA' });

test('amount in the uk-UA format', async ({ page }) => {
  await page.goto('/account');
  await expect(page.getByTestId('balance')).toHaveText(/1\s000,50\s₴/);
});

Limits and alternatives. locale only tells the browser the language: the translation is done by the application, if it reads navigator.language or Accept-Language. timezoneId does not change the zone of the server or of the test's Node process: new Date() in the test code stays in the machine's zone, so the expected value is calculated explicitly, as in the example. If a specific "now" is needed too, time is fixed separately through page.clock. Cypress and Selenium have no such built-in way for a time zone: there it is usually set through process environment variables or browser settings.

Common mistakes.

  • Setting geolocation and forgetting permissions: ['geolocation']: the application gets a refusal, and the test checks the wrong thing.
  • Typing the expected date as text: the test fits one zone and fails in CI.
  • Comparing an amount with an ordinary space instead of a non-breaking one: the difference is at the character level, while on screen it looks the same.
  • Checking only one zone: a date that works in Kyiv breaks in the west or the east.
  • Relying on the machine's locale: the same test formats numbers differently on a laptop and in a CI image.

Check yourself

A test sets geolocation in Lviv, but the application shows "Geolocation access denied". What is missing?

Answer

The permission: permissions: ['geolocation'] in use or context.grantPermissions. Without a permission the browser does not hand over the coordinates, and the application gets a refusal. This is also useful for the opposite scenario: to check the behaviour on refusal, you simply do not grant the permission.

A test expects "11.03.2026", it is green on a laptop in Kyiv and red in CI in UTC. Why, and how to fix it?

Answer

The moment 22:30Z is already 11 March in Kyiv but still the 10th in UTC. The test depends on the machine's zone. Fix timezoneId in test.use and derive the expected value through Intl.DateTimeFormat with the same timeZone, or better, run several zones.

In an interview. Junior: For localisation I set locale and timezoneId, and for geolocation both coordinates and a permission in permissions are needed. Middle/Senior: I do not leave the browser environment to the machine, because a test that passed in Kyiv and failed in UTC is flakiness by configuration. I calculate expected dates through Intl with an explicit zone, run several zones at the day boundary, and remember that timezoneId does not change the Node process or the server, while the "current" time I fix through page.clock.

More articles in this chapter