Пример #1
0
        /// <summary>
        /// Saves screenshot, attaches screenshot and already saved results file to existing bug
        /// </summary>
        /// <param name="ecId">Element context id</param>
        /// <param name="rect">Bounding rect of element for screenshot</param>
        /// <param name="a11yBugId">Bug's A11y-specific id</param>
        /// <param name="bugId">Bug's server-side id</param>
        /// <param name="snapshotFileName">saved snapshot file name</param>
        /// <returns>Success or failure</returns>
        private static async Task <bool> AttachBugDataInternal(Guid ecId, Rectangle?rect, string a11yBugId, int bugId, string snapshotFileName)
        {
            var imageFileName      = GetTempFileName(".png");
            var filedBugReproSteps = await BugReporter.GetExistingBugDescriptionAsync(bugId).ConfigureAwait(false);

            if (GuidsMatchInReproSteps(a11yBugId, filedBugReproSteps))
            {
                int?      attachmentResponse = null;
                const int maxAttempts        = 2;

                // Attempt to attach the results file twice
                for (int attempts = 0; attempts < maxAttempts; attempts++)
                {
                    try
                    {
                        attachmentResponse = await BugReporter.AttachTestResultToBugAsync(snapshotFileName, bugId).ConfigureAwait(false);

                        break;
                    }
                    catch (Exception ex)
                    {
                        if (!ex.IsTransient())
                        {
                            throw;
                        }
                    }
                }

                // Save local screenshot for HTML preview in browser
                GetScreenShotForBugDescription(ecId, rect)?.Save(imageFileName);

                var htmlDescription = "";

                if (imageFileName != null)
                {
                    var imgUrl = await BugReporter.AttachScreenshotToBugAsync(imageFileName, bugId).ConfigureAwait(false);

                    htmlDescription = $"<img src=\"{imgUrl}\" alt=\"screenshot\"></img>";
                }

                var scrubbedHTML = RemoveInternalHTML(filedBugReproSteps, a11yBugId) + htmlDescription;
                await BugReporter.ReplaceBugDescriptionAsync(scrubbedHTML, bugId).ConfigureAwait(false);

                File.Delete(snapshotFileName);
                if (imageFileName != null)
                {
                    File.Delete(imageFileName);
                }

                // if the bug failed to attach, return false
                return(attachmentResponse != null);
            }
            else
            {
                return(false);
            }
        }
Пример #2
0
        /// <summary>
        /// Opens bug filing window with prepopulated data
        /// </summary>
        /// <param name="bugInfo">Dictionary of bug info from with which to populate the bug</param>
        /// <param name="connection">connection info</param>
        /// <param name="onTop">Is window always on top</param>
        /// <param name="zoomLevel">Zoom level for bug file window</param>
        /// <param name="updateZoom">Callback to update configuration with zoom level</param>
        /// <returns></returns>
        public static (int?bugId, string newBugId) FileNewBug(BugInformation bugInfo, IConnectionInfo connection, bool onTop, int zoomLevel, Action <int> updateZoom)
        {
            if (!BugReporter.IsEnabled)
            {
                return(null, string.Empty);
            }

            try
            {
                // Create a A11y-specific Guid for this bug to verify that we are uploading
                //  attachment to the correct bug
                var a11yBugId = bugInfo.InternalGuid.HasValue
                    ? bugInfo.InternalGuid.Value.ToString()
                    : string.Empty;
                Uri url   = BugReporter.CreateBugPreviewAsync(connection, bugInfo).Result;
                var bugId = FileBugWindow(url, onTop, zoomLevel, updateZoom);

                if (bugId.HasValue)
                {
                    if (bugInfo.RuleForTelemetry != null)
                    {
                        Logger.PublishTelemetryEvent(TelemetryAction.Bug_Save, new Dictionary <TelemetryProperty, string>
                        {
                            { TelemetryProperty.RuleId, bugInfo.RuleForTelemetry },
                            { TelemetryProperty.UIFramework, bugInfo.UIFramework ?? string.Empty },
                        });
                    }
                    else // if the bug is coming from the hierarchy tree, it will not have ruleID or UIFramework
                    {
                        Logger.PublishTelemetryEvent(TelemetryAction.Bug_Save);
                    }
                }
                else
                {
                    Logger.PublishTelemetryEvent(TelemetryAction.Bug_Cancel);
                }
                return(bugId, a11yBugId);
            }
            catch
            {
                return(null, string.Empty);
            }
        }