我们有一个 Angular 4 项目,我们正在尝试使用 gulp、nightwatch 和 cucumber 添加一些 e2e 测试,但每次运行测试时都会发生以下错误:
$ gulp e2e-tests
[11:15:12] Using gulpfile ~project/path/gulpfile.js
[11:15:12] Starting 'e2e-tests'...
[11:15:12] Starting 'e2e-scenarios'...
[11:15:12] log file
[11:15:12] Starting nightwatch...
Starting selenium server... started - PID: 18742
There was an error while starting the test runner:
Error: Cannot find module 'e2e/step_definitions/xxxx.js'
at Function.Module._resolveFilename (module.js:555:15)
at Function.Module._load (module.js:482:25)
at Module.require (module.js:604:17)
at require (internal/module.js:11:18)
at /project/path/node_modules/cucumber/lib/cli/index.js:163:16
at Array.forEach (<anonymous>)
下面是我们的配置:
nightwatch.conf
var seleniumServer = require('selenium-server');
const chromedriver = require('chromedriver');
require('nightwatch-cucumber')({
cucumberArgs: ['--require', 'e2e/step_definitions', '--format', 'json:reports/cucumber.json', 'e2e/features']
});
module.exports = {
// Loads nightwatch-cucumber configuration into main nightwatch.js conf
custom_commands_path: '',
custom_assertions_path: '',
page_objects_path: '',
live_output: false,
disable_colors: false,
// Sets configuration for Selenium Server
selenium: {
start_process: true,
server_path: seleniumServer.path,
host: '127.0.0.1',
port: 4444,
cli_args : {
"webdriver.chrome.driver" : chromedriver.path
}
},
// Sets config options for different testing environments defined by the user
test_settings: {
default: {
launch_url: '',
selenium_port: 4444,
selenium_host: '127.0.0.1',
silent: true,
desiredCapabilities: {
browserName: 'chrome',
javascriptEnabled: true,
acceptSslCerts: true
},
'screenshots': {
enabled: true,
on_error: true,
on_failure: true,
path: '/screenshots'
}
},
chrome: {
desiredCapabilities: {
browserName: 'chrome',
javascriptEnabled: true,
acceptSslCerts: true
}
}
}
};
包.json
"devDependencies": {
"@angular/cli": "~1.6.0",
"@angular/compiler-cli": "^4.3.2",
"@angular/language-service": "^4.3.2",
"@types/jasmine": "~2.5.53",
"@types/jasminewd2": "~2.0.2",
"@types/node": "^6.0.104",
"codelyzer": "~3.0.1",
"gulp": "^3.9.1",
"jasmine-core": "~2.6.2",
"jasmine-spec-reporter": "~4.1.0",
"karma": "~1.7.0",
"karma-chrome-launcher": "~2.1.1",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^1.4.2",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.2",
"selenium-webdriver": "^4.0.0-alpha.1",
"ts-node": "~3.0.4",
"tslint": "~5.3.2",
"typescript": "~2.3.3"
}
gulpfile.js
var gulp = require('gulp');
var nightwatch = require('gulp-nightwatch');
var reporter = require('gulp-protractor-cucumber-html-report');
var runSequence = require('run-sequence');
gulp.task('default', function() {
return console.log('Starting gulp tasks…');
});
gulp.task('login', function() {
return gulp.src('')
.pipe(nightwatch({
configFile: 'nightwatch.conf.js'
}))
});
//E2E tasks
gulp.task('e2e-scenarios', [], function e2e() {
let tags = '';
let skipTags = '';
let tagIndex = process.argv.indexOf("--tag");
let skipTagIndex = process.argv.indexOf("--skiptags");
if (tagIndex > -1) {
tags = process.argv[tagIndex + 1];
tags = '--tag ' + tags;
}
if (skipTagIndex > -1) {
skipTags = process.argv[skipTagIndex + 1];
skipTags = '--skiptags ' + skipTags;
}
return gulp.src('')
.pipe(nightwatch({
configFile: 'nightwatch.conf.js',
cliArgs: [tags, skipTags]
}));
});
gulp.task('e2e-report', function () {
return gulp.src('./reports/cucumber.json')
.pipe(reporter({
dest: 'reports/'
}));
});
gulp.task('e2e-tests', function (done) {
runSequence('e2e-scenarios', 'e2e-report', function () {
done();
});
});
这是项目结构
项目 在这里输入图片描述
请帮助我找出导致此问题的原因。