我正在尝试将黄瓜“步骤”的步骤描述的字符串/正则表达式记录到控制台。这是一个示例步骤
Given Alice is hungry
...这是步骤定义的第一行
Given( /^Alice is hungry$/, () => {
我正在尝试在 webdriverio 的特定于黄瓜的钩子的上下文中,使用作为参数提供的“步骤”对象的字符串表示来将“鉴于 Alice 饿了”记录到控制台。跑步
beforeStep: function ({ uri, feature, step }, context) {
console.log(`Running "${JSON.stringify(step, null, 4)}"`);
}
...产生这个输出:
[0-0] Running "{
"uri": "featureFiles\\dev\\my-first-feature-file.feature",
"feature": {
"type": "Feature",
"tags": [],
"location": {
"line": 8,
"column": 1
},
"language": "en",
"keyword": "Functionality",
"name": "Eating too many cucumbers is not good for you",
"children": [
{
"type": "Scenario",
"tags": [
{
"type": "Tag",
"location": {
"line": 10,
"column": 3
},
"name": "@Szenario-Eating-all-the-cucumbers"
}
],
"location": {
"line": 11,
"column": 3
},
"keyword": "Szenario",
"name": "Eating a few is no problem",
"steps": [
{
"type": "Hook",
"location": {
"line": 187,
"column": 0,
"uri": "node_modules\\@wdio\\cucumber-framework\\build\\index
.js"
},
"keyword": "Hook",
"text": ""
},
{
"type": "Step",
"location": {
"line": 12,
"column": 3
},
"keyword": "Given",
"text": "Alice is hungry"
},
{
"type": "Step",
"location": {
"line": 13,
"column": 5
},
"keyword": "When ",
"text": "she eats 3 cucumbers'"
},
{
"type": "Step",
"location": {
"line": 14,
"column": 5
},
"keyword": "Then ",
"text": "she will be full"
},
但是,当我使用
beforeStep: function ({ uri, feature, step }, context) {
// eslint-disable-next-line no-undef
console.log(\`Running step "${step.text}"`);
}
...我得到的只是
[0-0] Running "undefined"
[0-0] Running "undefined"
我已经尝试了这两个选项:
console.log(`Running "${step.feature.children.steps.text}"`);
console.log(`Running "${feature.children.steps.text}"`);
在这两种情况下,这都会产生以下结果:
[0-0] Error in "BeforeStep Hook"
Cannot read property 'text' of undefined
我究竟做错了什么?