@@ -21,106 +21,100 @@ public class Reporter
21
21
public static bool TakeScreenshotAfterFail => Properties . Settings . Default . TakeScreenshotAfterFail ;
22
22
public static string Sprint => Properties . Settings . Default . Sprint ;
23
23
public static string RunName => Properties . Settings . Default . RunName ;
24
- public static bool RealTime => Properties . Settings . Default . RealTime ;
24
+ public static bool RealTimeGeneration => Properties . Settings . Default . RealTime ;
25
25
26
- public const string TestsFolder = "tests" ;
27
- public const string RunsFolder = "runs" ;
26
+ public const string TestsFolderName = "tests" ;
27
+ public const string RunsFolderName = "runs" ;
28
28
29
- private void CleanUp ( )
29
+ private void SetUp ( )
30
30
{
31
- _currentRun = new Run ( Guid . NewGuid ( ) )
31
+ ActionHelper . SafeAction ( ( ) =>
32
32
{
33
- TestRunFiles = new List < string > ( ) ,
34
- RunSummary = new RunSummary ( )
35
- } ;
36
- _currentRunningTests = new List < ITestRun > ( ) ;
37
- }
38
-
39
- public void RunStarted ( )
40
- {
41
- try
42
- {
43
- CleanUp ( ) ;
33
+ _currentRun = new Run ( Guid . NewGuid ( ) )
34
+ {
35
+ TestRunFiles = new List < string > ( ) ,
36
+ RunSummary = new RunSummary ( )
37
+ } ;
38
+ _currentRunningTests = new List < ITestRun > ( ) ;
39
+
44
40
_currentRun . Name = RunName ;
45
41
_currentRun . Sprint = Sprint ;
46
42
Extractor . ExtractReportBase ( ) ;
47
43
_currentRun . RunInfo . Start = DateTime . Now ;
48
- }
49
- catch ( Exception ex )
44
+ } ) ;
45
+ }
46
+
47
+ private void UpdateCurrentRunSummary ( ITestRun finalTest )
48
+ {
49
+ ActionHelper . SafeAction ( ( ) =>
50
50
{
51
- Log . Exception ( ex , "Exception in RunStarted" ) ;
52
- }
51
+ _currentRun . RunSummary = _currentRun . RunSummary . Update ( finalTest ) ;
52
+ } ) ;
53
53
}
54
54
55
- public void RunFinished ( )
55
+ private void GenerateReport ( )
56
56
{
57
- try
57
+ ActionHelper . SafeAction ( ( ) =>
58
58
{
59
59
_currentRun . RunInfo . Finish = DateTime . Now ;
60
- var runsPath = Path . Combine ( OutputPath , RunsFolder ) ;
60
+ var runsPath = Path . Combine ( OutputPath , RunsFolderName ) ;
61
61
_currentRun . Save ( runsPath ) ;
62
62
RunsHelper . SaveCurrentRunInfo ( runsPath , _currentRun . RunInfo ) ;
63
- }
64
- catch ( Exception ex )
65
- {
66
- Log . Exception ( ex , "Exception in RunFinished" ) ;
67
- }
63
+ } ) ;
64
+ }
65
+
66
+ public void RunStarted ( )
67
+ {
68
+ SetUp ( ) ;
69
+ }
70
+
71
+ public void RunFinished ( )
72
+ {
73
+ GenerateReport ( ) ;
68
74
}
69
75
70
76
public void TestStarted ( ITestRun testRun )
71
77
{
72
- try
78
+ ActionHelper . SafeAction ( ( ) =>
73
79
{
74
80
_currentRunningTests . Add ( testRun ) ;
75
- }
76
- catch ( Exception ex )
77
- {
78
- Log . Exception ( ex , "Exception in TestStarted" ) ;
79
- }
81
+ } ) ;
80
82
}
81
83
82
84
public void TestFinished ( ITestRun testRun )
83
85
{
84
- _currentRun . RunSummary . Total ++ ;
85
- try
86
+ ActionHelper . SafeAction ( ( ) =>
86
87
{
88
+ _currentRun . RunSummary . Total ++ ;
89
+
87
90
var finishDateTime = DateTime . Now ;
88
91
var currentTest = _currentRunningTests . GetTest ( testRun ) ;
89
92
var finalTest = testRun . Update ( currentTest ) ;
90
93
var testGuid = finalTest . TestInfo . Guid . ToString ( ) ;
91
-
92
- _currentRun . RunSummary = _currentRun . RunSummary . Update ( finalTest ) ;
93
-
94
- var testsPath = Path . Combine ( OutputPath , TestsFolder ) ;
94
+ var testsPath = Path . Combine ( OutputPath , TestsFolderName ) ;
95
95
var testPath = Path . Combine ( testsPath , testGuid ) ;
96
96
var fileName = finishDateTime . GetTestName ( ) ;
97
+
98
+ UpdateCurrentRunSummary ( finalTest ) ;
99
+
97
100
finalTest . TestInfo . FileName = fileName ;
98
101
finalTest . RunGuid = _currentRun . RunInfo . Guid ;
99
- if ( finalTest . TestInfo . Start . Equals ( default ( DateTime ) ) )
100
- {
101
- finalTest . TestInfo . Start = finishDateTime ;
102
- }
103
- if ( finalTest . TestInfo . Finish . Equals ( default ( DateTime ) ) )
104
- {
105
- finalTest . TestInfo . Finish = finishDateTime ;
106
- }
102
+ finalTest . TestInfo . Start = finalTest . TestInfo . Start . Equals ( default ( DateTime ) ) ? finishDateTime : finalTest . TestInfo . Start ;
103
+ finalTest . TestInfo . Finish = finalTest . TestInfo . Finish . Equals ( default ( DateTime ) ) ? finishDateTime : finalTest . TestInfo . Finish ;
107
104
finalTest
108
105
. TakeScreenshot ( testPath , TakeScreenshotAfterFail )
109
106
. Save ( testPath , fileName ) ;
110
107
_currentRunningTests . Remove ( currentTest ) ;
111
108
_currentRun . TestRunFiles . Add ( $ "{ testGuid } \\ { fileName } ") ;
112
109
Extractor . ExtractTestPage ( testsPath ) ;
110
+
113
111
TestRunsHelper . SaveCurrentTestInfo ( testPath , finalTest . TestInfo ) ;
114
112
115
- if ( RealTime )
113
+ if ( RealTimeGeneration )
116
114
{
117
- RunFinished ( ) ;
115
+ GenerateReport ( ) ;
118
116
}
119
- }
120
- catch ( Exception ex )
121
- {
122
- Log . Exception ( ex , $ "Exception in TestFinished { testRun . FullName } ") ;
123
- }
117
+ } ) ;
124
118
}
125
119
}
126
120
}
0 commit comments