1
- using System ;
1
+ using System ;
2
2
using System . Collections . Generic ;
3
3
using System . IO ;
4
4
using System . Linq ;
5
+ using System . Text ;
5
6
using System . Xml . Linq ;
6
7
7
8
namespace HelixTestHelpers
@@ -16,14 +17,21 @@ public class TestPass
16
17
17
18
public class TestResult
18
19
{
20
+ public TestResult ( )
21
+ {
22
+ Screenshots = new List < string > ( ) ;
23
+ }
24
+
19
25
public string Name { get ; set ; }
20
26
public bool Passed { get ; set ; }
21
27
public bool CleanupPassed { get ; set ; }
22
28
public TimeSpan ExecutionTime { get ; set ; }
23
29
public string Details { get ; set ; }
30
+
31
+ public List < string > Screenshots { get ; private set ; }
24
32
}
25
33
26
- public static void ConvertWttLogToXUnitLog ( string wttInputPath , string xunitOutputPath , string testNamePrefix )
34
+ public static void ConvertWttLogToXUnitLog ( string wttInputPath , string xunitOutputPath , string testNamePrefix , string helixResultsContainerUri , string helixResultsContainerRsas )
27
35
{
28
36
var testPass = TestResultParser . ParseTestWttFile ( wttInputPath , true ) ;
29
37
var results = testPass . TestResults ;
@@ -80,7 +88,24 @@ public static void ConvertWttLogToXUnitLog(string wttInputPath, string xunitOutp
80
88
failure . SetAttributeValue ( "exception-type" , "Exception" ) ;
81
89
82
90
var message = new XElement ( "message" ) ;
83
- message . Add ( new XCData ( result . Details ) ) ;
91
+
92
+ StringBuilder errorMessage = new StringBuilder ( ) ;
93
+
94
+ errorMessage . AppendLine ( "Log: " + GetUploadedFileUrl ( wttInputPath , helixResultsContainerUri , helixResultsContainerRsas ) ) ;
95
+
96
+ if ( result . Screenshots . Any ( ) )
97
+ {
98
+ errorMessage . AppendLine ( "Screenshots:" ) ;
99
+ foreach ( var screenshot in result . Screenshots )
100
+ {
101
+ errorMessage . AppendLine ( GetUploadedFileUrl ( screenshot , helixResultsContainerUri , helixResultsContainerRsas ) ) ;
102
+ }
103
+ }
104
+
105
+ errorMessage . AppendLine ( "Error Log: " ) ;
106
+ errorMessage . AppendLine ( result . Details ) ;
107
+
108
+ message . Add ( new XCData ( errorMessage . ToString ( ) ) ) ;
84
109
failure . Add ( message ) ;
85
110
86
111
test . Add ( failure ) ;
@@ -272,6 +297,26 @@ public static TestPass ParseTestWttFile(string fileName, bool cleanupFailuresAre
272
297
currentResult . Details += "]" ;
273
298
}
274
299
}
300
+
301
+ if ( currentResult != null && element . Name == "Msg" )
302
+ {
303
+ var dataElement = element . Element ( "Data" ) ;
304
+ if ( dataElement != null )
305
+ {
306
+ var supportingInfo = dataElement . Element ( "SupportingInfo" ) ;
307
+ if ( supportingInfo != null )
308
+ {
309
+ var screenshots = supportingInfo . Elements ( "Item" )
310
+ . Where ( item => GetAttributeValue ( item , "Name" ) == "Screenshot" )
311
+ . Select ( item => GetAttributeValue ( item , "Value" ) ) ;
312
+
313
+ foreach ( var screenshot in screenshots )
314
+ {
315
+ currentResult . Screenshots . Add ( screenshot ) ;
316
+ }
317
+ }
318
+ }
319
+ }
275
320
}
276
321
277
322
testPassStartTime = Int64 . Parse ( doc . Root . Descendants ( "WexTraceInfo" ) . First ( ) . Attribute ( "TimeStamp" ) . Value ) ;
@@ -288,5 +333,23 @@ public static TestPass ParseTestWttFile(string fileName, bool cleanupFailuresAre
288
333
return testpass ;
289
334
}
290
335
}
336
+
337
+ private static string GetAttributeValue ( XElement element , string attributeName )
338
+ {
339
+ if ( element . Attribute ( attributeName ) != null )
340
+ {
341
+ return element . Attribute ( attributeName ) . Value ;
342
+ }
343
+
344
+ return null ;
345
+ }
346
+
347
+ private static string GetUploadedFileUrl ( string filePath , string helixResultsContainerUri , string helixResultsContainerRsas )
348
+ {
349
+ var filename = Path . GetFileName ( filePath ) ;
350
+ return string . Format ( "{0}/{1}{2}" , helixResultsContainerUri , filename , helixResultsContainerRsas ) ;
351
+ }
291
352
}
353
+
354
+
292
355
}
0 commit comments