diff --git a/Ginger/GingerCoreNET/Logger/WebReportGenerator.cs b/Ginger/GingerCoreNET/Logger/WebReportGenerator.cs index 454002b573..f8ace5c8ef 100644 --- a/Ginger/GingerCoreNET/Logger/WebReportGenerator.cs +++ b/Ginger/GingerCoreNET/Logger/WebReportGenerator.cs @@ -77,11 +77,6 @@ public LiteDbRunSet RunNewHtmlReport(string reportResultsFolderPath = "", string IoHandler.Instance.TryFolderDelete(rootFolder); } IoHandler.Instance.CopyFolderRec(clientAppFolderPath, ReportrootPath, true); - - if(!Directory.Exists(Path.Combine(ReportrootPath, "assets", "screenshots"))) - { - Directory.CreateDirectory(Path.Combine(ReportrootPath, "assets", "screenshots")); - } } } catch (Exception ex) @@ -98,9 +93,9 @@ public LiteDbRunSet RunNewHtmlReport(string reportResultsFolderPath = "", string { return lightDbRunSet; } - IoHandler.Instance.DeleteFoldersData(Path.Combine(ReportrootPath, "assets", "Execution_Data")); - IoHandler.Instance.DeleteFoldersData(Path.Combine(ReportrootPath, "assets", "screenshots")); - IoHandler.Instance.DeleteFoldersData(Path.Combine(ReportrootPath, "assets", "artifacts")); + + CleanReportFolders(ReportrootPath); + LiteDbManager dbManager = new LiteDbManager(new ExecutionLoggerHelper().GetLoggerDirectory(WorkSpace.Instance.Solution.LoggerConfigurations.CalculatedLoggerFolder)); lightDbRunSet = dbManager.GetLatestExecutionRunsetData(runSetGuid); lightDbRunSet.SetAllIterationElementsRecursively(WorkSpace.Instance.SolutionRepository.GetAllRepositoryItems().First(r => r.IsDefault).ShowAllIterationsElements); @@ -116,6 +111,48 @@ public LiteDbRunSet RunNewHtmlReport(string reportResultsFolderPath = "", string return lightDbRunSet; } + /// + /// Cleans the report folders by deleting data in specified subdirectories. + /// If the directories do not exist, they are created. + /// + /// The root path of the report folders. + private static void CleanReportFolders(string ReportrootPath) + { + try + { + try + { + IoHandler.Instance.DeleteFoldersData(Path.Combine(ReportrootPath, "assets", "Execution_Data")); + } + catch (DirectoryNotFoundException) + { + Directory.CreateDirectory(Path.Combine(ReportrootPath, "assets", "Execution_Data")); + } + + try + { + IoHandler.Instance.DeleteFoldersData(Path.Combine(ReportrootPath, "assets", "screenshots")); + } + catch (DirectoryNotFoundException) + { + Directory.CreateDirectory(Path.Combine(ReportrootPath, "assets", "screenshots")); + } + + try + { + IoHandler.Instance.DeleteFoldersData(Path.Combine(ReportrootPath, "assets", "artifacts")); + } + catch (DirectoryNotFoundException) + { + Directory.CreateDirectory(Path.Combine(ReportrootPath, "assets", "artifacts")); + } + } + catch (Exception ex) + { + Reporter.ToLog(eLogLevel.ERROR, "Error while cleaning up reports folder", ex); + } + } + private void RemoveSkippedItems(LiteDbRunSet liteDbRunSet) { HTMLReportConfiguration _HTMLReportConfig = WorkSpace.Instance.SolutionRepository.GetAllRepositoryItems().FirstOrDefault(x => (x.IsDefault == true));