javascript - 我可以在 CircleCI 上使用 Nightwatch.js 运行 E2E 测试吗?

标签 javascript selenium nightwatch.js circleci

我正在开发网站并希望在 CircleCI 上自动运行测试。

我编写了配置文件和js文件进行测试,并在本地机器上运行E2E测试。有用。

然后,我编写了circleci.yml并在CircleCI上构建了项目。这不起作用。

错误日志

$ npm run test

> <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="eb989f8a9f8288b49c8e89b498829f8eabdbc5dbc5db" rel="noreferrer noopener nofollow">[email protected]</a> test /home/ubuntu/static_web_site
> nightwatch

Starting selenium server... started - PID:  17970

[Test] Test Suite
=====================

Running:  Demo test Google

Error retrieving a new session from the selenium server

Connection refused! Is selenium server started?
{ state: 'session not created',
  sessionId: null,
  hCode: 537979030,
  value: 
   { additionalInformation: '\nDriver info: driver.version: ChromeDriver',
     localizedMessage: 'session not created exception: Chrome version must be >= 58.0.3029.0\n  (Driver info: chromedriver=2.30.477691 (6ee44a7247c639c0703f291d320bdf05c1531b57),platform=Linux 3.13.0-119-generic x86_64) (WARNING: The server did not provide any stacktrace information)\nCommand duration or timeout: 746 milliseconds\nBuild info: version: \'3.4.0\', revision: \'unknown\', time: \'unknown\'\nSystem info: host: \'box2107\', ip: \'127.0.0.1\', os.name: \'Linux\', os.arch: \'amd64\', os.version: \'3.13.0-119-generic\', java.version: \'1.8.0_102\'\nDriver info: driver.version: ChromeDriver',
     systemInformation: 'System info: host: \'box2107\', ip: \'127.0.0.1\', os.name: \'Linux\', os.arch: \'amd64\', os.version: \'3.13.0-119-generic\', java.version: \'1.8.0_102\'',
     supportUrl: null,
     cause: null,
     suppressed: [],
     message: 'session not created exception: Chrome version must be >= 58.0.3029.0\n  (Driver info: chromedriver=2.30.477691 (6ee44a7247c639c0703f291d320bdf05c1531b57),platform=Linux 3.13.0-119-generic x86_64) (WARNING: The server did not provide any stacktrace information)\nCommand duration or timeout: 746 milliseconds\nBuild info: version: \'3.4.0\', revision: \'unknown\', time: \'unknown\'\nSystem info: host: \'box2107\', ip: \'127.0.0.1\', os.name: \'Linux\', os.arch: \'amd64\', os.version: \'3.13.0-119-generic\', java.version: \'1.8.0_102\'\nDriver info: driver.version: ChromeDriver',
     hCode: 60610566,
     class: 'org.openqa.selenium.SessionNotCreatedException',
     buildInformation: 
      { buildRevision: 'unknown',
        buildTime: 'unknown',
        releaseLabel: '3.4.0',
        hCode: 163722713,
        class: 'org.openqa.selenium.internal.BuildInfo' },
     screen: null },
  class: 'org.openqa.selenium.remote.Response',
  status: 33 }

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="becdcadfcad7dde1c9dbdce1cdd7cadbfe8e908e908e" rel="noreferrer noopener nofollow">[email protected]</a> test: `nightwatch`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="abd8dfcadfc2c8f4dccec9f4d8c2dfceeb9b859b859b" rel="noreferrer noopener nofollow">[email protected]</a> test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/ubuntu/.npm/_logs/2017-06-30T02_34_01_711Z-debug.log

npm run test returned exit code 1

package.json

