【问题标题】:Calling Steps from Step Definitions从步骤定义调用步骤
【发布时间】:2019-03-31 00:49:29
【问题描述】:

我正在创建一个功能文件,用于从其他场景调用其他步骤。如果缺少任何内容,请在下面找到并提出建议。

功能文件:

功能:测试多个步骤

Scenario: Print All console
    Given Print the start console
    Given Print All console
do
step "Print the console for numbers"
step "Print first numbers console"
step "Print second numbers console"
end

Scenario: Print All console
    Given Print the console for numbers
    Then Print first numbers console
    Then Print second numbers console

步骤定义:

import { Then, Given } from 'cucumber';

Given(/^Print the start console$/, async () => {
    console.log('------Printing console-----');
});


Then(/^Print All console$/, async () => {
    console.log('------Printing all console-----');
});


Given(/^Print the console for numbers$/, async () => {
    console.log('------Printing console for numbers-----');
});


Then(/^Print first numbers console$/, async () => {
    console.log('------Printing first number console-----');
});

Then(/^Print second numbers console$/, async () => {
    console.log('------Printing second number console-----');
});

执行时我收到如下错误。请帮忙。

[12:21:35] E/launcher - 错误:错误:“src\features\multipleSteps.feature”中的解析错误:(6:5):预期:#EOF、#TableRow、#DocStringSeparator、#StepLine ,#TagLine,#ScenarioLine,#ScenarioOutlineLine,#Comment,#Empty,得到了'做'


【问题讨论】:

  • 移除特征文件中的代码。 do 和 step 线。错误消息最后也提到了它 - got 'do'
  • 那么,如何调用这些步骤。意图是重用这些步骤。是否应将其从功能文件中删除并添加到步骤定义文件中?然后请帮助语法
  • 代码应该在步骤定义中
  • 你能帮忙形成语法吗?我正在尝试使用打字稿,但语法不起作用。 Then(/^Print All console$/, async () => { do step "打印数字的控制台"; step "打印第一个数字的控制台"; step "打印第二个数字的控制台"; end console.log('-- ----打印所有控制台-----'); });

标签: typescript protractor cucumber


【解决方案1】:

您可以使用场景大纲 喜欢:

场景大纲:打印所有控制台

Given Print the start console

Given Print All “<console>”

例子:

|控制台|

|打印数字控制台 |

|打印第一个数字控制台 |

|打印第二个数字控制台 |

在此参考: Cucumber scenario outline and examples with generic step definitions

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-23
    • 2020-04-04
    相关资源
    最近更新 更多