I recently wrote a little function that takes a screenshot at the end of a test if it has errored. What sounded very simple at the start turned out to be quite a bit of work, and quite a few lines of code to handle certain scenarios! It's now over 50 lines of code! I'll start with what I had at the beginning, this was to simply take a screenshot in the working directory, we are using SpecFlow and Selenium to run the tests, so we are going to check if the ScenarioContext.Current.TestError isn't null, if it is, then using Selenium, take a screenshot (note the below code is a simplified version of what I had at the beginning). [AfterScenario] public static void TakeScreenShotOnError() { if (ScenarioContext.Current.TestError == null) return; var screenshotDriver = Driver as ITakesScreenshot; if (screenshotD...
Documenting my thoughts on life in the world of Testing
Comments
Post a Comment