Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
fix(fill): accept range values the browser re-serializes (#43343)
Yury Semikhatsky65f80bbc9503
diff --git a/packages/injected/src/injectedScript.ts b/packages/injected/src/injectedScript.tsindex 5346db99f5..f9cd653334 100644--- a/packages/injected/src/injectedScript.ts+++ b/packages/injected/src/injectedScript.ts@@ -925,7 +925,9 @@ export class InjectedScript {value = value.trim();input.focus();input.value = value;- if (input.value !== value)+ // The browser serializes range values in canonical form, e.g. "0.850" becomes "0.85".+ const accepted = type === 'range' ? Number(input.value) === Number(value) : input.value === value;+ if (!accepted)throw this.createStacklessError('Malformed value');element.dispatchEvent(new Event('input', { bubbles: true, composed: true }));element.dispatchEvent(new Event('change', { bubbles: true }));diff --git a/tests/page/page-fill.spec.ts b/tests/page/page-fill.spec.tsindex 3e918ab3c3..b667825e0e 100644--- a/tests/page/page-fill.spec.ts+++ b/tests/page/page-fill.spec.ts@@ -51,10 +51,17 @@ it('should fill different input types', async ({ page, server }) => {}});-it('should fill range input', async ({ page }) => {+it('should fill range input', {+ annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/43328' },+}, async ({ page }) => {await page.setContent('<input type=range min=0 max=100 value=50>');await page.fill('input', '42');expect(await page.$eval('input', input => input.value)).toBe('42');+ // Valid numbers that the browser may serialize differently.+ for (const [value, expected] of [['42.0', 42], ['1e1', 10]] as const) {+ await page.fill('input', value);+ expect(await page.$eval('input', (input: HTMLInputElement) => input.valueAsNumber)).toBe(expected);+ }});it('should throw on incorrect range value', async ({ page }) => {