Pregunta

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
        }  
   }
}
¿Fue útil?

Solución

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 
        }
    }
}

Otros consejos

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?

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top