從量角器2.0升級到量角器2.1時遇到問題,並懷疑這是使用量角器2.1和CucumberJS時的問題。當我編輯package.json降級到Protractor 2.0.0並重新安裝節點包時,問題就解決了。什麼原因導致了Protractor 2.1.0中的錯誤?我如何重寫我的項目以使用Protractor 2.1.0和Cucumber JS?使用量角器2.1.0和CucumberJS時出錯
我的項目文件及其內容列舉如下:
/路徑/到/ 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'
}
};
/路徑/到/ myproject的/ 功能/ demo.feature
Feature: Refund item
Scenario: Jeff returns a faulty microwave
Given Jeff has bought a microwave for $100
And he has a receipt
When he returns the microwave
Then Jeff should be refunded $100
/路徑/到/ myproject的/ 特徵/ 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();
});
};
/路徑/到/ 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降級到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?謝謝!
嗨@AristarkhArtemiy,我試圖實現你做了什麼,但我不斷收到: [啓動]錯誤:類型錯誤:未定義不功能 at /usr/local/lib/node_modules/protractor/lib/frameworks/cucumber.js:150:36 at Function.promise(/usr/local/lib/node_modules/protractor/node_modules/q/q.js :650:9) at /usr/local/lib/node_modules/protractor/lib/frameworks/cucumber.js:147:14 at _fulfilled(/ usr/local/lib/node_modules/protractor/node_modules/q/q。 js:797:54) at self.promiseDispatch.done –