title: SpecFlow AfterScenario execute each time with total number of scenarios count
body: <p>I have created a base class for taking screenshot for failed test cases in C#. I have used specflow with MSTest for automation testing. However, the problem is when a scenarios fails system runs the below <code>AfterScenario</code> method for total numbers of scenario counts. For example, I have 40 scenarios in my current project, let say scenario# 1 is running and after scenarion#1 execution <code>AfterScenario</code> method will call but it is calling for 40 times, for each time scenario.    </p>
  
  <p>Base class code</p>
  
  <pre><code>[Binding]
  public abstract class TakeScreenshot : Steps
  {
      [AfterScenario]
      public void AfterWebTest()
      {
          if (ScenarioContext.Current["run"]=="0")
          {
  
              if (ScenarioContext.Current.TestError != null)
              {
                  TakeScenarioScreenshot(Tools.driver);
              }
              ScenarioContext.Current["run"] = "1";
          }
      }
  
      private void TakeScenarioScreenshot(IWebDriver driver)
      {
          try
          {            
              string fileNameBase = string.Format("{0}_{1}",
              DateTime.Now.ToString("yyMMddHHmmssFFF") , ScenarioContext.Current.ScenarioInfo.Title);
  
              var artifactDirectory = Path.Combine(Directory.GetCurrentDirectory(), "testresults");
              if (!Directory.Exists(artifactDirectory))
                  Directory.CreateDirectory(artifactDirectory);
  
              string pageSource = driver.PageSource;
              string sourceFilePath = Path.Combine(artifactDirectory, fileNameBase + "_source.html");
              File.WriteAllText(sourceFilePath, pageSource, Encoding.UTF8);
              ITakesScreenshot takesScreenshot = driver as ITakesScreenshot;
  
              if (takesScreenshot != null)
              {
                  var screenshot = takesScreenshot.GetScreenshot();
                  string screenshotFilePath = Path.Combine(artifactDirectory, fileNameBase + "_screenshot.png");
                  screenshot.SaveAsFile(screenshotFilePath, ImageFormat.Png);
              }
          }
          catch (Exception ex)
          {
              Console.WriteLine("Error while taking screenshot: {0}", ex);
          }
      }
  }
  </code></pre>
  
  <p>This is my test class where I am inheriting <code>TakeScreenshot</code> class</p>
  
  <pre><code>[Binding]
  public class CheckTwoNumberAreEqual : TakeScreenshot
  {
  
      [Given(@"Check two numbers are same")]
      public void GivenChecktwonumbersaresame()
      {
          Assert.AreEqual(2, 3);
      }
  }
  
  
  [Binding]
  public class TestAddNewUser : TakeScreenshot
  {
  
      [Given(@"Add two numbers and check answer")]
      public void GivenAddtwonumbersandcheckanswer()
      {
          int a=2+3;
          Assert.AreEqual(2, a);
      }
  }
  </code></pre>
  
  <p>Is there anyway to prevent <code>AfterScenario</code> execution for n (scenario count)?</p>