Skip to content

Playwright: Can't type national characters: keyboard.press: Unknown key #5279

@mirao

Description

@mirao

Have this config:

import { setHeadlessWhen, setCommonPlugins } from '@codeceptjs/configure';
// turn on headless mode when running with HEADLESS=true environment variable
// export HEADLESS=true && npx codeceptjs run
setHeadlessWhen(process.env.HEADLESS);

// enable all common plugins https://github.com/codeceptjs/configure#setcommonplugins
setCommonPlugins();

export const config: CodeceptJS.MainConfig = {
  tests: './*_test.ts',
  output: './output',
  helpers: {
    Playwright: {
      browser: 'chromium',
      url: 'http://localhost',
      show: true
    }
  },
  include: {
    I: './steps_file'
  },
  plugins: {
    htmlReporter: {
      enabled: true
    }
  },
  name: 'my'
}

and this test:

Feature("My");

Scenario("Test national characters", ({ I }) => {
  I.type("Oprávněné"); // Czech characters
});

Run the test. It fails (keyboard.press: Unknown key: "á" undefined) 🐛 .

mirao@rog:~/workspace/my$ codeceptjs run --verbose
***************************************
nodeInfo:  20.19.5
osInfo:  Linux 6.14 Ubuntu 24.04.3 LTS 24.04.3 LTS (Noble Numbat)
cpuInfo:  (16) x64 AMD Ryzen 7 9700X 8-Core Processor
chromeInfo:  141.0.7390.122
edgeInfo:  "N/A"
firefoxInfo:  undefined
safariInfo:  N/A
playwrightBrowsers:  "chromium: 141.0.7390.37, firefox: 142.0.1, webkit: 26.0"
If you need more detailed info, just run this: npx codeceptjs info
***************************************
CodeceptJS v3.7.5 #StandWithUkraine
Using test root "/home/mirao/workspace/my"
Helpers: Playwright
Plugins: screenshotOnFail, htmlReporter, retryFailedStep, eachElement

My --
/home/mirao/workspace/my/My_test.ts
    [1]  Starting recording promises
    Timeouts: 
 › [Session] Starting singleton browser session
  Test national characters
 › [New Session] {"ignoreHTTPSErrors":false,"acceptDownloads":true}
  Scenario()
    I type "Oprávněné"
    [1]  Error (Non-Terminated) | Error: keyboard.press: Unknown key: "á" | err => { step.status = 'failed' step.endTime = +Da...
    [1] Error | Error: keyboard.press: Unknown key: "á" undefined...
HTML Reporter: Test finished - Test national characters, State: failed, Retries: 0
HTML Reporter: Test Test national characters artifacts at test.finished: []
HTML Reporter: Added new test - Test national characters, State: failed
    [1] <teardown>  Stopping recording promises
 › <screenshotOnFail> Test failed, try to save a screenshot
 › [Screenshot] output/Test_national_characters.failed.png
  ✖ FAILED in 163ms

    [2]  Starting recording promises

-- FAILURES:

  1) My
       Test national characters:
     
  keyboard.press: Unknown key: "á"
  
      at Playwright.type (node_modules/codeceptjs/lib/helper/Playwright.js:1879:32)
  
  
  ◯ File: file:///home/mirao/workspace/my/My_test.ts
  
  ◯ Scenario Steps:
  ✖ I.type("Oprávněné") at Test.<anonymous> (./My_test.ts:4:5)
  
  ◯ Artifacts:
  - screenshot: /home/mirao/workspace/my/output/Test_national_characters.failed.png
  
  ◯ Metadata:
  - browser: chromium
  - browserVersion: 141.0.7390.37
  - windowSize: 1280x720


  FAIL  | 0 passed, 1 failed   // 448ms

A problem is that the helper method type() uses the Playwright's API page.keyboard.press() and it allows only simple characters and modificators.

Workaround: Use page.keyboard.type() for strings.

This works ✔️ :

Feature("My");

Scenario("Test national characters", ({ I }) => {
  I.usePlaywrightTo("Test typing national characters", async ({ page }) => {
    await page.keyboard.type("Oprávněné"); // Czech characters
  });
});

Used SW:

  • CodeceptJS 3.7.5
  • Playwright 1.56.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions