Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple keys in sendKeys action #56

Open
pepelsbey opened this issue Feb 14, 2014 · 9 comments
Open

Multiple keys in sendKeys action #56

pepelsbey opened this issue Feb 14, 2014 · 9 comments
Assignees

Comments

@pepelsbey
Copy link

I'm trying to pass multiple keys Cmd Alt P at the same time to Dalek to test page behavior:

test
    .open('themes/ribbon/index.html')
    .sendKeys('body', '\uE03D\uE00A\u0050') // Cmd Alt P
    .assert.attr('body', 'class', 'full')
.done();

And it seems doesn't work as test is failing. I'm using W3C WebDriver spec for key codes reference, but I haven't found clear description on how to send multiple keys (both in Dalek docs and spec), especially with regular, not special ones like Alt and Cmd.

The same test with just a F5 works fine, of course:

test
    .open('themes/ribbon/index.html')
    .sendKeys('body', '\uE035') // F5
    .assert.attr('body', 'class', 'full')
.done();

Cross-posted from StackOverflow

@asciidisco
Copy link
Member

As @ryanzec has the most experience with this, I´m happily delegating the question ;)

@ryanzec
Copy link
Contributor

ryanzec commented Feb 16, 2014

I don't think this is an issue with DalekJS. \e0050 is the code for a capital P and
\u0070 is the code for a lowercase p. When I use \u0070, everything seems to work (using keymaster to bind events to keys pressed).

Could you give the code you are using to trigger code execution with certain keys being pressed?

@pepelsbey
Copy link
Author

Here's full test with \u0070 you suggested: first passed, second failed.

module.exports = {
    'Body class is switching from `list` to `full` on F5': function (test) {
        test
            .open('http://shwr.me/shower/themes/ribbon/')
            .sendKeys('body', '\uE035') // F5
            .assert.attr('body', 'class', 'full', 'Mode is full')
        .done();
    },
    // Cmd Alt P
    'Body class is switching from `list` to `full` on Cmd Alt P': function (test) {
        test
            .open('http://shwr.me/shower/themes/ribbon/')
            .sendKeys('body', '\uE03D\uE00A\u0070') // Cmd Alt P
            .assert.attr('body', 'class', 'full', 'Mode is full')
        .done();
    }
};

But when I manually press F5 and Cmd Alt P on ribbon page they acts the same.

@ryanzec
Copy link
Contributor

ryanzec commented Feb 17, 2014

@pepelsbey I have tested the cmd alt p my my Mac locally and the test works properly, are you on a Mac or PC? If you are on a PC, maybe there is something with Windows causing the issue. I would need a full example (the actually code with the tests) with the test failing but the code working to further investigate this since the example I have created works properly.

@pepelsbey
Copy link
Author

I'm on Mac (with latest everything: OS, Node.js, DalekJS, etc.) and testing it using default PhantomJS.

@ryanzec
Copy link
Contributor

ryanzec commented Feb 17, 2014

@pepelsbey Try testing with Chrome (that is what I have been using), might be an issue with PhantomJS.

@pepelsbey
Copy link
Author

Here's my output

$ dalek tests/test.js 
Running tests
Running Browser: PhantomJS
OS: mac unknown 32bit
Browser Version: 1.9.7

RUNNING TEST - "Body class is switching from `list` to `full` on F5"
▶ OPEN http://shwr.me/shower/themes/ribbon/
▶ SENDKEYS body
✔ ATTRIBUTE Mode is full
✔ 1 Assertions run
✔ TEST - "Body class is switching from `list` to `full` on F5" SUCCEEDED

RUNNING TEST - "Body class is switching from `list` to `full` on Cmd Alt P"
▶ OPEN http://shwr.me/shower/themes/ribbon/
▶ SENDKEYS body
✘ ATTRIBUTE
0 EXPECTED: full
0 FOUND: list
0 MESSAGE: Mode is full
✘ TEST - "Body class is switching from `list` to `full` on Cmd Alt P" FAILED

 1/2 assertions passed. Elapsed Time: 6.98 sec 

@pepelsbey
Copy link
Author

Yep, works fine with -b chrome option. Thank you, I should've tried it myself.

@hadynz
Copy link

hadynz commented Aug 5, 2014

In case this is useful to anyone else, I've written a small NPM module unicode-keymap to return a key code reference map based on the W3C WebDriver Spec.

Example usage:

var keys = require('unicode-keymap');

module.exports = {
    'Body class is switching from `list` to `full` on Cmd Alt P': function (test) {
        test
            .open('http://shwr.me/shower/themes/ribbon/')
            .sendKeys('body', keys.CONTROL + keys.ALT + '\u0050') // Cmd Alt P
            .assert.attr('body', 'class', 'full', 'Mode is full')
        .done();
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants