Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(codegen): make sure input recording with japanese IME Work #16400

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/playwright-core/src/server/injected/recorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ class Recorder {
if (event.key === 'Insert' && event.shiftKey)
return false;
}
if (['Shift', 'Control', 'Meta', 'Alt'].includes(event.key))
if (['Shift', 'Control', 'Meta', 'Alt', 'Process'].includes(event.key))
return false;
const hasModifier = event.ctrlKey || event.altKey || event.metaKey;
if (event.key.length === 1 && !hasModifier)
Expand Down
44 changes: 44 additions & 0 deletions tests/library/inspector/cli-codegen-1.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,50 @@ test.describe('cli codegen', () => {
expect(message.text()).toBe('John');
});

test('should fill japanese text', async ({ page, openRecorder }) => {
const recorder = await openRecorder();

// In Japanese, "てすと" or "テスト" means "test".
await recorder.setContentAndWait(`<input id="input" name="name" oninput="input.value === 'てすと' && console.log(input.value)"></input>`);
const selector = await recorder.focusElement('input');
expect(selector).toBe('input[name="name"]');

async function inputText(text: string) {
await recorder.page.dispatchEvent(selector, 'keydown', { key: 'Process' });
await recorder.page.keyboard.insertText(text);
await recorder.page.dispatchEvent(selector, 'keyup', { key: 'Process' });
}
const [message, sources] = await Promise.all([
page.waitForEvent('console', msg => msg.type() !== 'error'),
recorder.waitForOutput('JavaScript', 'fill'),
(async () => {
await inputText('て');
await inputText('す');
await inputText('と');
})()
]);
expect(sources.get('JavaScript').text).toContain(`
// Fill input[name="name"]
await page.locator('input[name="name"]').fill('てすと');`);
expect(sources.get('Java').text).toContain(`
// Fill input[name="name"]
page.locator("input[name=\\\"name\\\"]").fill("てすと");`);

expect(sources.get('Python').text).toContain(`
# Fill input[name="name"]
page.locator(\"input[name=\\\"name\\\"]\").fill(\"てすと\")`);

expect(sources.get('Python Async').text).toContain(`
# Fill input[name="name"]
await page.locator(\"input[name=\\\"name\\\"]\").fill(\"てすと\")`);

expect(sources.get('C#').text).toContain(`
// Fill input[name="name"]
await page.Locator(\"input[name=\\\"name\\\"]\").FillAsync(\"てすと\");`);

expect(message.text()).toBe('てすと');
});

test('should fill textarea', async ({ page, openRecorder }) => {
const recorder = await openRecorder();

Expand Down