質問

I want to do execute [AfterTestRun] attribute marked method after test fails of [Binding] attribute marked class. How can I achieve something like:

[Binding]
public class TestsRunner
{
   [AfterTestFails] // There is no such attribute
   public static void DoStuff()
   {

   }
}

or

[Binding]
public class TestsRunner
{
   [AfterTestRun]
   public static void DoStuff()
   {
        if(ScenarioContext.Current.TestHasFailed) // There is no such property
        {
            // Do stuff
        }  
   }
}
役に立ちましたか?

解決

After reading some documentation here I have found the next solution:

[Binding]
public class TestsRunner
{
    [AfterScenario]
    public void TakeScreenShot()
    {
        if(ScenarioContext.Current.TestError != null)
        {
            WebBrowser.TakeScreenShot(); // Your custom browser take screenshot method 
        }
    }
}

他のヒント

As you say, these things don't exist. That's probably because you are trying to do something with SpecFlow that it has not been designed to do.

Don't forget all SpecFlow does is to bridge the gap between what a Unit testing framework (like NUnit, XUnit or MSTest) does and supporting plain text scenarios in a Gherkin format.

If you want to do these things that relate to the running of the test, then you probably need to look at the Unit test framework, or more likely, build your own test runner.

BTW, what is it that you actually want to do?

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top