I want to have a method in the framework which can take screenshots during my tests execution. Screenshots may be added to the summary reports for better understanding of a test execution flow. The IWebDriver can take screenshots, but I want all its actions being wrapped into a custom method for easier usage. I decided to implement the method as an extension method of IWebDriver interface because it will allow invoking the method such as if the IWebDriver actually had this method compiled inside its own native code.
Extension methods must be static and they must be located in a static class. I added new class to the Mapping project and named it Extensions.sc for the purpose.
For my screenshot-making method I have to add references to the following libraries:
● Selenium tool files: Selenium.WebDriverBackedSelenium.dll, ThoughtWorks.Selenium.Core.dll, WebDriver.dll, WebDriver.Support.dll;
● project Logger: file Logger.dll located in Logger/bin/Debug folder;
● reference to System.Drawing library
Below is the method that takes screenshots:
Considering that taking a screenshot has a sense only for reporting, the best way for using the method is passing it as a parameter to the Report class methods which log tests execution events.
So, I built the Mapping project and added the reference to it in the Tests project.
Now TakeScreenshot method may be invoked in the tests: