public void SetOptions(FileInfo screenshot, ScreenshotOptions options) { var fileName = Path .Combine(screenshot.DirectoryName, Path.GetFileNameWithoutExtension(screenshot.FullName) + ".metadata") .GetNormalizedLongPath(); File.WriteAllText(fileName, $"IgnoreInSnapshotCompare={options.IgnoreInSnapshotCompare}"); }
public ScreenshotInfo TakeScreenshot(string stepName, ScreenshotOptions options) { if (_app == null) { Console.WriteLine($"Skipping TakeScreenshot _app is not available"); return(null); } var title = $"{TestContext.CurrentContext.Test.Name}_{stepName}" .Replace(" ", "_") .Replace(".", "_") .Replace("(", "") .Replace(")", "") .Replace("\"", "") .Replace(",", "_") .Replace("__", "_"); var fileInfo = _app.Screenshot(title); var fileNameWithoutExt = Path.GetFileNameWithoutExtension(fileInfo.Name); if (fileNameWithoutExt != title) { var destFileName = Path .Combine(Path.GetDirectoryName(fileInfo.FullName), title + Path.GetExtension(fileInfo.Name)) .GetNormalizedLongPath(); if (File.Exists(destFileName)) { File.Delete(destFileName); } File.Move(fileInfo.FullName, destFileName); TestContext.AddTestAttachment(destFileName, stepName); fileInfo = new FileInfo(destFileName); } else { TestContext.AddTestAttachment(fileInfo.FullName, stepName); } if (options != null) { SetOptions(fileInfo, options); } return(new ScreenshotInfo(fileInfo, stepName)); }
public FileInfo TakeScreenshot(string stepName, ScreenshotOptions options) { var title = $"{TestContext.CurrentContext.Test.Name}_{stepName}" .Replace(" ", "_") .Replace(".", "_"); var fileInfo = _app.Screenshot(title); var fileNameWithoutExt = Path.GetFileNameWithoutExtension(fileInfo.Name); if (fileNameWithoutExt != title) { var destFileName = Path .Combine(Path.GetDirectoryName(fileInfo.FullName), title + Path.GetExtension(fileInfo.Name)) .GetNormalizedLongPath(); if (File.Exists(destFileName)) { File.Delete(destFileName); } File.Move(fileInfo.FullName, destFileName); TestContext.AddTestAttachment(destFileName, stepName); fileInfo = new FileInfo(destFileName); } else { TestContext.AddTestAttachment(fileInfo.FullName, stepName); } if (options != null) { var fileName = Path .Combine(fileInfo.DirectoryName, Path.GetFileNameWithoutExtension(fileInfo.FullName) + ".metadata") .GetNormalizedLongPath(); File.WriteAllText(fileName, $"IgnoreInSnapshotCompare={options.IgnoreInSnapshotCompare}"); } return(fileInfo); }