Skip to content

Instantly share code, notes, and snippets.

@arex1337
Created July 6, 2013 09:46
Show Gist options
  • Save arex1337/5939414 to your computer and use it in GitHub Desktop.
Save arex1337/5939414 to your computer and use it in GitHub Desktop.
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