testcafe icon indicating copy to clipboard operation
testcafe copied to clipboard

Support simulation of Function keys

Open AndreyBelym opened this issue 9 years ago • 12 comments

Are you requesting a feature or reporting a bug?

Feature

What is the current behavior?

You can't use .pressKey to simulate function keys (F1-F12).

What is the expected behavior?

You can use something like .pressKey('F2').

How would you reproduce the current behavior (if this is a bug)?

Provide the test code and the tested page URL (if applicable)

Tested page URL:

Test code


Specify your

  • testcafe version: 0.18.0
  • node.js version: 8.6.0

AndreyBelym avatar Oct 17 '17 09:10 AndreyBelym

This would be useful! If not implemented soon, It'd be great to put a note in the docs to prevent future wild goose chases.

bjornhansen avatar Jul 06 '18 17:07 bjornhansen

This would indeed be useful.

maximojoexpress avatar Sep 24 '20 01:09 maximojoexpress

Indeed, this will be very useful so I hope it will be implemented soon, thanks.

Nikolaj1010 avatar Apr 27 '21 08:04 Nikolaj1010

This is something we really need. Is there any workaround? We are committed to TestCafe and absolutely need to test this feature

csurfleet avatar Jun 11 '21 08:06 csurfleet

For anyone struggling with this, I got around it with the following: ` const pressF2 = ClientFunction(() => {

    var event = new KeyboardEvent('keydown', { key: 'F2' });
    document.dispatchEvent(event)
});

await pressF2();

`

csurfleet avatar Jun 11 '21 12:06 csurfleet

Any update on this?

EmiM avatar Dec 01 '21 13:12 EmiM

No updates yet. Once we get any results, we will post them in this thread.

github-actions[bot] avatar Dec 22 '21 15:12 github-actions[bot]

Really needs this feature. Any plans for adding this?

maldzi avatar May 09 '22 09:05 maldzi

We still plan to implement this feature. However, we work on features that are on our Roadmap first.

AlexSkorkin avatar May 09 '22 11:05 AlexSkorkin

For anyone struggling with this, I got around it with the following: ` const pressF2 = ClientFunction(() => {

    var event = new KeyboardEvent('keydown', { key: 'F2' });
    document.dispatchEvent(event)
});

await pressF2();

`

For me it was a part of the solution (I work with TypeScript). I have solved the problem with:

` export const pressF1 = ClientFunction (() => {

    const event= new KeyboardEvent('keydown', { code: 'F1' });
    Object.defineProperty(event, 'keyCode', {  get : () => 112 });
    window.dispatchEvent(event);

} `

AND BEFORE that, I had to click to get focus an element (body)

mrb1994 avatar Jun 20 '22 11:06 mrb1994

Really guys, feature was reported almost 5 years ago!

maldzi avatar Jul 01 '22 09:07 maldzi

We decided not to introduce built-in support for event simulation for Function keys. Please use one of the workarounds from this thread or use the t.dispatchEvent action.

miherlosev avatar Jun 13 '23 07:06 miherlosev