Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

Press special character in Browser Playback Tool

Robin
Robin Posts: 1

In the Browser Playback Tool there is an user action for KeyUp, KeyDown and Type. However all of these require a Text Input. How can I use there for a charactler like the Escape key for example.

Comments

  • tony
    tony Posts: 25 ✭✭

    To simulate keys that do not produce characters you will need to use the Execute JavaScript functionality. Please note that this may not work in all cases, as browsers often have auxiliary behavior attached to these non-character keys (such as dropping focus) that is not emulated through JavaScript. This will simply trigger any code listening for an event on the specified key.

    Below is an example of how to trigger a "keydown" with the "Escape" key. You can modify this code to trigger different events with different keys by changing "keycode" and "eventType."

    function typeSpecialCharacter(element) {
        var keycode = 27; // the escape keycode
        var eventType = "keydown";
        var evt;
        var win = element.ownerDocument.defaultView;
        if (win.KeyEvent) {
           evt = element.ownerDocument.createEvent('KeyEvents');
           evt.initKeyEvent(eventType, true, true, win, false, false, false, false, keycode, keycode);
        } else {
           evt = element.ownerDocument.createEvent('UIEvents');
           evt.initUIEvent(eventType, true, true, win, 1);
           evt.keyCode = keycode;
        }
        element.dispatchEvent(evt);
    }