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.83k stars 1.32k forks source link

Nigthwatch hangs at ENOTFOUND when launched with 2 browsers #2299

Closed Pieras2 closed 4 years ago

Pieras2 commented 4 years ago

Describe the bug

If NW is started with 2 browsers (--env chrome,firefox) it hangs when custom command fetches URL for JSON file if net::ERR_NAME_NOT_RESOLVED encounters.

If NW is started with one browser only (e.g. --env chrome) the NW goes back to command prompt at fail but doesn't close browser > after hook with browser.end() doesn't help.

If server where JSON is typically served is working all is fine.

Test folder contains ~8 tests, each test file calls this command for getting JSON, if we remove this command call from all test files except one, then no hangup happens even if 2 browser are used simultaneously.

Sample test

sampleTest.js

```js // custom command var util = require('util'); var events = require('events'); var fetch = require('node-fetch'); function getJSON() { } util.inherits(getJSON, events.EventEmitter); getJSON.prototype.command = function (apiUrl, success) { this.client.api.execute( function () { return window.sessionStorage.getItem('access_token'); }, [], item => { let headers = { 'Content-Type': 'application/json' }; if (item.value !== null) { headers['Authorization'] = `Bearer ${item.value}`; } fetch(apiUrl, { method: 'GET', headers }) .then(res => res.text()) .then(res => JSON.parse(res.trim())) .then(response => { success(response); this.emit('complete'); }) .catch(err => { this.emit('complete'); throw err; }); } ); }; module.exports = getJSON; // part of test var login = require('./login.js') let collapseSection module.exports = { 'LogIn': login.LogIn, 'Get BackEnd JSON data': login['Get BackEnd JSON data'], // <---- **hangs here** 'Check if Collapse button is displayed with correct screen size': function (browser) { headerPageObject = browser.page.headerPage() collapseSection = headerPageObject.section.COLLAPSE_BUTTON browser .setWindowSize(1920, 1080) .verify.not.visible(collapseSection.selector) .setWindowSize(575, 1080) .verify.visible(collapseSection.selector) }, 'Check if Collapse button opens menu with correct Items': function (browser) { let topBarCollapseSelector = collapseSection.elements.TOP_BAR_COLLAPSE browser.click(collapseSection.selector) browser.verify.visible(topBarCollapseSelector) for (element in headerPageObject.section) { if (headerPageObject.section[element].props.presentOnPage) { if (headerPageObject.section[element].props.presentOnCollapse) { browser.verify.visible(headerPageObject.section[element].selector) } } } } ```

Run with command

npm run nightwatch -- tests/nightwatch/tests/ --env firefox,chrome --url https://<my_url>

Verbose output

debug.log

``` Starting GeckoDriver on port 4444... Starting ChromeDriver on port 9515... GeckoDriver up and running on port 4444 with pid: 32092 (134ms). ChromeDriver up and running on port 9515 with pid: 20056 (126ms). Started child process for: firefox environment Started child process for: chrome environment ... ... ... → Running command: end ([Function]) chrome Failures in "Get BackEnd JSON data". Taking screenshot... chrome → Running [afterEach]: chrome → Completed [afterEach]. chrome × chrome [Collapse Button Test] Get BackEnd JSON data (1.107s) chrome FetchError: request to https:// failed, reason: getaddrinfo ENOTFOUND :443 chrome at TLSSocket.socketErrorListener (_http_client.js:392:9) chrome at emitErrorNT (internal/streams/destroy.js:91:8) chrome at emitErrorAndCloseNT (internal/streams/destroy.js:59:3) chrome at process._tickCallback (internal/process/next_tick.js:63:19) chrome → Running [after]: ... ... ... TEST FAILURE: 2 errors during execution; 0 assertions failed, 14 passed (20.835s) × collapseButtonTest – Get BackEnd JSON data (1.107s) FetchError: request to https:// failed, reason: getaddrinfo ENOTFOUND :443 at TLSSocket.socketErrorListener (_http_client.js:392:9) at emitErrorNT (internal/streams/destroy.js:91:8) at emitErrorAndCloseNT (internal/streams/destroy.js:59:3) at process._tickCallback (internal/process/next_tick.js:63:19) SKIPPED: - Check if Collapse button is displayed with correct screen size - Check if Collapse button opens menu with correct Items - Check if Collapse button is dissmissed after screen goes back to fullscreen ```

Configuration

nightwatch.json

