admin管理员组文章数量:1428105
I have some step definitions that use custom parameters.
const assertEntity = function(name: string, operator: string,
otherName: string) {
console.log(`assertAttrs with ${name} ${operator} ${otherName}`);
};
Then("{name} object is {operator} {otherName}", assertEntity);
And the following feature file (truncated)
Scenario: Compare two similar API key objects
Given we have a new ApiKey called Red
And parameter types defined like this
defineParameterType({
regexp: /name/,
transformer: function(s) {
return s;
},
name: "name"
});
However cucumber says step definition is undefined...
? Given we have a new ApiKey called Red
Undefined. Implement with the following snippet:
Given('we have a new ApiKey called Red', function () {
// Write code here that turns the phrase above into concrete actions
return 'pending';
});
I believe the problem is in my regexp but I've seen this done in examples so I'm not sure how to proceed.
I have some step definitions that use custom parameters.
const assertEntity = function(name: string, operator: string,
otherName: string) {
console.log(`assertAttrs with ${name} ${operator} ${otherName}`);
};
Then("{name} object is {operator} {otherName}", assertEntity);
And the following feature file (truncated)
Scenario: Compare two similar API key objects
Given we have a new ApiKey called Red
And parameter types defined like this
defineParameterType({
regexp: /name/,
transformer: function(s) {
return s;
},
name: "name"
});
However cucumber says step definition is undefined...
? Given we have a new ApiKey called Red
Undefined. Implement with the following snippet:
Given('we have a new ApiKey called Red', function () {
// Write code here that turns the phrase above into concrete actions
return 'pending';
});
I believe the problem is in my regexp but I've seen this done in examples so I'm not sure how to proceed.
Share Improve this question asked Oct 1, 2018 at 15:25 Alex LoganAlex Logan 1,2413 gold badges18 silver badges27 bronze badges1 Answer
Reset to default 4How the Transformers work
- The regex has to match the parameter
- The cucumber expression has to match the step when converted back to a regex
You can use any variety of transformations. For instance:
Given I am on the "Home" page
Given I am on the "My Basket" page
Could both be matched by the transformer:
defineParameterType({
regexp: /"([^"]*)"/,
transformer(string) {
return urls[string.replace(/ /g, "_").toLowerCase()]
},
name: 'page',
useForSnippets: false
});
The transformation that is happening here is the url is being located in an array of various urls.
The Answer
For your example, the step definition that you have provided wouldn't match the step that you have provided.
But, if we were to go ahead and match this:
Given we have a new ApiKey called "Red"
By using a step definition like this:
Given('we have a new ApiKey called {name}', function(){
return pending
});
We would require a step transformer like this:
defineParameterType({
regexp: /"([^"]*)"/,
transformer: function(s) {
return s;
},
name: "name",
useForSnippets: false
});
Note: "([^"]*)"
is not the be-all end-all of regex matching with Cucumber, but it was a fairly standard regex to be found within the step definitions before cucumber expressions came out with 3.x.x, hence the 2 examples I've used are with them.
本文标签: javascriptCucumber JS Custom parameter types not matchingStack Overflow
版权声明:本文标题:javascript - Cucumber JS: Custom parameter types not matching - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745499742a2660973.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论