2

I want to simulate multiple keypress(ctrl+alt, alt+enter, alt+uparrow etc) events for my acceptance test cases.

Ember test documentation has given an abstract syntax for the triggerEvent method. It's still unclear how to use it for multiple keypress events simulation.

edit: adding the code after the suggestion from comments.

let keytrigger = testSelector('random-id', "1");

triggerEvent(keytrigger, "keypress",{17,38});

Please help!

  • It would be awesome if you could share some code. We need to see what you have tried so far. :) – Badacadabra Apr 27 '17 at 13:30
  • Sure. ```var keytrigger = testSelector('random-id', "1"); triggerEvent(keytrigger, "keypress",{17,38}); ``` Also, I looked into [keyEvent](https://www.emberjs.com/api/classes/Ember.Test.html#method_keyEvent) which in turn calls [triggerEvent](https://github.com/emberjs/ember.js/blob/v2.12.0/packages/ember-testing/lib/helpers/key_event.js#L5) Need help on how to get my task done. – Karthikeyan Malaisamy Apr 27 '17 at 13:41
  • I suggest you to put the code in your question. You can edit it. ;) – Badacadabra Apr 27 '17 at 13:44
  • @KarthikeyanMalaisamy did not the answer I had provided work for you? – feanor07 May 11 '17 at 05:58
  • that is great, good luck! – feanor07 May 11 '17 at 06:20

1 Answers1

-1

It must be something like

triggerEvent('.myInputElement', 'keydown', {
  keyCode: 38,   // up arrow
  altKey: true,
  ctrlKey: true

});

for simulating ctrl+alt+up arrow simultaneously. For other properties to pass to keyboard event you can take a look at here I guess.

feanor07
  • 3,328
  • 15
  • 27
  • Should not it be a sequence of `keyboardEvent`s like `keydown` followed by `keyup`. – lft93ryt Aug 07 '17 at 01:07
  • I am trying to do a CTRL+G with `triggerEvent(node, 'keydown', {keyCode: 71, ctrlKey: true});` but still it does not work. is there any other method to do that. – lft93ryt Aug 07 '17 at 01:25
  • If you don't know the answer, why are you responding? If your response starts with "It must be something like" and ends with "I guess," you've done something wrong. – ChrisN Nov 09 '21 at 17:24