コード例 #1
0
        public static ITestRun SaveScreenshot(this ITestRun testRun, byte[] screenBytes, string reportOutputPath)
        {
            var screenPath     = Path.Combine(reportOutputPath, Paths.Folders.Tests, testRun.TestInfo.Guid.ToString(), Paths.Folders.Img);
            var screenshotName = ScreenshotHelper.SaveScreenshot(screenPath, screenBytes, DateTime.Now);
            var screenshot     = new TestScreenshot(screenshotName);

            testRun.Screenshots.Add(screenshot);
            return(testRun);
        }
コード例 #2
0
        public static TestScreenshotDto ToDto(this TestScreenshot testScreenshot)
        {
            var testScreenshotDto = new TestScreenshotDto
            {
                TestScreenshotInfo = testScreenshot.TestScreenshotInfo.ToDto(),
                Base64Data         = testScreenshot.Base64Data,
                TestGuid           = testScreenshot.TestGuid,
                Format             = testScreenshot.Format
            };

            return(testScreenshotDto);
        }
コード例 #3
0
        public static TestScreenshot Map(this TestScreenshotDto testScreenshotDto)
        {
            var name           = NamesProvider.GetScreenshotFileName(testScreenshotDto.TestScreenshotInfo.Date);
            var testScreenshot = new TestScreenshot
            {
                TestScreenshotInfo = testScreenshotDto.TestScreenshotInfo.MapSimpleItemInfo(name),
                Base64Data         = testScreenshotDto.Base64Data,
                TestGuid           = testScreenshotDto.TestGuid,
                Format             = testScreenshotDto.Format
            };

            return(testScreenshot);
        }
コード例 #4
0
ファイル: TestRunExtensions.cs プロジェクト: follyn/Ghpr.Core
        public static ITestRun TakeScreenshot(this ITestRun testRun, string testPath, bool takeScreenshotAfterFail)
        {
            if (!takeScreenshotAfterFail || !testRun.FailedOrBroken)
            {
                return(testRun);
            }
            var date = DateTime.Now;
            var s    = new TestScreenshot(date);

            Taker.TakeScreenshot(Path.Combine(testPath, "img"), date);
            testRun.Screenshots.Add(s);
            return(testRun);
        }
コード例 #5
0
 public void SaveScreenshot(Bitmap screen)
 {
     _action.Safe(() =>
     {
         var testGuid = _currentTestRun.TestInfo.Guid.ToString();
         var date     = DateTime.Now;
         var s        = new TestScreenshot(date);
         ScreenshotHelper.SaveScreenshot(Path.Combine(TestsPath, testGuid, Paths.Folders.Img), screen, date);
         _currentTestRun.Screenshots.Add(s);
         _currentTestRuns.First(
             tr => tr.TestInfo.Guid.Equals(_currentTestRun.TestInfo.Guid))
         .Screenshots.Add(s);
     });
 }
コード例 #6
0
        public static TestScreenshot LoadTestScreenshot(this string fullPath)
        {
            TestScreenshot testScreenshot = null;

            if (File.Exists(fullPath))
            {
                using (var file = File.OpenText(fullPath))
                {
                    var serializer = new JsonSerializer();
                    testScreenshot = (TestScreenshot)serializer.Deserialize(file, typeof(TestScreenshot));
                }
            }
            return(testScreenshot);
        }
コード例 #7
0
        public static string Save(this TestScreenshot testScreenshot, string path)
        {
            path.Create();
            var fullPath = Path.Combine(path, NamesProvider.GetScreenshotFileName(testScreenshot.TestScreenshotInfo.Date));

            using (var file = File.CreateText(fullPath))
            {
                var serializer = new JsonSerializer();
                serializer.Serialize(file, testScreenshot);
            }
            var fileInfo = new FileInfo(fullPath);

            fileInfo.Refresh();
            fileInfo.CreationTime = testScreenshot.TestScreenshotInfo.Date;
            return(fullPath);
        }
コード例 #8
0
 public void SaveScreenshot(Bitmap screen)
 {
     lock (_lock)
     {
         _actionHelper.SafeAction(() =>
         {
             var testGuid = _currentTestRun.TestInfo.Guid.ToString();
             var date     = DateTime.Now;
             var s        = new TestScreenshot(date);
             Taker.SaveScreenshot(Path.Combine(TestsPath, testGuid, "img"), screen, date);
             _currentTestRun.Screenshots.Add(s);
             _currentTestRuns.First(
                 tr => tr.TestInfo.Guid.Equals(_currentTestRun.TestInfo.Guid))
             .Screenshots.Add(s);
         });
     }
 }
コード例 #9
0
        public static DatabaseEntity <TestScreenshot> Map(this TestScreenshotDto testScreenshotDto)
        {
            var id = $"screenshot-{testScreenshotDto.TestGuid.ToString()}" +
                     $"-{testScreenshotDto.TestScreenshotInfo.Date:yyyyMMdd_HHmmssfff}";
            var testScreenshot = new TestScreenshot
            {
                TestScreenshotInfo = testScreenshotDto.TestScreenshotInfo.MapSimpleItemInfo(id),
                Base64Data         = testScreenshotDto.Base64Data,
                TestGuid           = testScreenshotDto.TestGuid,
                Format             = testScreenshotDto.Format
            };
            var entity = new DatabaseEntity <TestScreenshot>
            {
                Data = testScreenshot,
                Id   = id,
                Type = EntityType.ScreenshotType
            };

            return(entity);
        }