I would like to wrap a class into my Test so i don't need to write the class every time.
Story: I have a base class that takes a screenshot on a test fail. The function works well, but I have to wrap all the test with the class and that's what I want to avoid.
A test looks like this now.
[Fact]
public void TextEditor()
{
UITest(() =>
{
// Run Test
});
}
But my expected result is
[Fact]
public void TextEditor()
{
// Run Test
}
Is it possible to merge the class with the FACT attribute? or do you have an idea on how it could be done?
Base Class:
protected void UITest(Action action)
{
try
{
action();
}
catch (Exception ex)
{
var screenshotHandler = CurrentBrowser.Driver as ITakesScreenshot;
if (screenshotHandler != null)
{
var screenshot = screenshotHandler.GetScreenshot();
var path = CurrentBrowser.GetScreenshotLocation(
new StackFrame(1).GetMethod().Name);
var file = new FileInfo(path);
if (file.Directory != null && !file.Directory.Exists)
{
file.Directory.Create();
}
screenshot.SaveAsFile(path, ScreenshotImageFormat.Jpeg);
}
throw;
}
}