Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using System;
using System.Drawing.Imaging;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
namespace SomeNamespace
{
[TestClass]
public class BaseTest
{
public ScreenShotRemoteWebDriver Driver { get; set; }
public TestContext TestContext { get; set; }
[TestInitialize]
public void BaseTestInitialize()
{
this.Driver = DriverFactory.GetDriver();
}
[TestCleanup]
public void BaseTestCleanup()
{
if (this.TestContext.CurrentTestOutcome == UnitTestOutcome.Failed)
{
var filename = System.IO.Path.GetTempPath() + DateTime.Now.ToString("yy-MM-dd-HH-mm-ss-FFF") + "-" + this.GetType().Name +"-" + this.TestContext.TestName + ".jpg";
((ITakesScreenshot)this.Driver).GetScreenshot().SaveAsFile(filename, ImageFormat.Jpeg);
this.TestContext.AddResultFile(filename);
}
this.Driver.Quit();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.