将 Protractor 2.1.0 与 CucumberJS 一起使用时出错
Error using Protractor 2.1.0 with CucumberJS
我在从 Protractor 2.0 升级到 Protractor 2.1 时遇到问题,我怀疑这是使用 Protractor 2.1 和 CucumberJS 的问题。当我编辑 package.json 以降级到 Protractor 2.0.0,并重新安装节点包时,问题就解决了。是什么导致 Protractor 2.1.0 中的错误?如何重写我的项目以使用 Protractor 2.1.0 和 Cucumber JS?
我的项目文件及其内容如下:
/path/to/myproject/conf.js
exports.config = {
sauceUser: process.env.SAUCE_USERNAME,
sauceKey: process.env.SAUCE_ACCESS_KEY,
specs: [
'features/*.feature'
],
multiCapabilities: [
{
'browserName': 'chrome'
}
],
framework: 'cucumber',
cucumberOpts: {
require: 'features/stepDefinitions.js',
format: 'summary'
}
};
/path/to/myproject/features/demo.特征
Feature: Refund item
Scenario: Jeff returns a faulty microwave
Given Jeff has bought a microwave for 0
And he has a receipt
When he returns the microwave
Then Jeff should be refunded 0
/path/to/myproject/features/stepDefinitions.js
module.exports = function() {
this.Given(/^Jeff has bought a microwave for $(\d+)$/, function (arg1, callback) {
// Write code here that turns the phrase above into concrete actions
callback.pending();
});
this.Given(/^he has a receipt$/, function (callback) {
// Write code here that turns the phrase above into concrete actions
callback.pending();
});
this.When(/^he returns the microwave$/, function (callback) {
// Write code here that turns the phrase above into concrete actions
callback.pending();
});
this.Then(/^Jeff should be refunded $(\d+)$/, function (arg1, callback) {
// Write code here that turns the phrase above into concrete actions
callback.pending();
});
};
/path/to/myproject/package.json
{
"name": "strato-remake",
"version": "1.0.0",
"description": "",
"main": "conf.js",
"dependencies": {
},
"devDependencies": {
"cucumber": "0.4.9",
"protractor": "2.1.0"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
安装节点包后,量角器为运行:
$ npm install
$ $(npm bin)/protractor conf.js
以下错误打印到终端:
Using SauceLabs selenium server at http://ondemand.saucelabs.com:80/wd/hub
[launcher] Running 1 instances of WebDriver
[launcher] Error: TypeError: Cannot read property 'apply' of undefined
at formatter.handleBeforeFeatureEvent (/path/to/myproject/node_modules/protractor/lib/frameworks/cucumber.js:83:41)
at /path/to/myproject/node_modules/protractor/lib/frameworks/cucumber.js:153:15
at Function.promise (/path/to/myproject/node_modules/protractor/node_modules/q/q.js:650:9)
at /path/to/myproject/node_modules/protractor/lib/frameworks/cucumber.js:147:14
at _fulfilled (/path/to/myproject/node_modules/protractor/node_modules/q/q.js:797:54)
at self.promiseDispatch.done (/path/to/myproject/node_modules/protractor/node_modules/q/q.js:826:30)
at Promise.promise.promiseDispatch (/path/to/myproject/node_modules/protractor/node_modules/q/q.js:759:13)
at /path/to/myproject/node_modules/protractor/node_modules/q/q.js:525:49
at flush (/path/to/myproject/node_modules/protractor/node_modules/q/q.js:108:17)
at process._tickCallback (node.js:355:11)
[launcher] Process exited with error code 100
但是,如果我编辑 package.json 以降级到 Protractor 2.0.0,并再次安装节点包:
"devDependencies": {
"cucumber": "0.4.9",
"protractor": "2.0.0"
},
然后当我 运行 量角器:
$ $(npm bin)/protractor conf.js
Using SauceLabs selenium server at http://ondemand.saucelabs.com:80/wd/hub
[launcher] Running 1 instances of WebDriver
1 scenario (1 pending)
4 steps (1 pending, 3 skipped)
SauceLabs results available at http://saucelabs.com/jobs/8a85b85e7a1c5dd344e694e392ec90c3
[launcher] 0 instance(s) of WebDriver still running
[launcher] chrome #1 passed
如何重写此项目以兼容 Protractor 2.1.0 和 Cucumber JS?谢谢!
这是 Protractor 中的错误的结果,已由 this pull request 修复。要使用该特定提交,请将您的 package.json 更改为包括:
"devDependencies": {
"cucumber": "0.4.9",
"protractor": "git+https://github.com/angular/protractor.git#0262268fa43b9eefac815d986740efa07bb15818"
},
我在从 Protractor 2.0 升级到 Protractor 2.1 时遇到问题,我怀疑这是使用 Protractor 2.1 和 CucumberJS 的问题。当我编辑 package.json 以降级到 Protractor 2.0.0,并重新安装节点包时,问题就解决了。是什么导致 Protractor 2.1.0 中的错误?如何重写我的项目以使用 Protractor 2.1.0 和 Cucumber JS?
我的项目文件及其内容如下:
/path/to/myproject/conf.js
exports.config = {
sauceUser: process.env.SAUCE_USERNAME,
sauceKey: process.env.SAUCE_ACCESS_KEY,
specs: [
'features/*.feature'
],
multiCapabilities: [
{
'browserName': 'chrome'
}
],
framework: 'cucumber',
cucumberOpts: {
require: 'features/stepDefinitions.js',
format: 'summary'
}
};
/path/to/myproject/features/demo.特征
Feature: Refund item
Scenario: Jeff returns a faulty microwave
Given Jeff has bought a microwave for 0
And he has a receipt
When he returns the microwave
Then Jeff should be refunded 0
/path/to/myproject/features/stepDefinitions.js
module.exports = function() {
this.Given(/^Jeff has bought a microwave for $(\d+)$/, function (arg1, callback) {
// Write code here that turns the phrase above into concrete actions
callback.pending();
});
this.Given(/^he has a receipt$/, function (callback) {
// Write code here that turns the phrase above into concrete actions
callback.pending();
});
this.When(/^he returns the microwave$/, function (callback) {
// Write code here that turns the phrase above into concrete actions
callback.pending();
});
this.Then(/^Jeff should be refunded $(\d+)$/, function (arg1, callback) {
// Write code here that turns the phrase above into concrete actions
callback.pending();
});
};
/path/to/myproject/package.json
{
"name": "strato-remake",
"version": "1.0.0",
"description": "",
"main": "conf.js",
"dependencies": {
},
"devDependencies": {
"cucumber": "0.4.9",
"protractor": "2.1.0"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
安装节点包后,量角器为运行:
$ npm install
$ $(npm bin)/protractor conf.js
以下错误打印到终端:
Using SauceLabs selenium server at http://ondemand.saucelabs.com:80/wd/hub
[launcher] Running 1 instances of WebDriver
[launcher] Error: TypeError: Cannot read property 'apply' of undefined
at formatter.handleBeforeFeatureEvent (/path/to/myproject/node_modules/protractor/lib/frameworks/cucumber.js:83:41)
at /path/to/myproject/node_modules/protractor/lib/frameworks/cucumber.js:153:15
at Function.promise (/path/to/myproject/node_modules/protractor/node_modules/q/q.js:650:9)
at /path/to/myproject/node_modules/protractor/lib/frameworks/cucumber.js:147:14
at _fulfilled (/path/to/myproject/node_modules/protractor/node_modules/q/q.js:797:54)
at self.promiseDispatch.done (/path/to/myproject/node_modules/protractor/node_modules/q/q.js:826:30)
at Promise.promise.promiseDispatch (/path/to/myproject/node_modules/protractor/node_modules/q/q.js:759:13)
at /path/to/myproject/node_modules/protractor/node_modules/q/q.js:525:49
at flush (/path/to/myproject/node_modules/protractor/node_modules/q/q.js:108:17)
at process._tickCallback (node.js:355:11)
[launcher] Process exited with error code 100
但是,如果我编辑 package.json 以降级到 Protractor 2.0.0,并再次安装节点包:
"devDependencies": {
"cucumber": "0.4.9",
"protractor": "2.0.0"
},
然后当我 运行 量角器:
$ $(npm bin)/protractor conf.js
Using SauceLabs selenium server at http://ondemand.saucelabs.com:80/wd/hub
[launcher] Running 1 instances of WebDriver
1 scenario (1 pending)
4 steps (1 pending, 3 skipped)
SauceLabs results available at http://saucelabs.com/jobs/8a85b85e7a1c5dd344e694e392ec90c3
[launcher] 0 instance(s) of WebDriver still running
[launcher] chrome #1 passed
如何重写此项目以兼容 Protractor 2.1.0 和 Cucumber JS?谢谢!
这是 Protractor 中的错误的结果,已由 this pull request 修复。要使用该特定提交,请将您的 package.json 更改为包括:
"devDependencies": {
"cucumber": "0.4.9",
"protractor": "git+https://github.com/angular/protractor.git#0262268fa43b9eefac815d986740efa07bb15818"
},