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(keyboard): correctly press enter on firefox (#1023)
Joel Einbinder21acb369dbeb
diff --git a/src/firefox/ffInput.ts b/src/firefox/ffInput.tsindex 8627add2ec..66e55b8fa4 100644--- a/src/firefox/ffInput.ts+++ b/src/firefox/ffInput.ts@@ -64,6 +64,9 @@ export class RawKeyboardImpl implements input.RawKeyboard {code = 'OSLeft';if (code === 'MetaRight')code = 'OSRight';+ // Firefox will figure out Enter by itself+ if (text === '\r')+ text = '';await this._client.send('Page.dispatchKeyEvent', {type: 'keydown',keyCode: keyCodeWithoutLocation,diff --git a/test/keyboard.spec.js b/test/keyboard.spec.jsindex a6ebcc715a..d4621f6155 100644--- a/test/keyboard.spec.js+++ b/test/keyboard.spec.js@@ -207,15 +207,23 @@ module.exports.describe = function({testRunner, expect, FFOX, CHROMIUM, WEBKIT,await textarea.press('NumpadSubtract');expect(await page.evaluate('keyLocation')).toBe(3);});- it.skip(FFOX)('should press Enter', async({page, server}) => {- await page.setContent('<input></input>');- await page.$eval('input', body => body.addEventListener('keydown', event => {- if (event.key === 'Enter')- window.ENTER_DOWN = true;- }, false));- await page.focus('input');- await page.keyboard.press('Enter');- expect(await page.evaluate(() => window.ENTER_DOWN)).toBe(true);+ it('should press Enter', async({page, server}) => {+ await page.setContent('<textarea></textarea>');+ await page.focus('textarea');+ await page.evaluate(() => window.addEventListener('keydown', e => window.lastEvent = {key: e.key, code:e.code}));+ await testEnterKey('Enter', 'Enter', 'Enter');+ await testEnterKey('NumpadEnter', 'Enter', 'NumpadEnter');+ await testEnterKey('\n', 'Enter', 'Enter');+ await testEnterKey('\r', 'Enter', 'Enter');++ async function testEnterKey(key, expectedKey, expectedCode) {+ await page.keyboard.press(key);+ const lastEvent = await page.evaluate('lastEvent');+ expect(lastEvent.key).toBe(expectedKey, `${JSON.stringify(key)} had the wrong key: ${lastEvent.key}`);+ expect(lastEvent.code).toBe(expectedCode, `${JSON.stringify(key)} had the wrong code: ${lastEvent.code}`);+ expect(await page.$eval('textarea', t => t.value)).toBe('\n', `${JSON.stringify(key)} failed to create a newline`);+ await page.$eval('textarea', t => t.value = '');+ }});it('should throw on unknown keys', async({page, server}) => {let error = await page.keyboard.press('NotARealKey').catch(e => e);