theintern / leadfoot

A JavaScript client library that brings cross-platform consistency to the Selenium WebDriver API.
Other
170 stars 24 forks source link

pressKeys() method doesn't seem to work on Firefox #154

Closed sylvaindubus closed 5 years ago

sylvaindubus commented 6 years ago

Using

Current behavior

When using pressKeys on an element, I got this message :

× firefox on darwin 17.6.0 - User - can press keys (0.448s)
    UnknownCommand: [POST http://localhost:4444/wd/hub/session/68f06f64-ba7d-d24e-9d4a-a6cbbb013bf5/keys / {"value":[""]}] sendKeysToActiveElement
    Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T15:15:08.936Z'

How to reproduce

In this example, I'm trying to catch the keycode and display it in the div. Note that I got the same error when I simply try to send keys as string in a input element. This works great on Chrome and Safari.

index.html

<!DOCTYPE html>
<html lang="fr">
  <head>
    <meta charset="UTF-8">
    <title>Coucou</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  </head>
  <body>
    <div id="app" tabindex="1" style="border: 1px solid red; padding: 10px; width: 200px; height: 600px;"></div>
    <script>
      document.querySelector('#app').addEventListener('keydown', function(e) {
        var keycode = e.keyCode ? e.keyCode : e.which
        this.innerHTML += keycode + '<br/>'
      })
    </script>
  </body>
</html>

intern.json

{
  "functionalSuites": "test.js",
  "environments": [
    {
      "browserName": "chrome",
      "fixSessionCapabilities": "no-detect"
    },
    {
      "browserName": "firefox",
      "fixSessionCapabilities": "no-detect"
    }
  ],
  "tunnelOptions": {
    "drivers": [
      { "name": "chrome" },
      { "name": "firefox" }
    ]
  },
  "maxConcurrency": 1
}

test.js

const { registerSuite } = intern.getInterface('object');
const keys = require('@theintern/leadfoot/keys').default;

registerSuite('User', () => {
  let remote

  return {
    before() {
      remote = this.remote.get('index.html')
      remote.session.capabilities.supportsKeysCommand = true
    },
    tests: {
      'can press keys': () => (
        remote
          .findByCssSelector('#app')
          .click()
          .pressKeys(keys.ARROW_RIGHT)
          .sleep(3000)
      )
    }
  }
})
jason0x43 commented 5 years ago

This issue appears to be resolved with more recent versions of Firefox (tested with Intern 4.2.2, FF 67, geckodriver 0.24.0)