我有一个VueJS应用,该应用具有默认的Nightwatch E2E测试。我只是花了一些时间来设置用户帐户和身份验证。这样做之后,当我尝试运行E2E测试时,它们神秘地失败了。这是我得到的命令行输出:
code/premium-poker-tools [master●] » npm run e2e
> premium-poker-tools@1.0.0 e2e /Users/adamzerner/code/premium-poker-tools
> node test/e2e/runner.js
> Starting dev server...
Starting to optimize CSS...
> Listening at http://localhost:8080
Starting selenium server... started - PID: 58502
[BABEL] Note: The code generator has deoptimised the styling of "/Users/adamzerner/code/premium-poker-tools/test/e2e/specs/hit-calculator.js" as it exceeds the max of "500KB".
player
1
2
3
1) "before all" hook
0 passing (2s)
1 failing
1) player "before all" hook:
Connection refused! Is selenium server started?
npm ERR! code ELIFECYCLE
npm ERR! errno 10
npm ERR! premium-poker-tools@1.0.0 e2e: `node test/e2e/runner.js`
npm ERR! Exit status 10
npm ERR!
npm ERR! Failed at the premium-poker-tools@1.0.0 e2e 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! /Users/adamzerner/.npm/_logs/2019-05-23T19_47_08_016Z-debug.log
code/premium-poker-tools [master●] »
这是/Users/adamzerner/.npm/_logs/2019-05-27T17_44_07_557Z-debug.log
:
0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/Cellar/node/11.11.0/bin/node',
1 verbose cli '/usr/local/bin/npm',
1 verbose cli 'run',
1 verbose cli 'e2e' ]
2 info using npm@6.9.0
3 info using node@v11.11.0
4 verbose run-script [ 'pree2e', 'e2e', 'poste2e' ]
5 info lifecycle premium-poker-tools@1.0.0~pree2e: premium-poker-tools@1.0.0
6 info lifecycle premium-poker-tools@1.0.0~e2e: premium-poker-tools@1.0.0
7 verbose lifecycle premium-poker-tools@1.0.0~e2e: unsafe-perm in lifecycle true
8 verbose lifecycle premium-poker-tools@1.0.0~e2e: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/adamzerner/code/premium-poker-tools/node_modules/.bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/adamzerner/.rvm/bin
9 verbose lifecycle premium-poker-tools@1.0.0~e2e: CWD: /Users/adamzerner/code/premium-poker-tools
10 silly lifecycle premium-poker-tools@1.0.0~e2e: Args: [ '-c', 'node test/e2e/runner.js' ]
11 silly lifecycle premium-poker-tools@1.0.0~e2e: Returned: code: 10 signal: null
12 info lifecycle premium-poker-tools@1.0.0~e2e: Failed to exec e2e script
13 verbose stack Error: premium-poker-tools@1.0.0 e2e: `node test/e2e/runner.js`
13 verbose stack Exit status 10
13 verbose stack at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:301:16)
13 verbose stack at EventEmitter.emit (events.js:197:13)
13 verbose stack at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:197:13)
13 verbose stack at maybeClose (internal/child_process.js:984:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:265:5)
14 verbose pkgid premium-poker-tools@1.0.0
15 verbose cwd /Users/adamzerner/code/premium-poker-tools
16 verbose Darwin 18.6.0
17 verbose argv "/usr/local/Cellar/node/11.11.0/bin/node" "/usr/local/bin/npm" "run" "e2e"
18 verbose node v11.11.0
19 verbose npm v6.9.0
20 error code ELIFECYCLE
21 error errno 10
22 error premium-poker-tools@1.0.0 e2e: `node test/e2e/runner.js`
22 error Exit status 10
23 error Failed at the premium-poker-tools@1.0.0 e2e script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 10, true ]
对于一个,Connection refused! Is selenium server started?
错误似乎是错误的。上面显示的是Starting selenium server... started - PID: 58502
,我看到一个 Chrome 浏览器非常短暂地弹出,然后立即关闭。
这是所讨论的before
块的代码:
before(function (browser, done) {
console.log(1);
equityCalculator = browser.page['equity-calculator']();
console.log(2);
equityCalculator.navigate();
console.log(3);
browser.pause(20000);
equityCalculator
.waitForElementVisible('@app', 50000, function () {
console.log(4);
browser.resizeWindow(1440, 852, function () {
console.log(5);
done();
});
})
;
});
我一直试图确定问题出在哪里,但是我遇到了很多麻烦。 1
,2
和3
被注销,但4
或5
未注销,因此很有帮助。但是,如果3
被注销,为什么browser.pause(20000)
无法正常工作?
我也一直在尝试弄乱我的实际代码,以查看问题出在哪里。我在alert
中尝试了一些main.js
语句来试图找出问题所在:
// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
alert(1);
window.$ = require('jquery');
require('bootstrap');
alert(2);
import Vue from 'vue';
import store from '@/store';
import App from './App';
import router from './router';
import monkeyPatches from '@/services/monkey-patches';
import axios from 'axios';
import VueAxios from 'vue-axios';
alert(3);
Vue.config.productionTip = false
Vue.use(VueAxios, axios);
axios.interceptors.request.use(
function(config) {
config.withCredentials = true;
return config;
},
function(error) {
return Promise.reject(error);
}
);
/* eslint-disable no-new */
new Vue({
el: '#app',
router: router,
store: store,
template: '<App/>',
components: { App }
});
$(function () {
$('[data-toggle="popover"]').popover();
});
// if (navigator.serviceWorker) {
// navigator.serviceWorker.register('/service-worker.js').catch(function() {
// console.log('Service worker registration failed.');
// });
// }
但是很奇怪,alert(1)
甚至无法正常工作。所以我感到茫然。据我了解,main.js
的顶部是Vue应用程序的“开始”,如果还没有达到那个点,那是怎么回事? equityCalculator = browser.page['equity-calculator']();
和equityCalculator.navigate();
似乎很标准。这是页面对象的片段:
module.exports = {
url: 'http://localhost:8080/equity-calculator',
elements: {
'app': '#app',
当我启动开发服务器并转到该URL时,它完全可以工作。在实施用户帐户和身份验证之前,我的E2E测试全部正常运行,我没有更改此文件,但是现在遇到了问题。
我不确定从这里可以去哪里。救命!
更新:
摘录自package.json
:
{
...
"dependencies": {
...
"chromedriver": "^2.45.0",
"cross-spawn": "^6.0.5",
"nightwatch": "^0.9.21",
"selenium-server": "^3.141.59",
},
}
这里是nightwatch.conf.js
:
require('babel-register')
let config = require('../../config')
// http://nightwatchjs.org/gettingstarted#settings-file
module.exports = {
src_folders: ['test/e2e/specs'],
output_folder: 'test/e2e/reports',
custom_assertions_path: ['test/e2e/custom-assertions'],
page_objects_path: 'test/e2e/page-objects',
globals_path: 'test/e2e/globals.js',
test_runner : 'mocha',
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: {
selenium_port: 4444,
selenium_host: 'localhost',
silent: true,
globals: {
devServerURL: 'http://localhost:' + (process.env.PORT || config.dev.port),
handStrings: [
'aa', 'aks', 'aqs', 'ajs', 'ats', 'a9s', 'a8s', 'a7s', 'a6s', 'a5s', 'a4s', 'a3s', 'a2s',
'ako', 'kk', 'kqs', 'kjs', 'kts', 'k9s', 'k8s', 'k7s', 'k6s', 'k5s', 'k4s', 'k3s', 'k2s',
'aqo', 'kqo', 'qq', 'qjs', 'qts', 'q9s', 'q8s', 'q7s', 'q6s', 'q5s', 'q4s', 'q3s', 'q2s',
'ajo', 'kjo', 'qjo', 'jj', 'jts', 'j9s', 'j8s', 'j7s', 'j6s', 'j5s', 'j4s', 'j3s', 'j2s',
'ato', 'kto', 'qto', 'jto', 'tt', 't9s', 't8s', 't7s', 't6s', 't5s', 't4s', 't3s', 't2s',
'a9o', 'k9o', 'q9o', 'j9o', 't9o', '99', '98s', '97s', '96s', '95s', '94s', '93s', '92s',
'a8o', 'k8o', 'q8o', 'j8o', 't8o', '98o', '88', '87s', '86s', '85s', '84s', '83s', '82s',
'a7o', 'k7o', 'q7o', 'j7o', 't7o', '97o', '87o', '77', '76s', '75s', '74s', '73s', '72s',
'a6o', 'k6o', 'q6o', 'j6o', 't6o', '96o', '86o', '76o', '66', '65s', '64s', '63s', '62s',
'a5o', 'k5o', 'q5o', 'j5o', 't5o', '95o', '85o', '75o', '65o', '55', '54s', '53s', '52s',
'a4o', 'k4o', 'q4o', 'j4o', 't4o', '94o', '84o', '74o', '64o', '54o', '44', '43s', '42s',
'a3o', 'k3o', 'q3o', 'j3o', 't3o', '93o', '83o', '73o', '63o', '53o', '43o', '33', '32s',
'a2o', 'k2o', 'q2o', 'j2o', 't2o', '92o', '82o', '72o', '62o', '52o', '42o', '32o', '22',
],
}
},
chrome: {
desiredCapabilities: {
browserName: 'chrome',
javascriptEnabled: true,
acceptSslCerts: true
}
},
firefox: {
desiredCapabilities: {
browserName: 'firefox',
javascriptEnabled: true,
acceptSslCerts: true
}
}
}
}
对于Java / JDK:
code/premium-poker-tools-api [master] » java --version
java 9.0.4
Java(TM) SE Runtime Environment (build 9.0.4+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.4+11, mixed mode)
当我在Java控制面板中查看时,它说我是最新的。
我不确定如何确定我正在使用哪个Selenium版本或Chrome版本。对于Chrome,如果我打开Chrome并转到“关于Google Chrome”,它会显示74.0.3729.169
(最新版本),并且我假设我的测试使用的是同一版本。
答案 0 :(得分:1)
此日志消息...
Starting selenium server... started - PID: 58502
和随后的错误消息...
Connection refused! Is selenium server started?
...表示 WebDriver 实例(即 ChromeDriver )虽然已启动,但无法与 WebBrowsing 即 Chrome < / strong>会话。
有关以下内容的更多详细信息:
本可以帮助我们更好地调试问题。但是,正如您提到的“ 1、2和3被注销,而不是4或5” 一样,问题可能出在以下代码块中:
equityCalculator
.waitForElementVisible('@app', 50000, function () {
console.log(4);
browser.resizeWindow(1440, 852, function () {
console.log(5);
done();
});
})
根据讨论Connection refused! Is selenium server started nightwatch on edge,您的主要问题似乎是所使用的二进制版本之间的不兼容性。
@Test
。driver.quit()
方法内调用tearDown(){}
,以优雅地关闭和销毁 WebDriver 和 Web Client 实例。 updating
npm 解决了该问题(根据OP的评论)
npm update