```js { // Autogenerated by Nightwatch // Refer to the online docs for more details: https://nightwatchjs.org/gettingstarted/configuration/ const Services = {}; loadServices(); module.exports = { // An array of folders (excluding subfolders) where your tests are located; // if this is not specified, the test source must be passed as the second argument to the test runner. //src_folders: ['./tests'], // See https://nightwatchjs.org/guide/working-with-page-objects/ page_objects_path: './tests/nightwatch/pages', // See https://nightwatchjs.org/guide/extending-nightwatch/#writing-custom-commands custom_commands_path: './node_modules/@qc/nightwatch/commands', // See https://nightwatchjs.org/guide/extending-nightwatch/#writing-custom-assertions custom_assertions_path: '', // See https://nightwatchjs.org/guide/#external-globals globals_path: './globals/globalsModule.js', webdriver: { start_process: true }, test_settings: { firefox: { screenshots: { enabled: true, path: 'screens', on_failure: true }, desiredCapabilities: { browserName: 'firefox', alwaysMatch: { // Enable this if you encounter unexpected SSL certificate errors in Firefox // acceptInsecureCerts: true, 'moz:firefoxOptions': { args: [ //'-headless', // '-verbose' ] } } }, webdriver: { port: 4444, server_path: Services.geckodriver ? Services.geckodriver.path : '', cli_args: [ // very verbose geckodriver logs // '-vv' ] } }, firefox_cli: { screenshots: { enabled: true, path: 'screens', on_failure: true }, desiredCapabilities: { browserName: 'firefox', alwaysMatch: { // Enable this if you encounter unexpected SSL certificate errors in Firefox // acceptInsecureCerts: true, 'moz:firefoxOptions': { args: [ '-headless', // '-verbose' ] } } }, webdriver: { port: 4444, server_path: Services.geckodriver ? Services.geckodriver.path : '', cli_args: [ // very verbose geckodriver logs // '-vv' ] } }, chrome: { screenshots: { enabled: true, path: 'screens', on_failure: true }, desiredCapabilities: { browserName: 'chrome', chromeOptions: { // This tells Chromedriver to run using the legacy JSONWire protocol (not required in Chrome 78) // w3c: false, // More info on Chromedriver: https://sites.google.com/a/chromium.org/chromedriver/ args: [ //'--no-sandbox', //'--ignore-certificate-errors', //'--allow-insecure-localhost', //'--headless' ] } }, webdriver: { port: 9515, server_path: Services.chromedriver ? Services.chromedriver.path : '', cli_args: [ // --verbose ] } }, chrome_cli: { screenshots: { enabled: true, path: 'screens', on_failure: true }, desiredCapabilities: { browserName: 'chrome', chromeOptions: { // This tells Chromedriver to run using the legacy JSONWire protocol (not required in Chrome 78) // w3c: false, // More info on Chromedriver: https://sites.google.com/a/chromium.org/chromedriver/ args: [ //'--no-sandbox', //'--ignore-certificate-errors', //'--allow-insecure-localhost', '--headless' ] } }, webdriver: { port: 9515, server_path: Services.chromedriver ? Services.chromedriver.path : '', cli_args: [ // --verbose ] } }, ////////////////////////////////////////////////////////////////////////////////// // Configuration for when using the browserstack.com cloud service | // | // Please set the username and access key by setting the environment variables: | // - BROWSERSTACK_USER | // - BROWSERSTACK_KEY | // .env files are supported | ////////////////////////////////////////////////////////////////////////////////// browserstack: { selenium: { host: 'hub-cloud.browserstack.com', port: 443 }, // More info on configuring capabilities can be found on: // https://www.browserstack.com/automate/capabilities?tag=selenium-4 desiredCapabilities: { 'bstack:options': { local: 'false', userName: '${BROWSERSTACK_USER}', accessKey: '${BROWSERSTACK_KEY}' } }, disable_error_log: true, webdriver: { keep_alive: true, start_process: false } }, 'browserstack.chrome': { extends: 'browserstack', desiredCapabilities: { browserName: 'chrome', chromeOptions: { // This tells Chromedriver to run using the legacy JSONWire protocol // More info on Chromedriver: https://sites.google.com/a/chromium.org/chromedriver/ w3c: false } } }, 'browserstack.firefox': { extends: 'browserstack', desiredCapabilities: { browserName: 'firefox' } }, 'browserstack.ie': { extends: 'browserstack', desiredCapabilities: { browserName: 'IE', browserVersion: '11.0', 'bstack:options': { os: 'Windows', osVersion: '10', local: 'false', seleniumVersion: '3.5.2', resolution: '1366x768' } } }, ////////////////////////////////////////////////////////////////////////////////// // Configuration for when using the Selenium service, either locally or remote, | // like Selenium Grid | ////////////////////////////////////////////////////////////////////////////////// selenium: { // Selenium Server is running locally and is managed by Nightwatch selenium: { start_process: true, port: 4444, server_path: Services.seleniumServer ? Services.seleniumServer.path : '', cli_args: { 'webdriver.gecko.driver': Services.geckodriver ? Services.geckodriver.path : '', 'webdriver.chrome.driver': Services.chromedriver ? Services.chromedriver.path : '' } } }, 'selenium.chrome': { extends: 'selenium', desiredCapabilities: { browserName: 'chrome', chromeOptions: { w3c: false } } }, 'selenium.firefox': { extends: 'selenium', desiredCapabilities: { browserName: 'firefox', 'moz:firefoxOptions': { args: [ // '-headless', // '-verbose' ] } } } } }; function loadServices() { try { Services.seleniumServer = require('selenium-server'); } catch (err) { } try { Services.chromedriver = require('chromedriver'); } catch (err) { } try { Services.geckodriver = require('geckodriver'); } catch (err) { } } } ```

Your Environment

Executable Version
nightwatch --version 1.3.2
npm --version 6.3.14
node --version 10.18.0
Browser driver Version
NAME VERSION
chromedriver 78
geckodriver v0.26.0

System:

stale[bot] commented 4 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.