【问题标题】:CoreUi - why nightwatch cannot run e2e tests?CoreUi - 为什么 nightwatch 不能运行 e2e 测试?
【发布时间】:2021-05-13 12:55:00
【问题描述】:

我想开始使用 CoreUi Admin 模板并创建包含单元和 e2e 测试的项目。

一开始,我安装 CoreUi,如文档中所示:

git clone https://github.com/coreui/coreui-free-vue-admin-template.git CoreUI-Vue
cd CoreUI-Vue
npm install

一切正常。现在我想运行整个单元和 e2e 测试:

npm run test:unit   
npm run test:e2e

所有单元测试都运行正常。但是当我运行 e2e 测试时,我得到了以下错误:

> @coreui/coreui-free-vue-admin-template@3.1.4 test:e2e
> vue-cli-service test:e2e

 INFO  Starting development server...
[BABEL] Note: The code generator has deoptimised the styling of /home/bagsiur/Projects/B2B/test-coreui/CoreUI-Vue/node_modules/@coreui/vue/dist/coreui-vue.common.js as it exceeds the max of 500KB.


 WARNING  Compiled with 2 warnings                                                                                                                                                                       2:47:38 PM
 warning

asset size limit: The following asset(s) exceed the recommended size limit (244 KiB).
This can impact web performance.
Assets:
  css/app.10fee0d6.css (383 KiB)                                                                                                                                                                                     js/chunk-28d6db65.e7636129.js (488 KiB)
  js/chunk-2d0a400c.650c6f3a.js (3.37 MiB)                                                                                                                                                                           js/chunk-2d0ae5e6.22010046.js (390 KiB)
  js/chunk-2d237b34.468fc7b7.js (1.36 MiB)
  js/chunk-vendors.03b8fe62.js (687 KiB)

 warning

entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (244 KiB). This can impact web performance.
Entrypoints:
  app (1.07 MiB)
      js/chunk-vendors.03b8fe62.js
      css/app.10fee0d6.css
      js/app.94002fbe.js


                                                                                                                                                                                                                     App running at:
  - Local:   http://localhost:8080/
  - Network: http://172.31.33.121:8080/

  App is served in production mode.
  Note this is for preview or E2E testing only.

 INFO  Running end-to-end tests ...

[Test] Test Suite
=================
⚠ Error connecting to localhost on port 9515.
_________________________________________________
TEST FAILURE: 1 error during execution; 0 tests failed, 0 passed (348ms)

 ✖ test
   An error occurred while retrieving a new session: "unknown error: Chrome failed to start: exited abnormally."
Error: An error occurred while retrieving a new session: "unknown error: Chrome failed to start: exited abnormally."
    at endReadableNT (_stream_readable.js:1201:12)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)

  Error: An error occurred while retrieving a new session: "unknown error: Chrome failed to start: exited abnormally."                                                                                                    at endReadableNT (_stream_readable.js:1201:12)
       at processTicksAndRejections (internal/process/task_queues.js:84:21)

   SKIPPED:
   - CoreUI Vue e2e tests

 ERROR  Error: Command failed: /home/bagsiur/Projects/B2B/test-coreui/CoreUI-Vue/node_modules/nightwatch/bin/nightwatch --config /home/bagsiur/Projects/B2B/test-coreui/CoreUI-Vue/node_modules/@vue/cli-plugin-e2e-nightwatch/nightwatch.config.js --env chrome
Error: Command failed: /home/bagsiur/Projects/B2B/test-coreui/CoreUI-Vue/node_modules/nightwatch/bin/nightwatch --config /home/bagsiur/Projects/B2B/test-coreui/CoreUI-Vue/node_modules/@vue/cli-plugin-e2e-nightwatch/nightwatch.config.js --env chrome
    at makeError (/home/bagsiur/Projects/B2B/test-coreui/CoreUI-Vue/node_modules/execa/index.js:174:9)
    at /home/bagsiur/Projects/B2B/test-coreui/CoreUI-Vue/node_modules/execa/index.js:278:16
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
bagsiur@DESKTOP-718MBR1:~/Projects/B2B/test-coreui/CoreUI-Vue$
bagsiur@DESKTOP-718MBR1:~/Projects/B2B/test-coreui/CoreUI-Vue$ npm run test:e2e

> @coreui/coreui-free-vue-admin-template@3.1.4 test:e2e
> vue-cli-service test:e2e

 INFO  Starting development server...


 WARNING  Compiled with 2 warnings                                                                                                                                                                       3:06:39 PM
 warning

asset size limit: The following asset(s) exceed the recommended size limit (244 KiB).
This can impact web performance.
Assets:
  css/app.10fee0d6.css (383 KiB)
  js/chunk-28d6db65.e7636129.js (488 KiB)
  js/chunk-2d0a400c.650c6f3a.js (3.37 MiB)
  js/chunk-2d0ae5e6.22010046.js (390 KiB)
  js/chunk-2d237b34.468fc7b7.js (1.36 MiB)
  js/chunk-vendors.03b8fe62.js (687 KiB)

 warning
entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (244 KiB). This can impact web performance.
Entrypoints:
  app (1.07 MiB)
      js/chunk-vendors.03b8fe62.js
      css/app.10fee0d6.css
      js/app.94002fbe.js



  App running at:
  - Local:   http://localhost:8080/
  - Network: http://172.31.33.121:8080/

  App is served in production mode.
  Note this is for preview or E2E testing only.                                                                                                                                                                    
 INFO  Running end-to-end tests ...                                                                                                                                                                                
[Test] Test Suite
=================
⚠ Error connecting to localhost on port 9515.
_________________________________________________

TEST FAILURE: 1 error during execution; 0 tests failed, 0 passed (348ms)

 ✖ test
   An error occurred while retrieving a new session: "unknown error: Chrome failed to start: exited abnormally."
Error: An error occurred while retrieving a new session: "unknown error: Chrome failed to start: exited abnormally."
    at endReadableNT (_stream_readable.js:1201:12)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)

  Error: An error occurred while retrieving a new session: "unknown error: Chrome failed to start: exited abnormally."                                                                                                    at endReadableNT (_stream_readable.js:1201:12)
       at processTicksAndRejections (internal/process/task_queues.js:84:21)

   SKIPPED:
   - CoreUI Vue e2e tests

 ERROR  Error: Command failed: /home/bagsiur/Projects/B2B/test-coreui/CoreUI-Vue/node_modules/nightwatch/bin/nightwatch --config /home/bagsiur/Projects/B2B/test-coreui/CoreUI-Vue/node_modules/@vue/cli-plugin-e2e-nightwatch/nightwatch.config.js --env chrome
Error: Command failed: /home/bagsiur/Projects/B2B/test-coreui/CoreUI-Vue/node_modules/nightwatch/bin/nightwatch --config /home/bagsiur/Projects/B2B/test-coreui/CoreUI-Vue/node_modules/@vue/cli-plugin-e2e-nightwatch/nightwatch.config.js --env chrome
    at makeError (/home/bagsiur/Projects/B2B/test-coreui/CoreUI-Vue/node_modules/execa/index.js:174:9)
    at /home/bagsiur/Projects/B2B/test-coreui/CoreUI-Vue/node_modules/execa/index.js:278:16
    at processTicksAndRejections (internal/process/task_queues.js:97:5)

我在 wsl2 和 Debian 上工作。我的 node.js 版本是 v13.14.0,npm 是 7.12.1。我在版本中安装了 chromedriver:ChromeDriver 2.41.578700 (2f1ed5f9343c13f73144538f15c00b370eda6706) 和最后一个稳定的谷歌浏览器:google-chrome-stable 90.0.4430.212-1

我错过了什么?运行 e2e 测试时出错的原因可能在哪里?

@UPDATE:我把 Nightwatch.conf.json 的配置放到了:

// http://nightwatchjs.org/gettingstarted#settings-file

const path = require('path')
const deepmerge = require('deepmerge')
const chromedriver = require('chromedriver')

// user may have not installed geckodriver
let geckodriver = {}
try {
  geckodriver = require('geckodriver')
} catch (e) {}

const userOptions = JSON.parse(process.env.VUE_NIGHTWATCH_USER_OPTIONS || '{}')
const useSelenium = process.env.VUE_NIGHTWATCH_USE_SELENIUM === '1'
const startHeadless = process.env.VUE_NIGHTWATCH_HEADLESS === '1'
const concurrentMode = process.env.VUE_NIGHTWATCH_CONCURRENT === '1'
const chromeArgs = []
const geckoArgs = []

if (startHeadless) {
  chromeArgs.push('headless')
  geckoArgs.push('--headless')
}

const defaultSettings = {
  src_folders: ['tests/e2e/specs'],
  output_folder: 'tests/e2e/reports',
  page_objects_path: 'tests/e2e/page-objects',
  custom_assertions_path: 'tests/e2e/custom-assertions',
  custom_commands_path: 'tests/e2e/custom-commands',
  globals_path: path.resolve('tests/e2e/globals.js'),
  test_workers: concurrentMode,
  test_settings: {
    default: {
      detailed_output: !concurrentMode,
      launch_url: '${VUE_DEV_SERVER_URL}'
    },

    chrome: {
      desiredCapabilities: {
        browserName: 'chrome',
        chromeOptions: {
          w3c: false,
          args: chromeArgs
        }
      }
    },

    firefox: {
      desiredCapabilities: {
        browserName: 'firefox',
        alwaysMatch: {
          acceptInsecureCerts: true,
          'moz:firefoxOptions': {
            args: geckoArgs
          }
        }
      },
      webdriver: useSelenium ? {} : {
        server_path: geckodriver.path,
        port: 4444
      }
    }
  }
}

const baseSettings = deepmerge(defaultSettings, webdriverServerSettings())

module.exports = deepmerge(baseSettings, adaptUserSettings(userOptions))

function adaptUserSettings (settings) {
  // The path to nightwatch external globals file needs to be made absolute
  // if it is supplied in an additional config file, due to merging of config files
  if (settings.globals_path) {
    settings.globals_path = path.resolve(settings.globals_path)
  }

  return settings
}

function webdriverServerSettings () {
  if (useSelenium) {
    return {
      selenium: {
        start_process: true,
        host: '127.0.0.1',
        port: 4444,
        server_path: require('selenium-server').path,
        cli_args: {
          'webdriver.chrome.driver': chromedriver.path,
          'webdriver.gecko.driver': geckodriver.path
        }
      }
    }
  }

  return {
    webdriver: {
      start_process: true,
      port: 9515,
      server_path: chromedriver.path
    }
  }
}

【问题讨论】:

  • 你能发布你的 Nightwatch.conf.json 文件吗?
  • CoreUI 中没有 Nightwatch 的配置,所以我猜 Nightwatch 使用的是全局的。就我而言:/node_modules/@vue/cli-plugin-e2e-nightwatch/nightwatch.config.js。我发布了它的内容。

标签: vue.js nightwatch.js core-ui


【解决方案1】:

chromedriverchrome 的版本不匹配是 e2e 出现此类失败的最常见原因。

  • ChromeDriver 2.41 支持 Chrome v67-69
  • 您的 google-chrome-stable 90.0.4430 需要 ChromeDriver 90.0.4430

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-15
    • 1970-01-01
    • 1970-01-01
    • 2018-03-30
    • 2015-12-06
    • 1970-01-01
    相关资源
    最近更新 更多