theintern / leadfoot

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

click() does not seem to work on Chrome in mobile emulation mode #156

Closed sylvaindubus closed 5 years ago

sylvaindubus commented 6 years ago

Using

Current behavior

When I use the click() method on an element, nothing happen while it works normally on desktop mode.

How to reproduce

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"></div>
    <button id="button">Click me</button>
    <script>
      document.querySelector('#button').addEventListener('click', function(e) {
        setTimeout(function() {
          document.querySelector('#app').innerHTML += '<div id="block" style="background: red; width: 200px; height: 200px;"></div>'
        }, 200)
      })
    </script>
  </body>
</html>

intern.json

{
  "functionalSuites": "test.js",
  "environments": [
    {
      "browserName": "chrome",
      "fixSessionCapabilities": "no-detect"
    },
    {
      "browserName": "chrome",
      "fixSessionCapabilities": "no-detect",
      "goog:chromeOptions": { "mobileEmulation": { "deviceName": "Pixel 2" } }
    }
  ],
  "tunnelOptions": {
    "drivers": [
      { "name": "chrome" }
    ]
  },
  "maxConcurrency": 1
}

test.js

const { registerSuite } = intern.getInterface('object')

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

  return {
    before() {
      remote = this.remote.get('index.html').setFindTimeout(1000)
      remote.session.capabilities.touchEnabled = true
    },
    tests: {
      'can click on the button and see the new block': () => (
        remote
          .findByCssSelector('#button')
            .click()
            .end()
          .findByCssSelector('#block')
          .sleep(1000)
      )
    }
  }
})

Results

✓ chrome 67.0.3396.99 on Mac OS X - User - can click on the button and see the new block (1.509s)
No unit test coverage for chrome 67.0.3396.99 on Mac OS X
chrome 67.0.3396.99 on Mac OS X: 1 passed, 0 failed

‣ Created remote session chrome 67.0.3396.99 on Mac OS X (e558eabcf86096c7791c6e49f934c320)
× chrome 67.0.3396.99 on Mac OS X - User - can click on the button and see the new block (1.277s)
    NoSuchElement: [POST http://localhost:4444/wd/hub/session/e558eabcf86096c7791c6e49f934c320/element / {"using":"css selector","value":"#block"}] no such element: Unable to locate element: {"method":"css selector","selector":"#block"}
      (Session info: chrome=67.0.3396.99)
      (Driver info: chromedriver=2.39.562713 (dd642283e958a93ebf6891600db055f1f1b4f3b2),platform=Mac OS X 10.13.5 x86_64)
jason0x43 commented 5 years ago

This issue appears to be resolved by using a more recent version of Chrome.