Results 1 to 4 of 4

Thread: Keyboard events in WebDriver Tests

  1. #1
    Sencha Premium User
    Join Date
    Oct 2014
    Posts
    17
    Answers
    1

    Default Answered: Keyboard events in WebDriver Tests

    I recently changed our application's handling of the F5 key from plain javascript

    Code:
    var me = this;
    document.onkeydown=function (e) {
       if ((e.which || e.keyCode) == 116 || (e.which || e.keyCode) == 82) {
            // console.log('F5 key');
            e.preventDefault();
            me.onF5();
        }
    };
    to using the Ext KeyNav


    Code:
    new Ext.util.KeyNav({
        target: document.body,
        116: this.onF5,
        82: this.onF5,
        scope: this,
    });
    Unfortunately I'm having a hard time testing the application's response to a keyboard event in a WebDriver test because I haven't been able to figure out how to send the F5 key.
    I can test a call to the onF5 function, but this isn't exactly what I'm after since I'd like to verify the app's response to the keyboard event all the way through.

    How can I send F5 to the "document body" in a WebDriver test in such a way that the KeyNav I have set up will detect it.

    This is what I was previously doing in my test code that no longer works:
    Code:
            ST.execute(function(){
               document.dispatchEvent(new KeyboardEvent('keydown', { 'keyCode': 116, 'which': 116}));
             });

  2. Please try the following:

    Code:
    ST.element('//body')
        .type({
            key: 'F5'
        });

  3. #2
    Sencha - Sales Team daniel.gallo's Avatar
    Join Date
    Apr 2009
    Location
    London, England
    Posts
    369
    Answers
    63

    Default

    Please try the following:

    Code:
    ST.element('//body')
        .type({
            key: 'F5'
        });
    Daniel Gallo
    Sales Engineer
    Sencha

  4. #3
    Sencha Premium User
    Join Date
    Oct 2014
    Posts
    17
    Answers
    1

    Default

    That worked! Thank you!

  5. #4
    Sencha Premium User
    Join Date
    Oct 2014
    Posts
    17
    Answers
    1

    Default

    What about a key combination like Shift-Tab?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •