如何在specflow中的Then步骤之后使用When step?

时间:2015-07-07 14:00:35

标签: specflow

我想使用specflow进行系统测试 测试步骤应该是:

When I'm selecting "A"
Then "A" item(s) appear
When I'm selecting "B"
Then "A" and "B" item(s) appear
When I'm unselecting "A"
Then "A" item(s) appear

问题是2'nd When被specflow视为一种新方法。 你有谁知道解决方案是什么?

提前致谢!

1 个答案:

答案 0 :(得分:1)

你的场景对我来说使用语言很奇怪。这意味着您正在做某事,而不是执行,完成和行动。我认为When I select 'A'会更好。

无论如何,这些步骤定义应允许重复使用您的步骤:

[When(@"I'm selecting ""(.*)""")]
public void WhenIMSelecting(string p0)
{
    ScenarioContext.Current.Pending();
}

[Then(@"""(.*)"" item\(s\) appear")]
public void ThenItemSAppear(string p0)
{
    ScenarioContext.Current.Pending();
}

[Then(@"""(.*)"" and ""(.*)"" item\(s\) appear")]
public void ThenAndItemSAppear(string p0, string p1)
{
    ScenarioContext.Current.Pending();
}

[When(@"I'm unselecting ""(.*)""")]
public void WhenIMUnselecting(string p0)
{
    ScenarioContext.Current.Pending();
}

通常我更喜欢单引号来包装参数,因为它使正则表达式更容易使用,所以我会重写这样的场景:

When I select 'A'
Then 'A' item(s) are shown
When I select 'B'
Then 'A' and 'B' item(s) are shown
When I deselect 'A'
Then 'A' item(s) are shown

这将导致这些步骤定义:

[When(@"I select '(.*)'")]
public void WhenISelect(string p0)
{
    ScenarioContext.Current.Pending();
}

[Then(@"'(.*)' item\(s\) are shown")]
public void ThenItemSAreShown(string p0)
{
    ScenarioContext.Current.Pending();
}

[Then(@"'(.*)' and '(.*)' item\(s\) are shown")]
public void ThenAndItemSAreShown(string p0, string p1)
{
    ScenarioContext.Current.Pending();
}

[When(@"I deselect '(.*)'")]
public void WhenIDeselect(string p0)
{
    ScenarioContext.Current.Pending();
}

但显然你的域名在你的场景中使用你想要的任何语言: - )

相关问题