4

我想登录一次,然后在关闭浏览器之前运行几个场景(比如说 7 个场景)。

我在每个场景中都使用了背景而不是给定我登录,但似乎每次运行场景时,它都会首先登录。

这减慢了我的测试速度。

我想做的事:

登录并在同一个浏览器窗口上运行多个场景,然后在完成后将其关闭。

4

1 回答 1

5

What you're looking for is Specflow Hooks.

https://github.com/techtalk/SpecFlow/wiki/Hooks

You won't be able to specify "logging in" as a step in the background, instead you'll tag each scenario that you need to be logged in for.

Example:

@alreadyLoggedIn
Scenario: user can see XYZ
    Given...

@alreadyLoggedIn
Scenario: user can see ABC
    Given...

You then just need to specify the code for "logging in" inside a method decorated with the BeforeFeature attribute. This method will only be run once for any scenario in a feature.

[BeforeFeature("alreadyLoggedIn")]
public void BeforeFeatureLoggedIn()
{
    // write code to log the person in
}

If you have different users/roles you need to test for, just create separate tags (ie adminAlreadyLoggedIn, salesAlreadyLoggedIn, etc)

Hope this gets you on the right path!

于 2013-01-24T14:03:42.357 回答