微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

CoreUi - 为什么 nightwatch 不能运行 e2e 测试?

如何解决CoreUi - 为什么 nightwatch 不能运行 e2e 测试?

我想开始使用 CoreUi 管理模板并创建包含单元和 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
    }
  }
}

解决方法

chromedriverchrome 的版本不匹配是 e2e 像这样失败的最常见原因。

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。