【问题标题】:Find if specflow step starts with And or But查找 specflow 步骤是否以 And 或 But 开头
【发布时间】:2017-05-18 23:52:09
【问题描述】:

如果 Specflow 场景步骤以 AndBut 而不是 Given/When/Then 开头,有没有办法检索?我想把步骤写成文本。

例如:

Given this is a step
And this is another one
When I do something
Then something happen
But something else dont

And/But 是否存储在我可以检索的任何位置?

谢谢!

【问题讨论】:

  • 为什么需要这些信息?我从来不需要依赖 And/But 来执行步骤。
  • 我正在尝试将执行的步骤存储在一个文本文件中,例如一个小日志。目前,它的注册如下(考虑我给出的示例):鉴于这是一个步骤/鉴于这是另一个步骤/当我做某事/然后发生某事/然后其他事情不会再一次,这不是问题,但它会是很高兴以与编写方式相同的方式登录
  • 我明白了。比我的回答应该对你有所帮助。

标签: specflow


【解决方案1】:

可能是,此信息在 StepInfo (https://github.com/techtalk/SpecFlow/blob/master/TechTalk.SpecFlow/StepInfo.cs) 中可用。

[Binding]
public class Binding
{ 
    private ScenarioContext _scenarioContext;

    public Binding(ScenarioContext scenarioContext)
    {
        _scenarioContext = scenarioContext;
    }

    [AfterStep()]
    public void AfterStepHook()
    {
        var stepText = _scenarioContext.ScenarioStepContext.StepInfo.Text;
    }
}

无需编译/运行即可编写代码。

【讨论】:

  • 试过了,Text 属性返回没有任何关键字的步骤,而 StepDeifinitionType 属性返回 Given、When 或 Then 仅
猜你喜欢
  • 2014-05-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多