using OpenQA.Selenium.PhantomJS;
using OpenQA.Selenium.Support.UI;
private PhantomJSDriver driver;
driver = new PhantomJSDriver(@"\\bingdat53\TemplateData\CustomCode\URLGen\URL Generator\URL Generator");
public bool ScreenshotDiff(string curl, string turl)
var cbytes = GetBytesFromScreenshot(curl, ConfigManager.ControlXpath);
var tbytes = GetBytesFromScreenshot(turl, ConfigManager.TreatXpath);
return !cbytes.SequenceEqual(tbytes);
private byte[] GetBytesFromScreenshot(string url, string xpath)
driver.Navigate().GoToUrl(url);
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
wait.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(
By.XPath(ConfigManager.ControlXpath)));
IWebElement element = driver.FindElement(By.XPath(xpath));
var bytes = driver.GetScreenshot().AsByteArray;
using (var ms = new MemoryStream(bytes))
var cropArea = new Rectangle(element.Location, element.Size);
var newbmp = bmp.Clone(cropArea, bmp.PixelFormat);
return (byte[])converter.ConvertTo(newbmp, typeof(byte[]));