vue-unit-e2e-test 发表于 2017-05-13 | 分类于 js vue vue测试模块 vue-cli生成项目有unit和E2E测试模块. 以及项目构建的脚手架 测试脚本123456"scripts": { "unit": "cross-env BABEL_ENV=test karma start test/unit/karma.conf.js --single-run", "e2e": "node test/e2e/runner.js", "test": "npm run unit && npm run e2e", "lint": "eslint --ext .js,.vue src test/unit/specs test/e2e/specs" } e2e使用nightwatch, chrome驱动当做浏览器. 而Selenium做代理服务器. 向浏览器发送测试请求.Selenium做代理服务器 12345678910111213141516171819202122232425262728293031323334353637383940414243//nightwatch configmodule.exports = { src_folders: ['test/e2e/specs'],//测试脚本路径 output_folder: 'test/e2e/reports', custom_assertions_path: ['test/e2e/custom-assertions'], //断言路径 selenium: { start_process: true, server_path: require('selenium-server').path, host: '127.0.0.1', port: 4444, cli_args: { 'webdriver.chrome.driver': require('chromedriver').path --这里要设置浏览器驱动的路径 } }, test_settings: { default: { //All the other environments are inheriting from default selenium_port: 4444, selenium_host: 'localhost', silent: true, globals: { devServerURL: 'http://localhost:' + (process.env.PORT || config.dev.port) } }, chrome: { desiredCapabilities: { browserName: 'chrome', javascriptEnabled: true, acceptSslCerts: true } }, firefox: { desiredCapabilities: { browserName: 'firefox', javascriptEnabled: true, acceptSslCerts: true } } }} runner123456789101112131415161718192021222324252627282930server.ready.then(() => { // 2. run the nightwatch test suite against it // to run in additional browsers: // 1. add an entry in test/e2e/nightwatch.conf.json under "test_settings" // 2. add it to the --env flag below // or override the environment flag, for example: `npm run e2e -- --env chrome,firefox` // For more information on Nightwatch's config file, see // http://nightwatchjs.org/guide#settings-file var opts = process.argv.slice(2) if (opts.indexOf('--config') === -1) { opts = opts.concat(['--config', 'test/e2e/nightwatch.conf.js']) } if (opts.indexOf('--env') === -1) { opts = opts.concat(['--env', 'chrome'])//默认chrome测试 } var spawn = require('cross-spawn') var runner = spawn('./node_modules/.bin/nightwatch', opts, { stdio: 'inherit' }) runner.on('exit', function (code) { server.close() process.exit(code) }) runner.on('error', function (err) { server.close() throw err })})