【问题标题】:Want to execute background tag only once per feature file with multiple scenarios in specflow C#想要在 Specflow C# 中对具有多个场景的每个功能文件只执行一次背景标记
【发布时间】:2021-08-24 19:40:17
【问题描述】:

下面是代码:

Background: Navigate to mail from inbox
Given I login into gmail as valid user
When I click on mail from Inbox
Then mail should be open

Scenario: Delete mail from Inbox
When I open mail from Inbox page
And I click on Delete icon
Then mail should be deleted

Scenario: Sent mail from Draft box
When I open mail from Draft box
And I click on Sent button
Then mail should be sent

所以在这里我希望这个功能文件的背景应该只执行一次。一旦后台步骤被执行并导航到收件箱页面,那么场景应该一个接一个地执行。执行该功能文件中的所有场景后,应关闭浏览器。

现在它正在执行后台步骤,然后移动到执行它并在同一个浏览器上的第一个场景,它仍然从后台执行步骤。

【问题讨论】:

    标签: hook bdd specflow gherkin scenarios


    【解决方案1】:

    您正在寻找带有scopingBeforeFeature 挂钩到这一功能文件。

    所以你需要这样的钩子:

    
    [BeforeFeature()]
    [Scope(Feature = "feature title")]
    public static void SetupInbox()
    {
    /// your automation code
    }
    

    每个功能文件只执行一次。

    另外请注意,根据您的测试运行程序,场景执行的顺序与您的功能文件中的顺序不同。

    此外,我们非常不鼓励您编写相互依赖的场景。与单元测试一样,场景应该能够自行执行。


    全面披露:我是 SpecFlow 的社区经理和长期贡献者

    【讨论】:

    • 虽然我知道这一点,但无法说服经理,因此我想给出一些有效的证据。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-03-10
    • 1970-01-01
    • 1970-01-01
    • 2019-04-06
    • 2015-12-26
    • 1970-01-01
    • 2021-07-08
    相关资源
    最近更新 更多