/// <summary> /// Saves the screenshot. /// </summary> /// <param name="errorDetail">The error detail.</param> /// <param name="folder">The folder.</param> /// <param name="title">The title.</param> public void SaveScreenshot(ErrorDetail errorDetail, string folder, string title) { var fileName = string.Format(CultureInfo.CurrentCulture, "{0}_{1}_{2}.png", title, errorDetail.DateTime.ToString("yyyy-MM-dd HH-mm-ss-fff", CultureInfo.CurrentCulture), "browser"); var correctFileName = Path.GetInvalidFileNameChars().Aggregate(fileName, (current, c) => current.Replace(c.ToString(CultureInfo.CurrentCulture), string.Empty)); correctFileName = Regex.Replace(correctFileName, "[^0-9a-zA-Z._]+", "_"); correctFileName = NameHelper.ShortenFileName(folder, correctFileName, "_", 255); var filePath = Path.Combine(folder, correctFileName); try { errorDetail.Screenshot.SaveAsFile(filePath, ImageFormat.Png); Logger.Error(CultureInfo.CurrentCulture, "Test failed: screenshot saved to {0}.", filePath); Logger.Info(CultureInfo.CurrentCulture, "##teamcity[publishArtifacts '{0}']", filePath); } catch (NullReferenceException) { Logger.Error("Test failed but was unable to get webdriver screenshot."); } }
/// <summary> /// Takes the screenshot. /// </summary> /// <param name="errorDetail">The error detail.</param> /// <param name="title">The title.</param> public void SaveScreenshot(ErrorDetail errorDetail, string title) { var fileName = string.Format(CultureInfo.CurrentCulture, "{0}_{1}.png", title, errorDetail.DateTime.ToString("yyyy-MM-dd HH-mm-ss-fff", CultureInfo.CurrentCulture)); var correctFileName = Path.GetInvalidFileNameChars().Aggregate(fileName, (current, c) => current.Replace(c.ToString(CultureInfo.CurrentCulture), string.Empty)); var filePath = Path.Combine(Environment.CurrentDirectory, correctFileName); errorDetail.Screenshot.SaveAsFile(filePath, ImageFormat.Png); Console.Error.WriteLine("Test failed: screenshot saved to {0}.", filePath); }