0

We're developing several widgets, and have a requirement that we must support keyboard navigation (accessibility). We've added keyboard navigation as to the spec, and all is well, but we also want to test that it works using unit tests.

What we have tried is testing it with

  • selenium, but selenium does not seem to record arrow keys
  • busterJS, using the solution given in thread Simulate left and right arrow key event with javascript. But here we get different exceptions indicating that we are doing something illegal.
  • Triggering the event using jQuery trigger(), with the same results as the previous attempt.

I can understand that fireing keyboard events with key codes can be viewed as dangerous by browser manufacturers, and thus prohibited (If thats the core problem here). If this is actually the case, is there some option to set in IE10, Chrome or Firefox to enable the possibility to fire the events?

Any comments are welcomed, I might also be looking in the completely wrong direction here, so if you have some thoughts on how to unit test keyboard navigation in javascript, please feel free to enlighten me :)

Community
  • 1
  • 1
Henrik
  • 21
  • 4
  • I'm pretty sure you won't be able to do this. Programmatically fired events do not perform the associated native browser action. – Tim Down Aug 14 '12 at 08:43

1 Answers1

2

Well some solutions turned up,

  1. The old saying "when the user says nothing has changed, asume he is lying" turned out to be truthy once again. I retested the solution in the "Simulate left and right arrow key event with javascript" thread, and doing it exactly as the solution there described worked (except IE10).

    To make it work in IE10, I needed to switch the order of the if tests in the solution, because IE10 obviously only supports document.createEvent(), even though document.createEventObject evaluates to true.

  2. I also found a solution for Selenium.
    Even though selenium does not record the arrow key navigation, you can specify a keyDown command, set an element locator as your target and the escaped keyCode as your value (\37 = left, \38 = up, \39 = right, \40 = down)
    How to specify selenium element locators is described in the Selenium documentation

For both solutions to work, you need to attach the elements you want to use for your test to the DOM.

Community
  • 1
  • 1
Henrik
  • 21
  • 4