using AventStack.ExtentReports.Model; using OpenQA.Selenium; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using TechTalk.SpecFlow; namespace DemoBlazeAutomation.Utilities { public static class TakeScreenShot { public static String dir = AppDomain.CurrentDomain.BaseDirectory; public static string testResultPath = Path.Combine(dir, "Report"); //public static String testResultPath = dir.Replace(dir, "Report"); public static string addScreenshot(IWebDriver driver, ScenarioContext scenarioContext) { if (!Directory.Exists(testResultPath)) { Directory.CreateDirectory(testResultPath); } ITakesScreenshot takesScreenshot = (ITakesScreenshot)driver; Screenshot screenshot = takesScreenshot.GetScreenshot(); //string screenshotLocation = Path.Combine(testResultPath, scenarioContext.ScenarioInfo.Title + ".png"); //screenshot.SaveAsFile(screenshotLocation,ScreenshotImageFormat.Png); // Generar un nombre único para la captura de pantalla con la fecha y hora actual string timestamp = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss"); string screenshotLocation = Path.Combine(testResultPath, $"{scenarioContext.ScenarioInfo.Title}-{timestamp}.png"); screenshot.SaveAsFile(screenshotLocation); return screenshotLocation; } } }