所以,我一直在使用量角器(jasmine 2)编写非常好的 e2e 测试,但现在我的要求发生了变化:我需要从 Jasmine2 切换到 Cucumber 。截至目前,量角器不再直接支持黄瓜。我尝试了自定义框架设置 => 不成功。如前所述,我正在使用 gulp-angular-protractor,它为我提供了一个出色而简单的工作环境(在运行测试时打开/关闭 webdriver,gulp 命令等),我仍然想保留它。
这是我的配置:
包.json
...
"devDependencies": {
"angular-mocks": "^1.5.1",
"browser-sync": "^2.10.0",
"cucumber": "^0.10.2",
"del": "^2.1.0",
"gulp": "^3.9.1",
"gulp-angular-protractor": "^0.1.1",
...
gulpfile.js:
gulp.task('e2e', function(callback) {
gulp
.src(['./dist/**/*.e2e.js'])
.pipe(gulpProtractorAngular({
'configFile': 'protractor.conf.js',
'debug': false,
'autoStartStopServer': true
}))
.on('error', function(e) {
console.log(e);
})
.on('end', callback);
});
量角器.conf.js
exports.config = {
baseUrl: 'http://localhost:3000',
specs: ['dist/**/*.feature'],
directConnect: true,
exclude: [],
multiCapabilities: [{
browserName: 'chrome'
}],
allScriptsTimeout: 110000,
getPageTimeout: 100000,
framework: 'custom',
frameworkPath: require.resolve('cucumber'),
cucumberOpts: {
require: 'dist/**/*steps.js',
format: 'pretty'
},
/**
* ng2 related configuration
*
* useAllAngular2AppRoots: tells Protractor to wait for any angular2 apps on the page instead of just the one matching
* `rootEl`
*
*/
useAllAngular2AppRoots: true
};
虚拟测试:
世界.js
module.exports = function() {
this.World = function World(callback) {
this.prop = "Hello from the World!"; // this property will be available in step definitions
this.greetings = function(name, callback) {
console.log("\n----Hello " + name);
callback();
};
callback(); // tell Cucumber we're finished and to use 'this' as the world instance
};
}
login.component.feature
Feature: Sample
Scenario: First sample
Given this is the first sample
Scenario: Second sample
Given this is the second sample
login.component.steps.js
var sampleSteps = function() {
this.Given(/^this is the first sample$/, function (callback) {
console.log("\n----" + this.prop);
callback();
});
this.Given(/^this is the second sample$/, function (callback) {
this.greetings("everybody", callback);
});
};
module.exports = sampleSteps;
问题:当我运行 gulp e2e 时,我得到:
launcher] Error: TypeError: require(...).run is not a function
在 C:\Users\Documents\dev\node_modules\gulp-angular-protractor\node_m dules\gulp-protractor\node_modules\protractor\lib\runner.js:337:35 在 _fulfilled (C:\Users\Documents\dev\ node_modules\gulp-angular-protr ctor\node_modules\gulp-protractor\node_modules\protractor\node_modules\q\q.js:7 7:54) 在 self.promiseDispatch.done (C:\Users\Documents\dev\node_modules\ gul -angular-protractor\node_modules\gulp-protractor\node_modules\protractor\node_m dules\q\q.js:826:30) 在 Promise.promise.promiseDispatch (C:\Users\Documents\dev\node_modul s\gulp- angular-protractor\node_modules\gulp-protractor\node_modules\protractor\ ode_modules\q\q.js:759:13) 在 C:\Users\Documents\dev\node_modules\gulp-angular-protractor\node_m dules\gulp-protractor \node_modules\protractor\node_modules\q\q.js:525:49 冲洗 (C:\Users\Documents\dev\node_modules\gulp-angular-protractor node_modules\gulp-protractor\node_modules\protractor\node_modules\q\q.js:108:17
知道我在做什么错吗?