为什么 Protractor Cucumber 无法在 Protractor Cucumber 框架中使用最新版本的 Cucumber 找到步骤文件
Why protractor cucumber is not able to locate step file with latest version of Cucumber in Protractor Cucumber framework
我正在使用 Protractor Cucumber 框架,因为长期以来我观察到 Cucumber 无法在项目中找到规范文件。我使用了最新版本的黄瓜 6.0.3,它无法找到规范文件,但我有相同的代码 运行 使用黄瓜 1.3.3.. 任何人都可以告诉我这个版本有什么区别吗?我需要为 6.0.3
更新什么吗
黄瓜依赖 - 1.3.3
"cucumber": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/cucumber/-/cucumber-1.3.3.tgz",
"integrity": "sha1-Za+2Xy+T9y2teN8qterPFGCf7C8=",
"requires": {
"camel-case": "^3.0.0",
"cli-table": "^0.3.1",
"co": "^4.6.0",
"colors": "^1.1.2",
"commander": "^2.9.0",
"duration": "^0.2.0",
"figures": "1.7.0",
"gherkin": "^4.1.0",
"glob": "^7.0.0",
"is-generator": "^1.0.2",
"lodash": "^4.0.0",
"stack-chain": "^1.3.5",
"stacktrace-js": "^1.3.0"
}
黄瓜依赖 6.0.3 最新
"cucumber": {
"version": "6.0.3",
"resolved": "https://registry.npmjs.org/cucumber/-/cucumber-6.0.3.tgz",
"integrity": "sha512-FSx7xdAQfFjcxp/iRBAuCFSXp2iJP1tF2Q5k/a67YgHiYbnwsD9F+UNv9ZG90LFHNsNQhb+67AmVxHkp4JRDpg==",
"dev": true,
"requires": {
"assertion-error-formatter": "^3.0.0",
"bluebird": "^3.4.1",
"cli-table3": "^0.5.1",
"colors": "^1.1.2",
"commander": "^3.0.1",
"cucumber-expressions": "^8.0.1",
"cucumber-tag-expressions": "^2.0.2",
"duration": "^0.2.1",
"escape-string-regexp": "^2.0.0",
"figures": "^3.0.0",
"gherkin": "5.0.0",
"glob": "^7.1.3",
"indent-string": "^4.0.0",
"is-generator": "^1.0.2",
"is-stream": "^2.0.0",
"knuth-shuffle-seeded": "^1.0.6",
"lodash": "^4.17.14",
"mz": "^2.4.0",
"progress": "^2.0.0",
"resolve": "^1.3.3",
"serialize-error": "^4.1.0",
"stack-chain": "^2.0.0",
"stacktrace-js": "^2.0.0",
"string-argv": "^0.3.0",
"title-case": "^2.1.1",
"util-arity": "^1.0.2",
"verror": "^1.9.0"
}
StepDef
module.exports=function(){
this.Given(/^Open the browser and Load the URL$/,async function(){
await firstBrowser.get(properties.get("url1"));
browser.logger.info("Title of the window is :"+await browser.getTitle());
//screenshots.takesScreenshot("filename");
});
this.When(/^User entered the text in the search box$/,async function(){
firstBrowser.sleep(3000);
await page1.email().sendKeys(testData.Login.CM[0].Username);
browser.sleep(3000);
await page1.password().sendKeys(testData.Login.CM[0].Password);
});
}
配置文件
exports.config = {
//seleniumAddress: 'http://localhost:4444/wd/hub',
getPageTimeout: 60000,
allScriptsTimeout: 500000,
directConnect:true,
framework: 'custom',
// path relative to the current config file
frameworkPath: require.resolve('protractor-cucumber-framework'),
capabilities: {
'browserName': 'chrome'
},
ignoreUncaughtExceptions:true,
// Spec patterns are relative to this directory.
specs: [
'H:\workspace\Protractor_Cucumber\src\FeatureFiles\Test.feature'
],
cucumberOpts: {
require: 'H:\workspace\Protractor_Cucumber\src\StepDefFiles\*.js',
tags: false,
profile: false,
'no-source': true
},
onPrepare: function () {
browser.waitForAngularEnabled(false);
const {Given, Then, When, Before} = require('cucumber');
}
};
我没有在我的测试脚本中使用任何黄瓜钩子..
是什么让他们的工作方式与众不同,对此有什么帮助吗?
一个原因是 Then/When/Given
cucumber
6.x 中的用法更改,您可以更改几个步骤函数来验证这一点。
对于1.x步函数文件看起来像
module.exports = function () {
this.Then(/^Then the response status is (.*)$/, function (status) {
assert.equal(this.responseStatus, status)
});
this.When(//, ...)
}
对于6.x步函数文件看起来像
const { Then, When } = require('cucumber');
Then(/^the response status is (.*)$/, function (status) {
assert.equal(this.responseStatus, status)
});
When(//,...)
另一个可能的原因是需要升级与cucumber@6.x
兼容的protractor-cucumber-framework
版本
我正在使用 Protractor Cucumber 框架,因为长期以来我观察到 Cucumber 无法在项目中找到规范文件。我使用了最新版本的黄瓜 6.0.3,它无法找到规范文件,但我有相同的代码 运行 使用黄瓜 1.3.3.. 任何人都可以告诉我这个版本有什么区别吗?我需要为 6.0.3
更新什么吗黄瓜依赖 - 1.3.3
"cucumber": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/cucumber/-/cucumber-1.3.3.tgz",
"integrity": "sha1-Za+2Xy+T9y2teN8qterPFGCf7C8=",
"requires": {
"camel-case": "^3.0.0",
"cli-table": "^0.3.1",
"co": "^4.6.0",
"colors": "^1.1.2",
"commander": "^2.9.0",
"duration": "^0.2.0",
"figures": "1.7.0",
"gherkin": "^4.1.0",
"glob": "^7.0.0",
"is-generator": "^1.0.2",
"lodash": "^4.0.0",
"stack-chain": "^1.3.5",
"stacktrace-js": "^1.3.0"
}
黄瓜依赖 6.0.3 最新
"cucumber": {
"version": "6.0.3",
"resolved": "https://registry.npmjs.org/cucumber/-/cucumber-6.0.3.tgz",
"integrity": "sha512-FSx7xdAQfFjcxp/iRBAuCFSXp2iJP1tF2Q5k/a67YgHiYbnwsD9F+UNv9ZG90LFHNsNQhb+67AmVxHkp4JRDpg==",
"dev": true,
"requires": {
"assertion-error-formatter": "^3.0.0",
"bluebird": "^3.4.1",
"cli-table3": "^0.5.1",
"colors": "^1.1.2",
"commander": "^3.0.1",
"cucumber-expressions": "^8.0.1",
"cucumber-tag-expressions": "^2.0.2",
"duration": "^0.2.1",
"escape-string-regexp": "^2.0.0",
"figures": "^3.0.0",
"gherkin": "5.0.0",
"glob": "^7.1.3",
"indent-string": "^4.0.0",
"is-generator": "^1.0.2",
"is-stream": "^2.0.0",
"knuth-shuffle-seeded": "^1.0.6",
"lodash": "^4.17.14",
"mz": "^2.4.0",
"progress": "^2.0.0",
"resolve": "^1.3.3",
"serialize-error": "^4.1.0",
"stack-chain": "^2.0.0",
"stacktrace-js": "^2.0.0",
"string-argv": "^0.3.0",
"title-case": "^2.1.1",
"util-arity": "^1.0.2",
"verror": "^1.9.0"
}
StepDef
module.exports=function(){
this.Given(/^Open the browser and Load the URL$/,async function(){
await firstBrowser.get(properties.get("url1"));
browser.logger.info("Title of the window is :"+await browser.getTitle());
//screenshots.takesScreenshot("filename");
});
this.When(/^User entered the text in the search box$/,async function(){
firstBrowser.sleep(3000);
await page1.email().sendKeys(testData.Login.CM[0].Username);
browser.sleep(3000);
await page1.password().sendKeys(testData.Login.CM[0].Password);
});
}
配置文件
exports.config = {
//seleniumAddress: 'http://localhost:4444/wd/hub',
getPageTimeout: 60000,
allScriptsTimeout: 500000,
directConnect:true,
framework: 'custom',
// path relative to the current config file
frameworkPath: require.resolve('protractor-cucumber-framework'),
capabilities: {
'browserName': 'chrome'
},
ignoreUncaughtExceptions:true,
// Spec patterns are relative to this directory.
specs: [
'H:\workspace\Protractor_Cucumber\src\FeatureFiles\Test.feature'
],
cucumberOpts: {
require: 'H:\workspace\Protractor_Cucumber\src\StepDefFiles\*.js',
tags: false,
profile: false,
'no-source': true
},
onPrepare: function () {
browser.waitForAngularEnabled(false);
const {Given, Then, When, Before} = require('cucumber');
}
};
我没有在我的测试脚本中使用任何黄瓜钩子.. 是什么让他们的工作方式与众不同,对此有什么帮助吗?
一个原因是 Then/When/Given
cucumber
6.x 中的用法更改,您可以更改几个步骤函数来验证这一点。
对于1.x步函数文件看起来像
module.exports = function () {
this.Then(/^Then the response status is (.*)$/, function (status) {
assert.equal(this.responseStatus, status)
});
this.When(//, ...)
}
对于6.x步函数文件看起来像
const { Then, When } = require('cucumber');
Then(/^the response status is (.*)$/, function (status) {
assert.equal(this.responseStatus, status)
});
When(//,...)
另一个可能的原因是需要升级与cucumber@6.x
protractor-cucumber-framework
版本