Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Setting a different locale does not work as expected #30842

Closed
DanielStoica85 opened this issue May 16, 2024 · 4 comments
Closed

[Bug]: Setting a different locale does not work as expected #30842

DanielStoica85 opened this issue May 16, 2024 · 4 comments

Comments

@DanielStoica85
Copy link

DanielStoica85 commented May 16, 2024

Version

1.44.0

Steps to reproduce

I am based in The Netherlands. I am trying to write a test that checks if a redirect happens as expected based on the user's locale or location. The example I will give you below tests the Adidas website. This is just an example, I don't actually work at/for Adidas. :)

This is the test:

import { test, expect, type Page } from '@playwright/test';

test.use({
  locale: 'de-DE',
  timezoneId: 'Europe/Berlin',
});

test('test', async ({ page }) => {
  await page.goto('https://www.adidas.com', { timeout: 45000 });
  await page.waitForURL('https://www.adidas.de');
});

Expected behavior

I expect to be redirected to https://www.adidas.de

Actual behavior

I am redirected to https://www.adidas.nl

Additional context

It seems like the redirect happens based on my actual location/locale and not based on the one I set by using test.use().

Environment

System:
    OS: macOS 14.4.1
    CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
    Memory: 1012.85 MB / 32.00 GB
  Binaries:
    Node: 18.7.0 - ~/.nvm/versions/node/v18.7.0/bin/node
    npm: 8.15.0 - ~/.nvm/versions/node/v18.7.0/bin/npm
  IDEs:
    VSCode: 1.89.1 - /usr/local/bin/code
  Languages:
    Bash: 3.2.57 - /bin/bash
  npmPackages:
    @playwright/test: ^1.44.0 => 1.44.0

I tested this with several other locales, but the redirect still always happens based on my "real" location and not based on the one I set in the test.

@DanielStoica85
Copy link
Author

DanielStoica85 commented May 16, 2024

Update 1

I also added this to check what the detected locale is and the result was indeed de-DE, but somehow the redirect still does not happen accordingly.

// Execute JavaScript in the browser context to get the detected locale
  const detectedLocale = await page.evaluate(() => {
    // Access the browser's navigator object to get the language
    return navigator.language;
  });

  console.log('Detected Locale:', detectedLocale);

image

Update 2

Also checked the request headers and the Accept-Language is indeed de-DE, but then in the response headers I also see this:

image

Update 3: tried this on other websites as well and I always get redirected based on my real location and not based on the one set by Playwright

@yury-s
Copy link
Member

yury-s commented May 16, 2024

They may be redirecting you based on your IP address or some other logic. The adidas url does redirect me to 'https://www.adidas.com/us'. If you think that Playwright is not changing some settings properly based on locale, please provide a self contained reproduction which we could run locally.

@DanielStoica85
Copy link
Author

If that is the case (it most likely is), is there another (better) way to emulate a location by using Playwright, so that we can verify that the redirect happens as expected based on location?

@mxschmitt
Copy link
Member

IP address based geolocation detection can only be emulated on the networking level, so e.g. a proxy might work for you.

Closing since thats not a bug in Playwright.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants