nightwatchjs / nightwatch

Integrated end-to-end testing framework written in Node.js and using W3C Webdriver API. Developed at @browserstack
https://nightwatchjs.org
MIT License
11.79k stars 1.31k forks source link

Clicking after scrolling fails on Safari #2481

Closed posva closed 3 years ago

posva commented 4 years ago

Describe the bug

I found that using browser.click() on Safari right after using a block of execute or evaluate with some scrolling related code doesn't effectively run the following click

Sample test

sampleTest.js

```js module.exports = { /** @type {import('nightwatch').NightwatchTest} */ bug: function (browser) { const TIMEOUT = 3000 browser .url('https://router.vuejs.org/guide/essentials/nested-routes.html') .waitForElementPresent('#app > *', 1000) .execute(function () { window.scrollTo(0, 100) // works in Safari // document.querySelector('.sidebar-group-items li:nth-child(4) a').click() }) .click('.sidebar-group-items li:nth-child(4) a') .waitForElementPresent('#programmatic-navigation', TIMEOUT) }, } ```

Run with command

yarn nightwatch -e safari sampleTest.js

Verbose output

debug.log

```txt yarn run v1.22.4 $ /Users/posva/vue-router-next/node_modules/.bin/nightwatch -c e2e/sample.config.js e2e/specs/bug-report.js -e safari --verbose Starting Selenium Server on port 4444... Selenium Server up and running on port 4444 with pid: 60404 (517ms). [Bug Report] Test Suite =======================  Request POST /wd/hub/session  { desiredCapabilities: { browserName: 'safari', platform: 'ANY', acceptSslCerts: true, name: 'Bug Report' } }  Response 200 POST /wd/hub/session (816ms) { status: 0, sessionId: '448A366F-1485-4F26-81E5-4E4254E1E476', value: { 'safari:platformVersion': '10.15.4', 'safari:automaticInspection': false, 'webkit:WebRTC': { DisableICECandidateFiltering: false, DisableInsecureMediaCapture: false }, browserVersion: '13.1', strictFileInteractability: false, browserName: 'Safari', 'safari:useSimulator': false, 'safari:automaticProfiling': false, 'safari:platformBuildVersion': '19E287', acceptInsecureCerts: false, setWindowRect: true, platformName: 'macOS', 'safari:diagnose': false, 'webdriver.remote.sessionid': '448A366F-1485-4F26-81E5-4E4254E1E476' } } Using: Safari (13.1) on macOS platform. Received session with ID: 448A366F-1485-4F26-81E5-4E4254E1E476  → Running [before]: → Completed [before]. Running: bug → Running [beforeEach]: → Completed [beforeEach].  → Running command: url ('https://router.vuejs.org/guide/essentials/nested-routes.html')  Request POST /wd/hub/session/448A366F-1485-4F26-81E5-4E4254E1E476/url  { url: 'https://router.vuejs.org/guide/essentials/nested-routes.html' }  Response 200 POST /wd/hub/session/448A366F-1485-4F26-81E5-4E4254E1E476/url (240ms) { state: 'success', sessionId: null, value: null, status: 0 }  → Completed command: url ('https://router.vuejs.org/guide/essentials/nested-routes.html') (242ms)  → Running command: waitForElementPresent ('#app > *', 1000)  Request POST /wd/hub/session/448A366F-1485-4F26-81E5-4E4254E1E476/elements  { using: 'css selector', value: '#app > *' }  Response 200 POST /wd/hub/session/448A366F-1485-4F26-81E5-4E4254E1E476/elements (74ms) { state: 'success', sessionId: null, value: [ { 'element-6066-11e4-a52e-4f735466cecf': 'node-AE29BDD8-6456-4350-9A94-DF112EB6B104' } ], status: 0 } ✔ Element <#app > *> was present after 74 milliseconds.  → Completed command: waitForElementPresent ('#app > *', 1000) (76ms)  → Running command: execute ([Function])  Request POST /wd/hub/session/448A366F-1485-4F26-81E5-4E4254E1E476/execute  { script: 'var passedArgs = Array.prototype.slice.call(arguments,0); return function () {\n' + ' window.scrollTo(0, 100)\n' + ' // works in Safari\n' + " // document.querySelector('.sidebar-group-items li:nth-child(4) a').click()\n" + ' }.apply(window, passedArgs);', args: [] }  Response 200 POST /wd/hub/session/448A366F-1485-4F26-81E5-4E4254E1E476/execute (26ms) { state: 'success', sessionId: null, value: null, status: 0 }  → Completed command: execute ([Function]) (27ms)  → Running command: click ('.sidebar-group-items li:nth-child(4) a')  Request POST /wd/hub/session/448A366F-1485-4F26-81E5-4E4254E1E476/elements  { using: 'css selector', value: '.sidebar-group-items li:nth-child(4) a' }  Response 200 POST /wd/hub/session/448A366F-1485-4F26-81E5-4E4254E1E476/elements (6ms) { state: 'success', sessionId: null, value: [ { 'element-6066-11e4-a52e-4f735466cecf': 'node-63474816-D549-4D77-BBE4-81C84F4C1AC6' }, { 'element-6066-11e4-a52e-4f735466cecf': 'node-696EFACA-9B30-4FEB-BBA1-0F57E65A7AC1' } ], status: 0 }  Request POST /wd/hub/session/448A366F-1485-4F26-81E5-4E4254E1E476/element/node-63474816-D549-4D77-BBE4-81C84F4C1AC6/click  {}  Response 200 POST /wd/hub/session/448A366F-1485-4F26-81E5-4E4254E1E476/element/node-63474816-D549-4D77-BBE4-81C84F4C1AC6/click (68ms) { state: 'success', sessionId: null, value: null, status: 0 }  → Completed command: click ('.sidebar-group-items li:nth-child(4) a') (78ms)  → Running command: waitForElementPresent ('#programmatic-navigation', 3000)  Request POST /wd/hub/session/448A366F-1485-4F26-81E5-4E4254E1E476/elements  { using: 'css selector', value: '#programmatic-navigation' }  Response 200 POST /wd/hub/session/448A366F-1485-4F26-81E5-4E4254E1E476/elements (30ms) { state: 'success', sessionId: null, value: [], status: 0 }  Request POST /wd/hub/session/448A366F-1485-4F26-81E5-4E4254E1E476/elements  { using: 'css selector', value: '#programmatic-navigation' }  Response 200 POST /wd/hub/session/448A366F-1485-4F26-81E5-4E4254E1E476/elements (7ms) { state: 'success', sessionId: null, value: [], status: 0 }  Request POST /wd/hub/session/448A366F-1485-4F26-81E5-4E4254E1E476/elements  { using: 'css selector', value: '#programmatic-navigation' }  Response 200 POST /wd/hub/session/448A366F-1485-4F26-81E5-4E4254E1E476/elements (28ms) { state: 'success', sessionId: null, value: [], status: 0 }  Request POST /wd/hub/session/448A366F-1485-4F26-81E5-4E4254E1E476/elements  { using: 'css selector', value: '#programmatic-navigation' }  Response 200 POST /wd/hub/session/448A366F-1485-4F26-81E5-4E4254E1E476/elements (10ms) { state: 'success', sessionId: null, value: [], status: 0 }  Request POST /wd/hub/session/448A366F-1485-4F26-81E5-4E4254E1E476/elements  { using: 'css selector', value: '#programmatic-navigation' }  Response 200 POST /wd/hub/session/448A366F-1485-4F26-81E5-4E4254E1E476/elements (36ms) { state: 'success', sessionId: null, value: [], status: 0 }  Request POST /wd/hub/session/448A366F-1485-4F26-81E5-4E4254E1E476/elements  { using: 'css selector', value: '#programmatic-navigation' }  Response 200 POST /wd/hub/session/448A366F-1485-4F26-81E5-4E4254E1E476/elements (12ms) { state: 'success', sessionId: null, value: [], status: 0 }  Request POST /wd/hub/session/448A366F-1485-4F26-81E5-4E4254E1E476/elements  { using: 'css selector', value: '#programmatic-navigation' }  Response 200 POST /wd/hub/session/448A366F-1485-4F26-81E5-4E4254E1E476/elements (28ms) { state: 'success', sessionId: null, value: [], status: 0 } ✖ Timed out while waiting for element <#programmatic-navigation> to be present for 3000 milliseconds. - expected "found" but got: "not found" (3176ms)  at Object.bug (/Users/posva/vue-router-next/e2e/specs/bug-report.js:16:8) at processTicksAndRejections (internal/process/task_queues.js:97:5)  → Completed command: waitForElementPresent ('#programmatic-navigation', 3000) (3178ms) → Running [afterEach]: → Completed [afterEach]. FAILED: 1 assertions failed and 1 passed (3.603s) → Running [after]: → Completed [after].  → Running command: end ([Function]) Failures in "bug". Taking screenshot...  → Running command: saveScreenshot ('/Users/posva/vue-router-next/e2e/screenshots/bug-report/bug_FAILED_May-20-2020-183042-GMT+0200-(Central-European-Summer.png', [Function])  → Running command: screenshot (false, [Function])  Request GET /wd/hub/session/448A366F-1485-4F26-81E5-4E4254E1E476/screenshot   Response 200 GET /wd/hub/session/448A366F-1485-4F26-81E5-4E4254E1E476/screenshot (46ms) { state: 'success', sessionId: null, value: '', status: 0, suppressBase64Data: true }  → Completed command: screenshot (false, [Function]) (63ms)  → Completed command: saveScreenshot ('/Users/posva/vue-router-next/e2e/screenshots/bug-report/bug_FAILED_May-20-2020-183042-GMT+0200-(Central-European-Summer.png', [Function]) (68ms)  → Running command: session ('delete', [Function])  Request DELETE /wd/hub/session/448A366F-1485-4F26-81E5-4E4254E1E476   Response 200 DELETE /wd/hub/session/448A366F-1485-4F26-81E5-4E4254E1E476 (17ms) { state: 'success', sessionId: null, value: null, status: 0 }  → Completed command: end ([Function]) (92ms)  → Completed command: session ('delete', [Function]) (21ms) _________________________________________________ TEST FAILURE: 1 assertions failed, 1 passed (5.173s)  ✖ bug-report – bug (3.603s) Wrote report file to: e2e/reports/SAFARI_13.1__bug-report.xml. Wrote log file to: /Users/posva/vue-router-next/selenium-server.log. Selenium Server process closed. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command. ```

Configuration

nightwatch.json

The problem appears without adding any config and using the one generated ```js { /** @type {import('nightwatch').NightwatchTestSettingScreenshots} */ const browserDefaults = { selenium_port: 4444, selenium_host: 'localhost', silent: true, screenshots: { enabled: true, on_failure: true, on_error: false, path: 'e2e/screenshots', }, } /** @type {import('nightwatch').NightwatchOptions} */ module.exports = { src_folders: ['e2e/specs'], output_folder: 'e2e/reports', // set to true when testing on multiple browsers (-e chrome,firefox) to display tests as they pass instead of waiting for everything to be finished live_output: false, selenium: { start_process: true, start_session: true, host: '127.0.0.1', port: 4444, server_path: require('selenium-server').path, cli_args: { // 'webdriver.chrome.driver': require('chromedriver').path, // 'webdriver.gecko.driver': require('geckodriver').path, }, }, webdriver: { start_process: false, }, test_settings: { default: { launch_url: 'https://nightwatchjs.org', }, safari: { ...browserDefaults, desiredCapabilities: { browserName: 'safari', acceptSslCerts: true, }, }, }, } ```

Your Environment

Executable Version
nightwatch --version 1.3.5
npm --version VERSION
yarn --version 1.22.4
node --version v12.16.1
Browser driver Version
selenium-server 3.141.59
OS Version
macOS 10.15.4
stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had any recent activity. If possible, please retry using the latest Nightwatch version and update the issue with any relevant details. If no further activity occurs, it will be closed. Thank you for your contribution.