/// <summary>
        /// Captures a screenshot of the browser running on the Selenium Grid node as base64.
        /// Use an online coverter to view the actual image:  http://codebeautify.org/base64-to-image-converter
        /// </summary>
        /// <param name="driver">Remote driver</param>
        /// <param name="filePath">path where file will be written</param>
        /// <param name="fileName">the file name to be saved with datetime: fileName-yyyy-MM-dd_hh-mm-ss-tt.txt</param>
        /// <returns>name of the file containing the image data</returns>
        public static string CaptureScreenshot(RemoteWebDriverAugmented driver, string filePath = "", string fileName = "")
        {
            Screenshot ss         = ((ITakesScreenshot)driver).GetScreenshot();
            string     screenshot = ss.AsBase64EncodedString;

            byte[] screenshotAsByteArray = ss.AsByteArray;
            string file = "";

            if (filePath != "" && fileName != "")
            {
                fileName = string.Format(fileName + "-{0:yyyy-MM-dd_hh-mm-ss-tt}.txt", DateTime.Now);
                file     = string.Format("{0}\\{1}", filePath, fileName);
                System.IO.File.WriteAllText(file, ss.ToString());
            }
            return(file);
        }
        /// <summary>
        /// Captures a screenshot of the browser running on the Selenium Grid node as base64.
        /// Use an online coverter to view the actual image:  http://codebeautify.org/base64-to-image-converter
        /// </summary>
        /// <param name="driver">Remote driver</param>
        /// <param name="filePath">path where file will be written</param>
        /// <param name="fileName">the file name to be saved with datetime: fileName-yyyy-MM-dd_hh-mm-ss-tt.txt</param>
        /// <returns>name of the file containing the image data</returns>
        public static string CaptureScreenshot(RemoteWebDriverAugmented driver, string filePath = "", string fileName = "")
        {
            Screenshot ss   = ((ITakesScreenshot)driver).GetScreenshot();
            string     file = "";

            if (filePath != "" && fileName != "")
            {
                if (!System.IO.Directory.Exists(filePath))
                {
                    System.IO.Directory.CreateDirectory(filePath);
                }
                var newFileName = string.Format(fileName + "-{0:yyyy-MM-dd_hh-mm-ss-tt}.txt", DateTime.Now);
                file = string.Format("{0}\\{1}", filePath, newFileName);
                System.IO.File.WriteAllText(file, ss.ToString());
            }
            return(file);
        }
Esempio n. 3
0
 public static string CaptureScreenShot(IWebDriver driver, string methodName)
 {
     try
     {
         if (driver == null)
         {
             return("");
         }
         if (driver is RemoteWebDriverAugmented &&
             (ConfigurationManager.AppSettings["CaptureScreenshot"] == "true") &&
             (ConfigurationManager.AppSettings["ScreenShotPath"] != ""))
         {
             string filePath = ConfigurationManager.AppSettings["ScreenShotPath"];
             return(RemoteWebDriverAugmented.CaptureScreenshot(driver as RemoteWebDriverAugmented, filePath, methodName));
         }
         return("");
     }
     catch { return(""); }
 }