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

sendkeys for Chrome has issues with non-English keyboards #3003

Closed
vincentdieltiens opened this issue Mar 5, 2016 · 5 comments
Closed

sendkeys for Chrome has issues with non-English keyboards #3003

vincentdieltiens opened this issue Mar 5, 2016 · 5 comments

Comments

@vincentdieltiens
Copy link

When I use the sendKeys method to test a homemade hotkey service, Some tests are failing with chrome for some keys like a or q.

The method sendKeys seems to send the wrong keycode :

  • for a it sends 81 (instead of 65)
  • for q it sends 65 (instead of 81)
  • for w it sends 90 (instead of 87)
  • ...

The keys for which there is a problem seems to be 'querty' and 'azerty'...
I provide below a very simple example that fails with chrome (and should not) and passes with firefox.

Note that i'm using a french version of chrome and firefox with an apple azerty keyboard.

Bug report

  • Node Version: v4.3.2
  • Protractor Version: 3.1.1
  • Browser(s): chrome 49.0.2623.75
  • Operating System and Version Mac OS X 10.11 El capitan
  • Your protractor configuration file
exports.config = {
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['src/listener.e2e.js'],
  baseUrl: 'http://localhost:3000/',
  multiCapabilities: [{
    'browserName': 'chrome'
  }, {
    'browserName': 'firefox'
  }]
};
  • A relevant example test
    Index.html :

    <!doctype html>
    <html>
        <head>
        </head>
        <body ng-app="protractor.test">
            <h2>Infos</h2>
        <example></example>
    
        <script type="text/javascript" src="../node_modules/angular/angular.js"></script>
        <script type="text/javascript" src="../src/listener.js"></script>
    </body>
    </html>

    listener.js :

    angular.module('protractor.test', [])
    .component('example', {
        'controllerAs': 'example',
        'templateUrl': 'example.html',
        controller: function() {
            document.querySelector('body').addEventListener('keydown', function(e) {
                document.querySelector('#keyCode').innerHTML = e.keyCode;
                document.querySelector('#which').innerHTML = e.which;
                document.querySelector('#charCode').innerHTML = e.charCode;
            });
        }
    });

    example.html :

    KeyCode: <span id="keyCode"></span><br />
    which: <span id="which"></span><br />
    charCode: <span id="charCode"></span>

    listener.e2e.js :

    describe('protractor test', function() {
        var inputElement;
    
        beforeEach(function() {
            browser.get('example/index.html');
        });
    
        it('should send 65 keyCode for "a"', function() {
            element(by.css('body')).sendKeys(
                '', 
                'a',
                ''
            );
    
            expect(element(by.css('#keyCode')).getText()).toEqual('65');
        });
    });
  • Output from running the test

    $ protractor protractor.e2e.conf.js  --troubleshoot
    DEBUG - Running with --troubleshoot
    DEBUG - Protractor version: 3.1.1
    DEBUG - Your base url for tests is http://localhost:3000/
    [launcher] Running 2 instances of WebDriver
    F
    ------------------------------------
    [chrome #1] PID: 21659
    [chrome #1] Specs: /Users/Vince/Documents/www/bo2-modules/protractor-test/src/listener.e2e.js
    [chrome #1]
    [chrome #1] Using the selenium server at http://localhost:4444/wd/hub
    [chrome #1] DEBUG - WebDriver session successfully started with capabilities { caps_:
    [chrome #1]    { applicationCacheEnabled: false,
    [chrome #1]      rotatable: false,
    [chrome #1]      mobileEmulationEnabled: false,
    [chrome #1]      chrome:
    [chrome #1]       { chromedriverVersion: '2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4)',
    [chrome #1]         userDataDir: '/var/folders/_3/zqn09vsj6zd4v1t_5004t3j80000gn/T/.org.chromium.Chromium.FkkGyV' },
    [chrome #1]      takesHeapSnapshot: true,
    [chrome #1]      databaseEnabled: false,
    [chrome #1]      handlesAlerts: true,
    [chrome #1]      hasTouchScreen: false,
    [chrome #1]      version: '49.0.2623.75',
    [chrome #1]      platform: 'MAC',
    [chrome #1]      browserConnectionEnabled: false,
    [chrome #1]      nativeEvents: true,
    [chrome #1]      acceptSslCerts: true,
    [chrome #1]      'webdriver.remote.sessionid': 'b6fd8a99-7a31-49e1-996f-883c48d41b27',
    [chrome #1]      locationContextEnabled: true,
    [chrome #1]      webStorageEnabled: true,
    [chrome #1]      browserName: 'chrome',
    [chrome #1]      takesScreenshot: true,
    [chrome #1]      javascriptEnabled: true,
    [chrome #1]      cssSelectorsEnabled: true } }
    [chrome #1] DEBUG - Running with spec files /Users/Vince/Documents/www/bo2-modules/protractor-test/src/listener.e2e.js
    [chrome #1] Started
    [chrome #1] F
    [chrome #1]
    [chrome #1] Failures:
    [chrome #1] 1) protractor test should send 65 keyCode for "a"
    [chrome #1]   Message:
    [chrome #1]     Expected '81' to equal '65'.
    [chrome #1]   Stack:
    [chrome #1]     Error: Failed expectation
    [chrome #1]         at Object.<anonymous> (/Users/Vince/Documents/www/bo2-modules/protractor-test/src/listener.e2e.js:15:49)
    [chrome #1]         at process._tickCallback (node.js:364:9)
    [chrome #1]
    [chrome #1] 1 spec, 1 failure
    [chrome #1] Finished in 0.801 seconds
    
    [launcher] 1 instance(s) of WebDriver still running
    .
    ------------------------------------
    [firefox #2] PID: 21660
    [firefox #2] Specs: /Users/Vince/Documents/www/bo2-modules/protractor-test/src/listener.e2e.js
    [firefox #2]
    [firefox #2] Using the selenium server at http://localhost:4444/wd/hub
    [firefox #2] DEBUG - WebDriver session successfully started with capabilities { caps_:
    [firefox #2]    { applicationCacheEnabled: true,
    [firefox #2]      rotatable: false,
    [firefox #2]      handlesAlerts: true,
    [firefox #2]      databaseEnabled: true,
    [firefox #2]      version: '44.0.2',
    [firefox #2]      platform: 'MAC',
    [firefox #2]      nativeEvents: false,
    [firefox #2]      acceptSslCerts: true,
    [firefox #2]      'webdriver.remote.sessionid': '143072e1-23a0-4454-99a1-868eab681f1d',
    [firefox #2]      webStorageEnabled: true,
    [firefox #2]      locationContextEnabled: true,
    [firefox #2]      browserName: 'firefox',
    [firefox #2]      takesScreenshot: true,
    [firefox #2]      javascriptEnabled: true,
    [firefox #2]      cssSelectorsEnabled: true } }
    [firefox #2] DEBUG - Running with spec files /Users/Vince/Documents/www/bo2-modules/protractor-test/src/listener.e2e.js
    [firefox #2] Started
    [firefox #2] .
    [firefox #2]
    [firefox #2]
    [firefox #2] 1 spec, 0 failures
    [firefox #2] Finished in 0.788 seconds
    
    [launcher] 0 instance(s) of WebDriver still running
    [launcher] chrome #1 failed 1 test(s)
    [launcher] firefox #2 passed
    [launcher] overall: 1 failed spec(s)
    [launcher] Process exited with error code 1
    
  • Steps to reproduce the bug

    • install protractor, selenium and angular 1.5.0
    • run the selenium server
    • execute the e2e test.

Thanks,
Vincent

@vincentdieltiens vincentdieltiens changed the title sendkeys send wrong keycodes to chrome sendkeys sends wrong keycodes to chrome Mar 5, 2016
@tullmann
Copy link
Contributor

tullmann commented Mar 6, 2016

The chromedriver project has had a bunch of weird bugs with keyboards (especially non-US ones). See https://bugs.chromium.org/p/chromedriver/issues/detail?id=627 (and search for sendKeys in their issue tracker). 627 is marked fixed, but there may still be issues.

You can enable chromedriver logger (see http://stackoverflow.com/questions/31662828/how-to-access-chromedriver-logs-for-protractor-test) to get more details about what keycodes are being sent.

@vincentdieltiens
Copy link
Author

After enabling chromedriver logger (with the solution (given by jmr) of running chromedriver in a separate process), here are the logs relatives to the key event :

[5.643][INFO]: COMMAND TypeElement {
   "id": "0.9101050850003958-1",
   "value": [ "", "a", "" ]
}
...
[5.677][DEBUG]: DEVTOOLS COMMAND Input.dispatchKeyEvent (id=47) {
   "modifiers": 0,
   "nativeVirtualKeyCode": 81,
   "text": "",
   "type": "rawKeyDown",
   "unmodifiedText": "",
   "windowsVirtualKeyCode": 81
}
[5.678][DEBUG]: DEVTOOLS RESPONSE Input.dispatchKeyEvent (id=47) {

}
[5.678][DEBUG]: DEVTOOLS COMMAND Input.dispatchKeyEvent (id=48) {
   "modifiers": 0,
   "nativeVirtualKeyCode": 0,
   "text": "a",
   "type": "char",
   "unmodifiedText": "a",
   "windowsVirtualKeyCode": 0
}
[5.678][DEBUG]: DEVTOOLS RESPONSE Input.dispatchKeyEvent (id=48) {

}
[5.678][DEBUG]: DEVTOOLS COMMAND Input.dispatchKeyEvent (id=49) {
   "modifiers": 0,
   "nativeVirtualKeyCode": 81,
   "text": "",
   "type": "keyUp",
   "unmodifiedText": "",
   "windowsVirtualKeyCode": 81
}
[5.678][DEBUG]: DEVTOOLS RESPONSE Input.dispatchKeyEvent (id=49) {

}

So, chromedriver seems to get "a" and translate it to the keyCode 81 which is incorrect...

@juliemr
Copy link
Member

juliemr commented Mar 7, 2016

Pretty sure this is a ChromeDriver issue. I don't see an open issue of theirs for dealing with this, so we should find the minimal test case and create an issue with them.

@juliemr
Copy link
Member

juliemr commented Jun 21, 2016

I can't reproduce w/o a custom keyboard - @vincentdieltiens could you please open an issue with chromedriver at https://bugs.chromium.org/p/chromedriver/issues/list? Thanks.

@juliemr juliemr changed the title sendkeys sends wrong keycodes to chrome sendkeys for Chrome has issues with non-English keyboards Jun 21, 2016
@juliemr
Copy link
Member

juliemr commented Sep 20, 2016

Closing this as stale and not helpful to keep open.

@juliemr juliemr closed this as completed Sep 20, 2016
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

3 participants