Beispiel #1
0
        /// <summary>
        /// Automatically embeds a video of the test run from this point forward when a trigger event occurs.
        /// </summary>
        /// <remarks>
        /// <para>
        /// Recording a screen capture video can be very CPU and space intensive particularly
        /// when running tests on a single-core CPU.  We recommend calling
        /// <see cref="AutoEmbedRecording(TriggerEvent, string, CaptureParameters, double)" /> with
        /// a <see cref="CaptureParameters.Zoom" /> factor of 0.25 or less and a frame rate
        /// of no more than 5 to 10 frames per second.
        /// </para>
        /// <para>
        /// If screenshots cannot be captured, the method will embed a warning message to that effect.
        /// </para>
        /// </remarks>
        /// <param name="triggerEvent">The trigger event.</param>
        /// <param name="attachmentName">The name to give the video attachment, or null to assign one automatically.</param>
        /// <param name="parameters">The capture parameters.</param>
        /// <param name="framesPerSecond">The number of frames per second to capture.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="parameters"/> is null.</exception>
        /// <seealso cref="TestContext.AutoExecute(TriggerEvent, Gallio.Common.GallioAction)"/>
        public static void AutoEmbedRecording(TriggerEvent triggerEvent, string attachmentName, CaptureParameters parameters, double framesPerSecond)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            TestContext context = TestContext.CurrentContext;

            if (context != null)
            {
                try
                {
                    ScreenRecorder recorder = StartRecording(parameters, framesPerSecond);

                    context.AutoExecute(triggerEvent, () =>
                    {
                        recorder.Stop();

                        if (recorder.Video.FrameCount != 0)
                        {
                            context.LogWriter.Default.EmbedVideo(attachmentName, recorder.Video);
                        }
                    }, recorder.Dispose);
                }
                catch (ScreenshotNotAvailableException ex)
                {
                    context.AutoExecute(triggerEvent, () =>
                    {
                        context.LogWriter.Default.WriteException(ex, "Recording not available.");
                    });
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Automatically embeds a screenshot when a trigger event occurs.
        /// </summary>
        /// <remarks>
        /// <para>
        /// If screenshots cannot be captured, the method will embed a warning message to that effect.
        /// </para>
        /// </remarks>
        /// <param name="triggerEvent">The trigger event.</param>
        /// <param name="attachmentName">The name to give to the image attachment, or null to assign one automatically.</param>
        /// <param name="parameters">The capture parameters.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="parameters"/> is null.</exception>
        /// <seealso cref="TestContext.AutoExecute(TriggerEvent, Gallio.Common.GallioAction)"/>
        public static void AutoEmbedScreenshot(TriggerEvent triggerEvent, string attachmentName, CaptureParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            TestContext context = TestContext.CurrentContext;

            if (context != null)
            {
                context.AutoExecute(triggerEvent, () =>
                {
                    try
                    {
                        Bitmap bitmap = Screenshot(parameters);
                        context.LogWriter.Default.EmbedImage(attachmentName, bitmap);
                    }
                    catch (ScreenshotNotAvailableException ex)
                    {
                        context.LogWriter.Default.WriteException(ex, "Screenshot not available.");
                    }
                });
            }
        }