DevExpress / testcafe

A Node.js tool to automate end-to-end web testing.
https://testcafe.io
MIT License
9.83k stars 673 forks source link

The code returned by using t.pressKey("esc") to trigger the keydown event is "" #8328

Closed goodnightql closed 2 weeks ago

goodnightql commented 3 weeks ago

What is your Scenario?

Use testcafe to simulate keystrokes await t.pressKey("esc")

What is the Current behavior?

image

What is the Expected behavior?

return as manual triggerred

What is the public URL of the test page? (attach your complete example)

my test html page

What is your TestCafe test code?

fixture('DDVUITest PerspectiveViewer').page("your html page").before( ctx=>{
}) .beforeEach(async t=>{

}) .afterEach(t=>{ }) .afterEach(t=>{ }) .after(ctx=>{

}).skipJsErrors(); test("keydown",async t => { await t.eval(()=>{ window.addEventListener("keydown",e=>console.log(e)) }) await t.pressKey("esc") })

Your complete configuration file

No response

Your complete test report

No response

Screenshots

No response

Steps to Reproduce

testcafe chrome test.js --live check the outputInfo in the browser console

TestCafe version

3.7.0-rc.3

Node.js version

20.17.0

Command-line arguments

testcafe chrome test.js

Browser name(s) and version(s)

chrome Version 130.0.6723.70 (Official Build) (64-bit)

Platform(s) and version(s)

windows 11

Other

No response

Bayheck commented 2 weeks ago

Hello, thank you for reaching out to us.

TestCafe t.pressKey does not support the code property of the KeyboardEvent. We recommend using the following workaround with the t.dispatchEvent method to fire your own DOM event:

await t.dispatchEvent(Selector('body'), 'keydown', { code: 'Escape',})

I will close this ticket.