Skip to content

Test website geolocation with Playwright

Build a Playwright country test matrix with separate controls for proxy exit IP, locale, timezone and browser geolocation.

Mobileproxies.orgUpdated 4 min read

Configure the proxy for the network exit, locale and timezone for the browser environment, and geolocation only when testing the browser location API. Assert your site's actual behavior instead of treating those settings as interchangeable.

Separate the inputs in your test matrix

A country test needs an expected result. For an owned storefront, that might be a particular currency default, a region selector or a redirect. Write down whether the product specification says the result should depend on the exit IP, a saved preference or an explicit user choice.

Playwright's geolocation emulation changes the location exposed through the browser API when permission is granted. It does not move the request to a different network. A proxy changes the network path; it does not automatically change the browser language, timezone or location permission.

InputPlaywright controlWhat it tests
Network exitproxyServer behavior that depends on the connecting address.
LanguagelocaleBrowser language and locale-sensitive formatting.
TimezonetimezoneIdDate and time behavior in the browser.
Browser locationgeolocation + permissionFeatures that call the browser location API.
Saved preferenceFresh context or explicit storageWhether cookies/account state override defaults.

Create an isolated browser context

Use explicit credential fields for an authenticated HTTP proxy. Keep the endpoint and credentials in environment variables and outside the repository. The locale below is a test scenario; select a currently available proxy country separately.

A fresh context prevents a previous country's cookies from contaminating the next scenario. If the feature intentionally retains a user's country selection, write a separate persistence test rather than silently reusing state.

TypeScript · Playwright
import { test, expect } from '@playwright/test'

test('storefront uses the expected country', async ({ browser }) => {
  const context = await browser.newContext({
    proxy: {
      server: process.env.MP_PROXY_SERVER!,
      username: process.env.MP_PROXY_USERNAME!,
      password: process.env.MP_PROXY_PASSWORD!,
    },
    locale: 'en-GB',
    timezoneId: 'Europe/London',
  })
  try {
    const page = await context.newPage()
    await page.goto(process.env.QA_BASE_URL!)
    await expect(page.getByTestId('country-code'))
      .toHaveText(process.env.QA_EXPECTED_COUNTRY!)
  } finally {
    await context.close()
  }
})

country-code is a test hook on the owned demonstration site. Adapt the assertion to your application's contract. Do not assume arbitrary websites expose that attribute.

Assert the behavior that matters

Screenshots help explain a visual difference, but an image alone does not prove that the correct request path was used. Record the scenario name, expected country and the observed outcome alongside it.

Use synthetic accounts and owned pages for downloadable examples. Traces can include request headers, URLs and page content, so review them before uploading or sharing.

  • Confirm the network exit with a diagnostic endpoint before interpreting a country failure.
  • Assert the final route or selected country, not only a screenshot.
  • Check displayed currency and a stable product label where those are part of the specification.
  • Test an explicit country selection separately from automatic detection.
  • Add browser geolocation permission only for scenarios that need it.
Download the regional QA starter

Make a failed run useful

  1. Confirm that the chosen country plan is currently available.
  2. Separate proxy connection/authentication errors from assertion failures.
  3. Check whether the server and browser see the expected network and locale inputs.
  4. If IP databases disagree, use the location-mismatch worksheet.
  5. Reproduce once with the same inputs before changing multiple settings.

Sources and further reading

The guidance above distinguishes documented client behavior from product-specific details. Confirm current plan availability at checkout.