{
  "name": "static_web_site",
  "version": "0.0.0",
  "description": "",
  "scripts": {
    "build": "rimraf dist && webpack",
    "start": "webpack-dev-server -d --colors --inline --hot --port 4000 --host 0.0.0.0",
    "test": "nightwatch",
    "lint": "sass-lint -v -q && pug-lint app/**/*.pug"
  },
  "keywords": [],
  "author": "Allajah",
  "license": "MIT",
  "devDependencies": {
    "babel-core": "^6.23.1",
    "babel-loader": "^7.0.0",
    "babel-plugin-add-module-exports": "^0.2.1",
    "babel-polyfill": "^6.23.0",
    "babel-preset-es2015": "^6.22.0",
    "babel-register": "^6.24.1",
    "chromedriver": "^2.30.1",
    "copy-webpack-plugin": "^4.0.1",
    "css-loader": "^0.28.0",
    "extract-text-webpack-plugin": "^2.1.1",
    "file-loader": "^0.10.1",
    "html-webpack-plugin": "^2.28.0",
    "nightwatch": "^0.9.16",
    "node-sass": "^4.5.0",
    "normalize.css": "^6.0.0",
    "postcss-loader": "^2.0.6",
    "pug": "^2.0.0-beta.12",
    "pug-lint": "^2.4.0",
    "pug-loader": "^2.3.0",
    "rimraf": "^2.6.1",
    "sass-lint": "^1.10.2",
    "sass-loader": "^6.0.2",
    "selenium-server-standalone-jar": "=3.4.0",
    "style-loader": "^0.13.2",
    "webpack": "^2.6.1",
    "webpack-dev-server": "^2.4.1"
  }
}

nightwatch.json

{
  "src_folders": ["test/e2e/"],
  "output_folder": "test/reports/",
  "custom_commands_path": "",
  "custom_assertions_path": "",
  "page_objects_path": "",
  "globals_path": "node_modules/babel-register",
  "selenium": {
    "start_process": true,
    "server_path": "node_modules/selenium-server-standalone-jar/jar/selenium-server-standalone-3.4.0.jar",
    "log_path": "test/logs",
    "host": "127.0.0.1",
    "port": 4444,
    "cli_args": {
      "webdriver.chrome.driver": "node_modules/.bin/chromedriver"
    }
  },
  "test_settings": {
    "default": {
      "launch_url": "http://localhost",
      "selenium_port": 4444,
      "selenium_host": "localhost",
      "silent": true,
      "screenshots": {
        "enabled": true,
        "on_failure": true,
        "on_error": false,
        "path": "test/screenshots"
      },
      "desiredCapabilities": {
        "browserName": "chrome",
        "javascriptEnabled": true,
        "acceptSslCerts": true
      },
      "globals": {
        "baseUrl": "http://localhost:4000",
        "waitTime": 10000
      },
      "use_xpath": false
    }
  }
}

test/e2e/test.js

module.exports = {
    tag: 'nightwatch test',
    'test': (client) => {
        client.url('http://www.google.com').waitForElementVisible('body', 1000).assert.title('Google').assert.visible('input[type=text]').end()
    }
}

circle.yml

machine:
  node:
    version: 7.4.0
environment:
  PATH: "${PATH}:${HOME}/${CIRCLE_PROJECT_REPONAME}/node_modules/.bin"
dependencies:
  pre:
    - npm i -g npm
test:
  override:
    - npm run build
    - npm run start:
        background: true
    - sleep 10
    - npm run test

我编写这些脚本时引用了 https://github.com/beatfactor/nightwatch-circleci 。 我 fork 了它并尝试在 CircleCI 上运行测试,但它不起作用。

有人可以帮我在 CircleCI 上使用 Nightwatch.js 运行 E2E 测试吗?

谢谢:)

最佳答案

您只需在 CircleCI 上更新 Chrome。

来自 Selenium 的错误表明它预计 Chrome 至少为版本 58。 default Ubuntu images使用较旧(或更旧)版本的 Chrome。

要解决此问题,请在安装依赖项时将以下步骤添加到circle.yml 中:

wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
sudo apt-get update
sudo apt-get --fix-broken --only-upgrade install google-chrome-stable

关于javascript - 我可以在 CircleCI 上使用 Nightwatch.js 运行 E2E 测试吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44839920/

相关文章:

node.js - E/启动器 - 进程已退出,错误代码为 135

python - 通过 id、类名等以外的方式查找元素

python - 使用 PhantomJS 的 Selenium 内存使用失控

javascript - Nightwatch.js 无法循环运行浏览器

javascript - 如何对必填字段消息进行断言?

javascript - 如何获取未选中单选按钮旁边的输入文本值?

javascript - TradingView图表时间订单违规错误

node.js - nightwatch.js 无法在 headless 模式下运行 chrome

javascript - 如何获得没有背景的元素颜色?

javascript 常量和 Opera 浏览器