SpecFlow可重复使用的步骤定义 [英] SpecFlow Re-usable step definitions

查看:122
本文介绍了SpecFlow可重复使用的步骤定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让SpecFlow重用步骤定义?

Is there a way to have SpecFlow reuse Step Definitions?

在其他工具中,我使用了GivenWhenThen基类,其中包含诸如

In other tools I have used a GivenWhenThen base class that contains methods such as

WhenAnOrderIsCreated-这将初始化一个受保护的订单成员,以供继承类使用.

WhenAnOrderIsCreated -- this inits a protected order member to be used by inheriting classes.

似乎无法在SpecFlow上使用它(似乎不喜欢继承)

Just cant seem to get this working with SpecFlow (doesnt seem to like inheritance)

是否可以共享功能中的步骤?

Is there a way to share steps across features?

非常感谢

推荐答案

为什么可以-从步骤功能中查看调用步骤(

Why yes it's possible - check out the calling steps from step feature (https://specflow.org/documentation/Calling-Steps-from-Step-Definitions/)

简而言之,您将创建一个继承自这样的步骤的步骤定义类:

In short you create a step definition class that inherits from Steps like this:

[Binding]
public class CallingStepsFromStepDefinitionSteps : Steps
{}

然后您可以简单地调用其他步骤,例如:

And then you can simply call other steps like this:

[Given(@"I am logged in")]
public void GivenIAmLoggedIn()
{
     Given("I am on the index page");
     When("I enter my unsername nad password");
     And("I click the login button");
     incStepCount();
}

希望我能正确理解您的问题,并且这是对它的解答

I hope I understood your question correctly and that this was an answer to it

这篇关于SpecFlow可重复使用的步骤定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