Wrap specflow scenario within try-catch



  • I have been running into a problem with the C# selenium bindings decribed here: https://stackoverflow.com/questions/22322596/ where a timeout exception is thrown occasionally while running my selenium tests. The tests are all written using spec flow, and I would love to have a way to catch that exception and have the test return as Inconclusive (instead of failed) for that particular exception. Does anyone know of a way to wrap each spec flow scenario in a try catch block? Is that possible to do? Or a way to automatically catch this exception without having to wrap each individual step definition in a try catch block? Thanks!



  • I found a workaround for this issue where I can check for the exception after each step using the [AfterStep] binding. This works for me, and tests that failed are now marked as inconclusive: [AfterStep] public void check() { var exception = ScenarioContext.Current.TestError; if (exception is WebDriverException && exception.Message.Contains("The HTTP request to the remote WebDriver server for URL ")) { Assert.Inconclusive(exception.Message); } } Hopefully someone finds this helpful!



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2