繁体   English   中英

从SpecFlow中的场景获取当前的步骤定义

[英]Get current Step definition from of a Scenario in SpecFlow

我正在为一个名为CodeSpec的框架做贡献,该框架建立在SpecFlow的基础上。

使用ScenarioContext我可以获得当前正在执行的方案的标题。 但我也想获得步骤定义。

说的情况是

Scenario: Google for Cats
Given I navigate to "http://google.com"
And I enter value "Cats" to the "searchBox" with the "id" of "lst-ib"
And I click on element "searchButton" with the "xpath" of "id('sblsbb')/button" and wait "4" seconds
Then The page contains text pattern "The domestic cat is"

我可以使用以下代码获得标题,

[AfterScenario("UIAutomationReport")]
public static void AfterScenario()
{
    var title = ScenarioContext.Current.ScenarioInfo.Title;
   //title now is "Google for Cats"

}

我也想获得步骤定义,就像“ Given I navigate to "http://google.com"And I enter value "Cats" to the "searchBox" with the "id" of "lst-ib"

我怎样才能做到这一点?

您无法在当前版本的specflow中获得此功能,但在下一版本(v2)中,有关步骤文本和步骤类型的信息将可从ScenarioStepContext类中获得。

您可以从CI build nuget feed中获得新版本的beta版本。

您可以使用以下代码来获取步骤定义:

String title = ScenarioContext.Current.StepContext.StepInfo.Text; 

Console.WriteLine("Step Definition Title : " + title);

您可以找到呼叫者姓名和呼叫者属性

StackFrame frame =新的StackFrame(1);

MethodBase方法= frame.GetMethod();

message = String.Format(“ {0}。{1}:{2}”,method.DeclaringType.FullName,method.Name,message);

Console.WriteLine(message);

请参见C#方法调用者

归功于Specflow步骤说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM