Ejemplo n.º 1
0
        /// <summary>
        /// Takes a screenshot of the whole desktop.
        /// </summary>
        /// <param name="baseFileName">Base file name, will be combined with the screenshot directory, "_Desktop" and the file ending to the final file path.</param>
        public void TakeDesktopScreenshot([NotNull] string baseFileName)
        {
            ArgumentUtility.CheckNotNullOrEmpty("baseFileName", baseFileName);

            var fullFilePath = ScreenshotCapturerFileNameGenerator.GetFullScreenshotFilePath(_screenshotDirectory, baseFileName, "Desktop", "png");

            s_log.InfoFormat("Saving screenshot of desktop to '{0}'.", fullFilePath);

            try
            {
                // Todo RM-6337: Capture the mouse cursor as well.
                using (var bitmap = new Bitmap(s_screenSize.Width, s_screenSize.Height))
                {
                    using (var gfx = Graphics.FromImage(bitmap))
                    {
                        gfx.CopyFromScreen(0, 0, 0, 0, s_screenSize);
                        bitmap.Save(fullFilePath, ImageFormat.Png);
                    }
                }
            }
            catch (Exception ex)
            {
                s_log.Error(string.Format("Could not save screenshot to '{0}'.", fullFilePath), ex);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Takes a screenshot of the browser window by using the web driver's screenshot interface.
        /// </summary>
        /// <param name="baseFileName">Base file name, will be combined with the screenshot directory, "_Browser" and the file ending to the final file path.</param>
        /// <param name="browser">The browser session of which the screenshot should be taken.</param>
        public void TakeBrowserScreenshot([NotNull] string baseFileName, [NotNull] BrowserSession browser)
        {
            ArgumentUtility.CheckNotNullOrEmpty("baseFileName", baseFileName);
            ArgumentUtility.CheckNotNull("browser", browser);

            var fullFilePath = ScreenshotCapturerFileNameGenerator.GetFullScreenshotFilePath(_screenshotDirectory, baseFileName, "Browser", "png");

            s_log.InfoFormat("Saving screenshot of browser to '{0}'.", fullFilePath);

            try
            {
                browser.SaveScreenshot(fullFilePath, ImageFormat.Png);
            }
            catch (Exception ex)
            {
                s_log.Error(string.Format("Could not save screenshot to '{0}'.", fullFilePath), ex);
            }
        }