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): allow to clear number input (#2376)
Dmitry Gozman4413138cc6ac
diff --git a/src/injected/injectedScript.ts b/src/injected/injectedScript.tsindex 7acd156efe..c0e0a15b85 100644--- a/src/injected/injectedScript.ts+++ b/src/injected/injectedScript.ts@@ -211,7 +211,7 @@ export default class InjectedScript {return { status: 'error', error: 'Cannot fill input of type "' + type + '".' };if (type === 'number') {value = value.trim();- if (!value || isNaN(Number(value)))+ if (isNaN(Number(value)))return { status: 'error', error: 'Cannot type text into input[type=number].' };}if (input.disabled)diff --git a/test/page.spec.js b/test/page.spec.jsindex 93823978a5..d08e947cc5 100644--- a/test/page.spec.js+++ b/test/page.spec.js@@ -1164,16 +1164,15 @@ describe('Page.fill', function() {await page.fill('input', '-10e5');expect(await page.evaluate(() => input.value)).toBe('-10e5');});- it('should not be able to fill input[type=number] with empty string', async({page}) => {- await page.setContent(`<input id="input" type="number"></input>`);- let error = null;- await page.fill('input', '').catch(e => error = e);- expect(error.message).toContain('Cannot type text into input[type=number].');+ it('should be able to fill input[type=number] with empty string', async({page}) => {+ await page.setContent(`<input id="input" type="number" value="123"></input>`);+ await page.fill('input', '');+ expect(await page.evaluate(() => input.value)).toBe('');});it('should not be able to fill text into the input[type=number]', async({page}) => {await page.setContent(`<input id="input" type="number"></input>`);let error = null;- await page.fill('input', '').catch(e => error = e);+ await page.fill('input', 'abc').catch(e => error = e);expect(error.message).toContain('Cannot type text into input[type=number].');});it('should be able to clear', async({page, server}) => {