Esempio n. 1
0
        public void GetTestOutputFileName()
        {
            var finishDateTime     = new DateTime(2018, 10, 25, 5, 45, 55);
            var testOutputFileName = NamesProvider.GetTestOutputFileName(finishDateTime);

            Assert.AreEqual($"test_output_{finishDateTime:yyyyMMdd_HHmmssfff}.json", testOutputFileName);
        }
Esempio n. 2
0
 public static List <GhprTestCase> GetTestRunsListFromFile(string path, ILogger logger)
 {
     try
     {
         var xmlString = File.ReadAllText(path);
         var doc       = new XmlDocument();
         doc.LoadXml(xmlString);
         XmlNode node         = doc.DocumentElement;
         var     testCases    = node?.SelectNodes(".//*/test-case")?.Cast <XmlNode>().ToList();
         var     list         = testCases?.Select(n => TestRunHelper.GetTestAndOutput(n, logger)).ToList() ?? new List <GhprTestCase>();
         var     testSuites   = node?.SelectNodes(".//*/test-suite")?.Cast <XmlNode>().ToList() ?? new List <XmlNode>();
         var     testInfoDtos = list.Select(d => d.GhprTestRun.TestInfo).ToList();
         foreach (var testSuite in testSuites)
         {
             var testOutputs = TestRunHelper.GetOutputsFromSuite(testSuite, testInfoDtos);
             foreach (var output in testOutputs)
             {
                 var test = list.FirstOrDefault(t => t.GhprTestRun.TestInfo.Guid == output.Key.Guid &&
                                                t.GhprTestRun.TestInfo.Finish == output.Key.Finish) ?? new GhprTestCase();
                 test.GhprTestOutput.Output = output.Value.Output;
                 test.GhprTestOutput.TestOutputInfo.ItemName =
                     NamesProvider.GetTestOutputFileName(test.GhprTestRun.TestInfo.Finish);
                 test.GhprTestOutput.SuiteOutput = output.Value.SuiteOutput;
             }
         }
         return(list);
     }
     catch (Exception ex)
     {
         logger.Exception($"Exception in GetTestRunsListFromFile: {ex.Message}", ex);
         return(null);
     }
 }
Esempio n. 3
0
        public static string Save(this TestOutputDto testOutput, string path)
        {
            path.Create();
            var fullPath = Path.Combine(path, NamesProvider.GetTestOutputFileName(testOutput.TestOutputInfo.Date));

            using (var file = File.CreateText(fullPath))
            {
                var serializer = new JsonSerializer();
                serializer.Serialize(file, testOutput);
            }
            return(fullPath);
        }
Esempio n. 4
0
        public static TestOutput Map(this TestOutputDto testOutputDto)
        {
            var name       = NamesProvider.GetTestOutputFileName(testOutputDto.TestOutputInfo.Date);
            var testOutput = new TestOutput
            {
                SuiteOutput    = testOutputDto.SuiteOutput,
                Output         = testOutputDto.Output,
                TestOutputInfo = testOutputDto.TestOutputInfo.MapSimpleItemInfo(name)
            };

            return(testOutput);
        }
        public void UpdateTestOutput(ItemInfoDto testInfo, TestOutputDto testOutput)
        {
            var outputFolderPath = _locationsProvider.GetTestOutputFolderPath(testInfo.Guid);
            var outputFileName   = NamesProvider.GetTestOutputFileName(testInfo.Finish);
            var existingOutput   = Path.Combine(outputFolderPath, outputFileName).LoadTestOutput();

            _logger.Debug($"Loaded existing output: {JsonConvert.SerializeObject(existingOutput, Formatting.Indented)}");
            existingOutput.SuiteOutput = testOutput.SuiteOutput;
            existingOutput.Output      = testOutput.Output;
            File.Delete(Path.Combine(outputFolderPath, outputFileName));
            _logger.Debug("Deleted old output");
            existingOutput.Save(outputFolderPath);
            _logger.Debug($"Saved updated output: {JsonConvert.SerializeObject(existingOutput, Formatting.Indented)}");
        }
        public static TestOutputDto GetTestOutput(XmlNode testNode, DateTime testFinishDate, ILogger logger)
        {
            var output = new TestOutputDto
            {
                SuiteOutput    = "",
                Output         = testNode.SelectSingleNode("./output")?.InnerText ?? "",
                TestOutputInfo = new SimpleItemInfoDto
                {
                    Date     = testFinishDate,
                    ItemName = NamesProvider.GetTestOutputFileName(testFinishDate)
                }
            };

            return(output);
        }
        public ItemInfoDto SaveTestRun(TestRunDto testRun, TestOutputDto testOutput)
        {
            testRun.TestInfo.ItemName          = NamesProvider.GetTestRunFileName(testRun.TestInfo.Finish);
            testOutput.TestOutputInfo.ItemName = NamesProvider.GetTestOutputFileName(testRun.TestInfo.Finish);
            testRun.Output.ItemName            = testOutput.TestOutputInfo.ItemName;
            var imgFolder = _locationsProvider.GetScreenshotFolderPath(testRun.TestInfo.Guid);

            if (Directory.Exists(imgFolder))
            {
                var imgFiles = new DirectoryInfo(imgFolder).GetFiles("*.json");
                _logger.Info($"Checking unassigned img files: {imgFiles.Length} file found");
                foreach (var imgFile in imgFiles)
                {
                    var img = Path.Combine(imgFolder, imgFile.Name).LoadTestScreenshot();
                    if (imgFile.CreationTime > testRun.TestInfo.Start)
                    {
                        _logger.Info($"New img file found: {imgFile.CreationTime}, {imgFile.Name}");
                        if (testRun.Screenshots.All(s => s.Date != img.TestScreenshotInfo.Date))
                        {
                            testRun.Screenshots.Add(img.TestScreenshotInfo);
                        }
                    }
                }
            }
            var testOutputFullPath = testOutput.Save(_locationsProvider.GetTestOutputFolderPath(testRun.TestInfo.Guid));

            _logger.Info($"Test output was saved: '{testOutputFullPath}'");
            _logger.Debug($"Test run output data was saved correctly: {JsonConvert.SerializeObject(testOutput, Formatting.Indented)}");
            var testRunFullPath = testRun.Save(_locationsProvider.GetTestFolderPath(testRun.TestInfo.Guid));

            _logger.Info($"Test run was saved: '{testRunFullPath}'");
            var testRunsInfoFullPath = testRun.TestInfo.SaveTestInfo(_locationsProvider);

            _logger.Info($"Test runs Info was saved: '{testRunsInfoFullPath}'");
            _logger.Debug($"Test run data was saved correctly: {JsonConvert.SerializeObject(testRun, Formatting.Indented)}");

            if (!_processedTests.ContainsKey(testRun.TestInfo.Guid))
            {
                _processedTests.Add(testRun.TestInfo.Guid, testRun.TestInfo);
            }

            return(testRun.TestInfo);
        }