pestphp / pestphp/pest

Add withLocale() to global browser configuration

Open
#1,659 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
11.7k
Forks
538
Avg merge
4d 11h
Merged PRs (30d)
8

Description

Problem

withLocale() exists on PendingAwaitablePage (per-visit level):

$page = visit('/')->withLocale('fr-FR');

But there is no equivalent on the global pest()->browser() configuration (Configuration class). The default locale is hardcoded to en-US in PendingAwaitablePage::buildAwaitablePage():

$context = $browser->newContext([
    'locale' => 'en-US',
    // ...
    ...$options,
]);

This means every visit() call defaults to en-US for navigator.language, and there's no way to change this globally without passing ['locale' => 'fr'] to every single visit() call.

Use case

Applications that detect the browser language via navigator.language to set the UI language need the Playwright browser context to use the correct locale. With 60+ test files and 179 visit() calls, passing the locale to each one is not practical.

Desired behavior

// tests/Pest.php
pest()->browser()->withLocale('fr');

Similar to how withHost(), userAgent(), timeout(), inDarkMode() etc. already work on Configuration.

Suggested implementation

  1. Add Playwright::setDefaultLocale(string $locale) and Playwright::defaultLocale() (similar to existing setHost/host pattern)
  2. Add Configuration::withLocale(string $locale) that calls Playwright::setDefaultLocale()
  3. Use Playwright::defaultLocale() ?? 'en-US' in PendingAwaitablePage::buildAwaitablePage()

Environment

  • pest-plugin-browser: 4.0
  • Pest: 4.x
  • PHP: 8.5

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the existing setHost/host pattern in Playwright and Configuration, then inspect PendingAwaitablePage::buildAwaitablePage() where the browser context locale defaults to en-US. Add the global locale behavior described in the issue and verify that visit() uses it for navigator.language while retaining en-US when no locale is configured.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, playwright
Domain
testing
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.