简体   繁体   中英

vsts hosted agent docker container (ubuntu) - unable to run nightwatch tests (Error connecting to 127.0.0.1 on port 4444

I am trying to run selenium tests in azure pipeline and running into errors The CICD pipeline is using VSTS hosted agent and building a Ubuntu docker container.

My test tasks are running after the Docker container image build and throwing out the below error. Not sure what I am missing out.

Tests work find on my windows machine.

Please let me know if any further information is needed

any good nightwatch docker project out there pls throw it here.

2020-04-22T10:53:24.0632804Z - Connecting to 127.0.0.1 on port 4444...
2020-04-22T10:53:24.0633097Z 
2020-04-22T10:53:24.0633309Z    Response 500 POST /wd/hub/session (20137ms)
2020-04-22T10:53:24.0633973Z ⚠ Error connecting to 127.0.0.1 on port 4444.
2020-04-22T10:53:24.0634476Z   Error: An error occurred while retrieving a new session: "Timed out waiting for driver server to start."
2020-04-22T10:53:24.0635002Z        at endReadableNT (_stream_readable.js:1187:12)
2020-04-22T10:53:24.0635520Z        at processTicksAndRejections (internal/process/task_queues.js:84:21)
2020-04-22T10:53:24.0636178Z  Cannot write log file to /vsts/agent/_work/r2/a/_QA_IDLookUp/output/logs/selenium-server.log.
2020-04-22T10:53:24.0636541Z npm ERR! Test failed.  See above for more details.
2020-04-22T10:53:24.0637274Z 
2020-04-22T10:53:24.0638871Z > qa-idlookup@1.0.0 test /vsts/agent/_work/r2/a/_QA_IDLookUp
2020-04-22T10:53:24.0639529Z > nightwatch -e headlessChrome
2020-04-22T10:53:24.0639818Z 
2020-04-22T10:53:24.0639982Z 
2020-04-22T10:53:24.0640105Z 
2020-04-22T10:53:24.0640412Z [Specs/Inquire Driver] Test Suite
2020-04-22T10:53:24.0640807Z =================================
2020-04-22T10:53:24.0641034Z    {
2020-04-22T10:53:24.0641217Z      value: {
2020-04-22T10:53:24.0641411Z        error: [
2020-04-22T10:53:24.0642113Z          "Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'",
2020-04-22T10:53:24.0643143Z          "System info: host: '15e4d52e2df2', ip: '172.17.0.2', os.name: 'Linux', os.arch: 'amd64', os.version: '5.0.0-1031-azure', java.version: '1.8.0_241'",
2020-04-22T10:53:24.0644010Z          'Driver info: driver.version: unknown'
2020-04-22T10:53:24.0644276Z        ],
2020-04-22T10:53:24.0645537Z        message: 'Timed out waiting for driver server to start.'
2020-04-22T10:53:24.0645906Z      },
2020-04-22T10:53:24.0646113Z      status: 13
2020-04-22T10:53:24.0646394Z }

package.json:

{
  "name": "qa-idlookup",
  "version": "1.0.0",
  "description": "NightwatchJS with Selenium Server",
  "main": "index.js",
  "scripts": {
    "test": "nightwatch -e headlessChrome",
    "headless": "nightwatch -e headlessChrome",
    "chrome": "nightwatch -e chrome",
    "firefox": "nightwatch -e firefox",
    "edge": "nightwatch -e edge",
    "ie": "nightwatch -e ie",
    "all": "nightwatch -e headlessChrome,chrome,firefox,edge,ie",
    "update": "npx npm-check-updates -u && npm install"
  },
  "keywords": [
    "Nightwatch",
    "NightwatchJS",
    "Selenium"
  ],
  "author": "Raju",
  "license": "ISC",
  "devDependencies": {
    "chromedriver": "80.0.2",
    "easy-soap-request": "^3.2.2",
    "edgedriver": "^4.17134.1",
    "geckodriver": "^1.19.1",
    "iedriver": "^3.14.2",
    "nightwatch": "^1.3.4",
    "selenium-server": "^3.141.59",
    "xmldom": "^0.3.0"
  }
}

nightwatch.conf.js

const seleniumServer = require('selenium-server');
const chromeDriver = require('chromedriver');
const geckoDriver = require('geckodriver');
const ieDriver = require('iedriver');
const edgeDriver = require('edgedriver');

module.exports = {
  src_folders: ['src'],
  output_folder: 'output/reports',
  custom_commands_path: '',
  custom_assertions_path: '',
  page_objects_path: '',
  globals_path: '',
  live_output: false,
  disable_colors: false,
  parallel_process_delay: 10,
  "test_workers": {
    "enabled": false,
    "workers": "auto"
  },
  selenium: {
    start_process: true,
    start_session: false,
    server_path: seleniumServer.path,
    check_process_delay: 5000,
    log_path: 'output/logs',
    host: '127.0.0.1',
    port: 4444,
    cli_args: {
      "webdriver.chrome.driver": chromeDriver.path,
      "webdriver.gecko.driver": geckoDriver.path,
      "webdriver.ie.driver": ieDriver.path,
      "webdriver.edge.driver": edgeDriver.path
    }
  },
  test_settings: {
    skip_testcases_on_fail: false,
    end_session_on_fail: false,
    default: {
      "request_timeout_options": {
        "timeout": 10000
      },
      "screenshots": {
        "enabled": true,
        "on_failure": true,
        "on_error": false,
        "path": "output/screenshots"
      },
      desiredCapabilities: {
        browserName: 'chrome',
      }
    },
    headlessChrome: {
      desiredCapabilities: {
        browserName: 'chrome',
        javascriptEnabled: true,
        acceptSslCerts: true,
        chromeOptions: {
          w3c: false,
          args: ['headless', 'disable-gpu']
        }
      }
    },
    chrome: {
      desiredCapabilities: {
        browserName: 'chrome',
        javascriptEnabled: true,
        acceptSslCerts: true,
        chromeOptions: {
          w3c: false,
          args: ['disable-gpu']
        }
      }
    },
    firefox: {
      desiredCapabilities: {
        browserName: 'firefox',
        javascriptEnabled: true,
        acceptSslCerts: true,
        marionette: true
      }
    },
    edge: {
      desiredCapabilities: {
        browserName: 'MicrosoftEdge',
        javascriptEnabled: true,
      }
    },
    ie: {
      desiredCapabilities: {
        browserName: 'internet explorer',
        javascriptEnabled: true,
      }
    }
  }
};

Found a solution myself for this issue. For people who ever are trying the same,

please make sure that the right binaries are installed in the Docker Ubuntu

  1. The package.json chrome devdependancy is pulling.exe binary into the Docker ubuntu (looks like its an issue with chrome driver npm package)

  2. Make sure that stable linux chrome also is installed on the Docker Ubuntu

  3. Try to setup the project on a local Docker container first and get inside the docker container to debug it (Basically bash into the Docker container and try to run the tests there). If the tests run properly there most probably they should run correctly in the pipeline

I am planning to write an end to end setup blog soon. I will update here once it is done.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM