System info
- Playwright Version: v1.37.1
- Operating System: All
- Browser: All
- Other info:
Source code
Config file
// playwright.config.ts
import { defineConfig, devices } from '@playwright/test';
export default defineConfig({
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'], },
},
]
});
Test file (self-contained)
it('should check the box using setChecked', async ({ page }) => {
await page.setContent(`
<input id="input"></input>
<script>
window.__keyLog = "";
document.getElementById("input").addEventListener("keydown", (e) => {
window.__keyLog += e.code + ",";
});
</script>
`);
await page.locator("#input").type("ABC");
const keyLog = await page.evaluate("window.__keyLog");
expect(keyLog).toContain("Shift");
});
Steps
Expected
keyLog is something like ShiftLeft,KeyA,ShiftLeft,KeyB,ShiftLeft,KeyC, .
Actual
keyLog is KeyA,KeyB,KeyC, .
Notes
I see that #24614 changes to pressSequentially(), but it appears to use type() under the hood, so shouldn't make a difference.
I think the issue is that
|
async type(text: string, options?: { delay?: number }) { |
|
const delay = (options && options.delay) || undefined; |
|
for (const char of text) { |
|
if (usKeyboardLayout.has(char)) { |
|
await this.press(char, { delay }); |
|
} else { |
|
if (delay) |
|
await new Promise(f => setTimeout(f, delay)); |
|
await this.insertText(char); |
|
} |
|
} |
|
} |
calls insertText when a modifier key would be required, which for Chromium eventually calls https://chromedevtools.github.io/devtools-protocol/tot/Input/#method-insertText.
I find this misleading, especially for the Page.keyboard.type API — I expect it to exactly emulate the events a human typing on a real keyboard would generate.
System info
Source code
Config file
Test file (self-contained)
Steps
Expected
keyLogis something likeShiftLeft,KeyA,ShiftLeft,KeyB,ShiftLeft,KeyC,.Actual
keyLogisKeyA,KeyB,KeyC,.Notes
I see that #24614 changes to
pressSequentially(), but it appears to usetype()under the hood, so shouldn't make a difference.I think the issue is that
playwright/packages/playwright-core/src/server/input.ts
Lines 87 to 98 in a34030b
calls
insertTextwhen a modifier key would be required, which for Chromium eventually calls https://chromedevtools.github.io/devtools-protocol/tot/Input/#method-insertText.I find this misleading, especially for the
Page.keyboard.typeAPI — I expect it to exactly emulate the events a human typing on a real keyboard would generate.