Fork me on GitHub

Specflow 的Scope和Tag的用法

Specflow 的Scope和Tag的用法

在Specflow中,step和step Definition 一般是多对一的关系,也就是说同一个step Definition可以被step多次复用,区别只是step中的参数不同, 比如:

step Definition

        [Then(@"I have see (.*) on UI")]
        public void GivenIHaveSeeOnUI(string text)
        {
        }

多个step

Then I have see a button on UI
Then I have see a form on UI

但是,有时step和step Definition也需要做到一对多 ,这时可以使用Scope和Tag来进行局部绑定。

也就是说,在step上加上Tag,它只会调用对应scope的step Definition,形式如下:

step

@Button
Then I have see a button on UI

step Definition

        [Then(@"I have see (.*) on UI")]
        [Scope(Tag = "Button")]
        public void GivenIHaveSeeOnUI(string text)
        {
        }
        [Then(@"I have see (.*) on UI")]
        [Scope(Tag = "Form")]
        public void GivenIHaveSeeOnUI(string text)
        {
        }

这样,Tag的step只会和对应的Definition绑定。

尤其注意,项目中一些比较容易重复的step Definition如果不加Scope,或者Step的scenario上忘记加Tag,很容易造成Multiple binding。

补充:

Scope除了可以限定Tag范围,也可以限定Feature和Scenario范围。比如:

针对scenario

Feature: Scope
Scenario: Dial in HK
	Given I have dialed number 132098
Scenario: Dial in mainland
	Given I have dialed number 132098

可以使用如下所示的Scope

[Scope(Scenario = "Dial in HK")]
[Scope(Scenario = "Dial in mainland")]

转自:https://blog.csdn.net/qq_42412416/article/details/80686748

posted @ 2021-09-29 22:12  浩然哉  阅读(164)  评论(0)    收藏  举报
/* 看板娘 */
浏览器标题切换
浏览器标题切换end