コード例 #1
0
        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}");
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        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);
        }