Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

feat(lang): emulate language on firefox (#1453)

Pavel Feldmane210e5601c87
diff --git a/package.json b/package.json
index 81ad8b1e2c..769ac69bcc 100644
--- a/package.json
+++ b/package.json
@@ -9,7 +9,7 @@
"main": "index.js",
"playwright": {
"chromium_revision": "751710",
- "firefox_revision": "1044",
+ "firefox_revision": "1045",
"webkit_revision": "1180"
},
"scripts": {
diff --git a/src/firefox/ffBrowser.ts b/src/firefox/ffBrowser.ts
index c6e5ea7fb7..687e870996 100644
--- a/src/firefox/ffBrowser.ts
+++ b/src/firefox/ffBrowser.ts
@@ -170,8 +170,8 @@ export class FFBrowserContext extends BrowserContextBase {
async _initialize() {
if (this._options.permissions)
await this.grantPermissions(this._options.permissions);
- if (this._options.extraHTTPHeaders)
- await this.setExtraHTTPHeaders(this._options.extraHTTPHeaders);
+ if (this._options.extraHTTPHeaders || this._options.locale)
+ await this.setExtraHTTPHeaders(this._options.extraHTTPHeaders || {});
if (this._options.offline)
await this.setOffline(this._options.offline);
if (this._options.httpCredentials)
@@ -257,7 +257,10 @@ export class FFBrowserContext extends BrowserContextBase {
async setExtraHTTPHeaders(headers: network.Headers): Promise<void> {
this._options.extraHTTPHeaders = network.verifyHeaders(headers);
- await this._browser._connection.send('Browser.setExtraHTTPHeaders', { browserContextId: this._browserContextId || undefined, headers: headersArray(this._options.extraHTTPHeaders) });
+ const allHeaders = { ...this._options.extraHTTPHeaders };
+ if (this._options.locale)
+ allHeaders['Accept-Language'] = this._options.locale;
+ await this._browser._connection.send('Browser.setExtraHTTPHeaders', { browserContextId: this._browserContextId || undefined, headers: headersArray(allHeaders) });
}
async setOffline(offline: boolean): Promise<void> {
diff --git a/src/firefox/ffPage.ts b/src/firefox/ffPage.ts
index 724b351cea..a44eee30d8 100644
--- a/src/firefox/ffPage.ts
+++ b/src/firefox/ffPage.ts
@@ -87,6 +87,7 @@ export class FFPage implements PageDelegate {
async _initialize() {
const geolocation = this._browserContext._options.geolocation;
+ const language = this._browserContext._options.locale;
try {
await Promise.all([
// TODO: we should get rid of this call to resolve before any early events arrive, e.g. dialogs.
@@ -95,6 +96,7 @@ export class FFPage implements PageDelegate {
worldName: UTILITY_WORLD_NAME,
}),
geolocation ? this._setGeolocation(geolocation) : Promise.resolve(),
+ language ? this._session.send('Page.setLanguageOverride', { language }) : Promise.resolve(),
new Promise(f => this._session.once('Page.ready', f)),
]);
this._pageCallback(this._page);
diff --git a/test/assets/formatted-number.html b/test/assets/formatted-number.html
new file mode 100644
index 0000000000..93fd057a47
--- /dev/null
+++ b/test/assets/formatted-number.html
@@ -0,0 +1,3 @@
+<script>
+window.result = (1000000.50).toLocaleString().replace(/\s/g, ' ');
+</script>
diff --git a/test/emulation.spec.js b/test/emulation.spec.js
index 433debdf60..eb0f64485b 100644
--- a/test/emulation.spec.js
+++ b/test/emulation.spec.js
@@ -291,7 +291,7 @@ module.exports.describe = function({testRunner, expect, playwright, headless, FF
});
});
- describe.fail(FFOX)('BrowserContext({locale})', function() {
+ describe('BrowserContext({locale})', function() {
it('should affect accept-language header', async({browser, server}) => {
const context = await browser.newContext({ locale: 'fr-CH' });
const page = await context.newPage();
@@ -308,7 +308,7 @@ module.exports.describe = function({testRunner, expect, playwright, headless, FF
expect(await page.evaluate(() => navigator.language)).toBe('fr-CH');
await context.close();
});
- it('should format number', async({browser, server}) => {
+ it.fail(FFOX)('should format number', async({browser, server}) => {
{
const context = await browser.newContext({ locale: 'en-US' });
const page = await context.newPage();
@@ -324,7 +324,7 @@ module.exports.describe = function({testRunner, expect, playwright, headless, FF
await context.close();
}
});
- it('should format date', async({browser, server}) => {
+ it.fail(FFOX)('should format date', async({browser, server}) => {
{
const context = await browser.newContext({ locale: 'en-US', timezoneId: 'America/Los_Angeles' });
const page = await context.newPage();
@@ -342,6 +342,20 @@ module.exports.describe = function({testRunner, expect, playwright, headless, FF
await context.close();
}
});
+ it.fail(CHROMIUM || FFOX)('should apply to popups', async({browser, server}) => {
+ const context = await browser.newContext({ locale: 'fr-CH' });
+ const page = await context.newPage();
+ await page.goto(server.EMPTY_PAGE);
+
+ const [popup] = await Promise.all([
+ page.waitForEvent('popup'),
+ page.evaluate(url => window._popup = window.open(url), server.PREFIX + '/formatted-number.html'),
+ ]);
+ await popup.waitForLoadState({ waitUntil: 'domcontentloaded' });
+ const result = await popup.evaluate(() => window.result);
+ expect(result).toBe('1 000 000,5');
+ await context.close();
+ });
});
describe('focus', function() {