Skip to content

Instantly share code, notes, and snippets.

@FriendlyTester
Created March 6, 2014 11:09
Show Gist options
  • Save FriendlyTester/9387475 to your computer and use it in GitHub Desktop.
Save FriendlyTester/9387475 to your computer and use it in GitHub Desktop.
IWebDriver Screenshot Extension
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
using System;
using System.Drawing.Imaging;
namespace Richard.WebDriverExtensions
{
public static class WebDriverExtensions
{
/// <summary>
/// Take a screenshot of the current page
/// </summary>
/// <param name="driver"></param>
/// <param name="FileLocationName">Full directory plus the file name and format, e.g C:\Temp\Image.jpeg</param>
/// <param name="imageFormat">System image format, I tend to stick to jpeg</param>
public static void TakeScreenshot(this IWebDriver driver, string FileLocationName, ImageFormat imageFormat)
{
((ITakesScreenshot)driver).GetScreenshot().SaveAsFile(FileLocationName, imageFormat);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment