コード例 #1
0
        /// <summary>
        /// Builds the path of the file without the extension.
        /// </summary>
        /// <param name="screenshotInfo">The screenshot information.</param>
        /// <returns>The file path without the extension.</returns>
        protected override string BuildFilePath(ScreenshotInfo screenshotInfo)
        {
            if (FilePathBuilder != null)
            {
                return(FilePathBuilder(screenshotInfo));
            }

            string folderPath = FolderPathBuilder?.Invoke()
                                ?? $@"Logs\{AtataContext.BuildStart:yyyy-MM-dd HH_mm_ss}\{AtataContext.Current.TestName}";

            folderPath = folderPath.SanitizeForPath();

            string fileName = FileNameBuilder?.Invoke(screenshotInfo)
                              ?? $"{screenshotInfo.Number:D2} - {screenshotInfo.PageObjectFullName}{screenshotInfo.Title?.Prepend(" - ")}";

            fileName = fileName.SanitizeForFileName();

            return(Path.Combine(folderPath, fileName));
        }
コード例 #2
0
        /// <summary>
        /// Formats the screenshot file path using path variables.
        /// </summary>
        /// <param name="format">The format.</param>
        /// <param name="screenshotInfo">The screenshot information.</param>
        /// <returns>The formatted file path format.</returns>
        public static string FormatPath(string format, ScreenshotInfo screenshotInfo)
        {
            if (format.Contains('{'))
            {
                var screenshotVariables = new Dictionary <string, object>
                {
                    ["screenshot-number"]             = screenshotInfo.Number,
                    ["screenshot-title"]              = screenshotInfo.Title,
                    ["screenshot-pageobjectname"]     = screenshotInfo.PageObjectName,
                    ["screenshot-pageobjecttypename"] = screenshotInfo.PageObjectTypeName,
                    ["screenshot-pageobjectfullname"] = screenshotInfo.PageObjectFullName
                };

                return(AtataContext.Current.FillTemplateString(format, screenshotVariables));
            }
            else
            {
                return(format);
            }
        }
コード例 #3
0
        /// <summary>
        /// Takes the specified screenshot.
        /// </summary>
        /// <param name="screenshotInfo">The screenshot information.</param>
        public void Take(ScreenshotInfo screenshotInfo)
        {
            string filePath = BuildFilePath(screenshotInfo);

            filePath  = filePath.SanitizeForPath();
            filePath += ImageFormat.GetExtension();

            if (!Path.IsPathRooted(filePath))
            {
                filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, filePath);
            }

            string folderPath = Path.GetDirectoryName(filePath);

            if (!Directory.Exists(folderPath))
            {
                Directory.CreateDirectory(folderPath);
            }

            screenshotInfo.Screenshot.SaveAsFile(filePath, ImageFormat);

            AtataContext.Current.Log.Info($"Screenshot saved to file \"{filePath}\"");
        }
コード例 #4
0
ファイル: LogManager.cs プロジェクト: atata-framework/atata
        public void Screenshot(string title = null)
        {
            if (Driver == null || !screenshotConsumers.Any())
                return;

            try
            {
                screenshotNumber++;

                string logMessage = $"Take screenshot #{screenshotNumber}";

                if (!string.IsNullOrWhiteSpace(title))
                    logMessage += $" {title}";

                Info(logMessage);

                ScreenshotInfo screenshotInfo = new ScreenshotInfo
                {
                    Screenshot = Driver.TakeScreenshot(),
                    Number = screenshotNumber,
                    Title = title,
                    PageObjectName = AtataContext.Current.PageObject.ComponentName,
                    PageObjectFullName = AtataContext.Current.PageObject.ComponentFullName
                };

                foreach (IScreenshotConsumer screenshotConsumer in screenshotConsumers)
                {
                    try
                    {
                        screenshotConsumer.Take(screenshotInfo);
                    }
                    catch (Exception e)
                    {
                        Error("Screenshot failed", e);
                    }
                }
            }
            catch (Exception e)
            {
                Error("Screenshot failed", e);
            }
        }
コード例 #5
0
 /// <summary>
 /// Builds the path of the file without the extension.
 /// </summary>
 /// <param name="screenshotInfo">The screenshot information.</param>
 /// <returns>The file path without the extension.</returns>
 protected abstract string BuildFilePath(ScreenshotInfo screenshotInfo);
コード例 #6
0
 protected virtual string BuildDefaultFileName(ScreenshotInfo screenshotInfo) =>
 $"{screenshotInfo.Number:D2} - {screenshotInfo.PageObjectFullName}{screenshotInfo.Title?.Prepend(" - ")}";