vsts托管代理docker容器(ubuntu)-无法运行nightwatch测试(连接到127.0.0.1端口4444时出错)

问题描述 投票:0回答:1

我正试图在 azure 管道中运行 selenium 测试并运行到错误CICD 管道使用 VSTS 托管代理并构建 Ubuntu docker 容器。

我的测试任务在Docker容器镜像构建后运行,并抛出以下错误。不知道我错过了什么。

在我的windows机器上测试工作正常。

如果需要任何进一步的信息,请告诉我。

有什么好的nightwatch docker项目,请把它扔到这里。

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 > [email protected] 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 }

包.json.conf.js

{
  "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,
      }
    }
  }
};
node.js docker selenium azure-devops nightwatch.js
1个回答
0
投票

我自己找到了解决这个问题的方法。对于人们谁曾经尝试同样的。

请确保在Docker Ubuntu中安装了正确的二进制文件。

  1. 包.json chrome devdependancy将.exe二进制文件拉到Docker ubuntu中(看起来像是chrome驱动npm包的问题)。

  2. 确保在Docker Ubuntu上也安装了稳定的linux chrome。

  3. 试着先在本地Docker容器上设置项目,然后进入docker容器中调试它(基本上是用bash进入Docker容器并尝试在那里运行测试)。如果测试在那里正常运行,很可能在管道中也能正确运行。

我打算很快写一个端到端的设置博客。一旦完成,我将在这里更新。

© www.soinside.com 2019 - 2024. All rights reserved.