1
- [Diagnostics.CodeAnalysis.SuppressMessageAttribute (' PSPossibleIncorrectComparisonWithNull' , ' ' , Justification= ' Intentional use to select non null array items' )]
1
+ [Diagnostics.CodeAnalysis.SuppressMessageAttribute (' PSPossibleIncorrectComparisonWithNull' , ' ' , Justification = ' Intentional use to select non null array items' )]
2
2
[CmdletBinding (DefaultParameterSetName = ' Default' )]
3
3
param (
4
- [Parameter (Position = 0 )]
5
- [string ]$XLFile ,
4
+ [Parameter (Position = 0 )]
5
+ [string ]$XLFile ,
6
6
7
- [Parameter (ParameterSetName = ' Default' , Position = 1 )]
8
- [Alias (' Path' , ' relative_path' )]
9
- [object []]$Script = ' .' ,
7
+ [Parameter (ParameterSetName = ' Default' , Position = 1 )]
8
+ [Alias (' Path' , ' relative_path' )]
9
+ [object []]$Script = ' .' ,
10
10
11
- [Parameter (ParameterSetName = ' Existing' , Mandatory = $true )]
12
- [switch ]
13
- $UseExisting ,
11
+ [Parameter (ParameterSetName = ' Existing' , Mandatory = $true )]
12
+ [switch ]
13
+ $UseExisting ,
14
14
15
- [Parameter (ParameterSetName = ' Default' , Position = 2 )]
16
- [Parameter (ParameterSetName = ' Existing' , Position = 2 , Mandatory = $true )]
17
- [string ]$OutputFile ,
15
+ [Parameter (ParameterSetName = ' Default' , Position = 2 )]
16
+ [Parameter (ParameterSetName = ' Existing' , Position = 2 , Mandatory = $true )]
17
+ [string ]$OutputFile ,
18
18
19
- [Parameter (ParameterSetName = ' Default' )]
20
- [Alias (" Name" )]
21
- [string []]$TestName ,
19
+ [Parameter (ParameterSetName = ' Default' )]
20
+ [Alias (" Name" )]
21
+ [string []]$TestName ,
22
22
23
- [Parameter (ParameterSetName = ' Default' )]
24
- [switch ]$EnableExit ,
23
+ [Parameter (ParameterSetName = ' Default' )]
24
+ [switch ]$EnableExit ,
25
25
26
- [Parameter (ParameterSetName = ' Default' )]
27
- [Alias (' Tags' )]
28
- [string []]$Tag ,
29
- [string []]$ExcludeTag ,
26
+ [Parameter (ParameterSetName = ' Default' )]
27
+ [Alias (' Tags' )]
28
+ [string []]$Tag ,
29
+ [string []]$ExcludeTag ,
30
30
31
- [Parameter (ParameterSetName = ' Default' )]
32
- [switch ]$Strict ,
31
+ [Parameter (ParameterSetName = ' Default' )]
32
+ [switch ]$Strict ,
33
33
34
- [string ]$WorkSheetName = ' PesterResults' ,
35
- [switch ]$append ,
36
- [switch ]$Show
34
+ [string ]$WorkSheetName = ' PesterResults' ,
35
+ [switch ]$append ,
36
+ [switch ]$Show
37
37
)
38
38
39
- $InvokePesterParams = @ {OutputFormat = ' NUnitXml' } + $PSBoundParameters
39
+ $InvokePesterParams = @ {OutputFormat = ' NUnitXml' } + $PSBoundParameters
40
40
if (-not $InvokePesterParams [' OutputFile' ]) {
41
- $InvokePesterParams [' OutputFile' ] = Join-Path - ChildPath ' Pester.xml' - Path ([environment ]::GetFolderPath([System.Environment + SpecialFolder ]::MyDocuments))
41
+ $InvokePesterParams [' OutputFile' ] = Join-Path - ChildPath ' Pester.xml' - Path ([environment ]::GetFolderPath([System.Environment + SpecialFolder ]::MyDocuments))
42
42
}
43
- if ($InvokePesterParams [' Show' ] ) {}
44
- if ($InvokePesterParams [' XLFile' ]) {$InvokePesterParams.Remove (' XLFile' )}
45
- else { $XLFile = $InvokePesterParams [' OutputFile' ] -replace ' .xml$' , ' .xlsx' }
43
+ if ($InvokePesterParams [' Show' ] ) { }
44
+ if ($InvokePesterParams [' XLFile' ]) { $InvokePesterParams.Remove (' XLFile' ) }
45
+ else { $XLFile = $InvokePesterParams [' OutputFile' ] -replace ' .xml$' , ' .xlsx' }
46
46
if (-not $UseExisting ) {
47
- $InvokePesterParams.Remove (' Append' )
48
- $InvokePesterParams.Remove (' UseExisting' )
49
- $InvokePesterParams.Remove (' Show' )
50
- $InvokePesterParams.Remove (' WorkSheetName' )
51
- Invoke-Pester @InvokePesterParams
47
+ $InvokePesterParams.Remove (' Append' )
48
+ $InvokePesterParams.Remove (' UseExisting' )
49
+ $InvokePesterParams.Remove (' Show' )
50
+ $InvokePesterParams.Remove (' WorkSheetName' )
51
+ Invoke-Pester @InvokePesterParams
52
52
}
53
53
54
54
if (-not (Test-Path - Path $InvokePesterParams [' OutputFile' ])) {
55
- throw " Could not output file $ ( $InvokePesterParams [' OutputFile' ]) " ; return
55
+ throw " Could not output file $ ( $InvokePesterParams [' OutputFile' ]) " ; return
56
56
}
57
57
58
- $resultXML = ([xml ](Get-Content $InvokePesterParams [' OutputFile' ])).' test-results'
59
- $startDate = [datetime ]$resultXML.date
60
- $startTime = $resultXML.time
61
- $machine = $resultXML.environment .' machine-name'
58
+ $resultXML = ([xml ](Get-Content $InvokePesterParams [' OutputFile' ])).' test-results'
59
+ $startDate = [datetime ]$resultXML.date
60
+ $startTime = $resultXML.time
61
+ $machine = $resultXML.environment .' machine-name'
62
62
# $user = $resultXML.environment.'user-domain' + '\' + $resultXML.environment.user
63
- $os = $resultXML.environment.platform -replace ' \|.*$' , " $ ( $resultXML.environment .' os-version' ) "
63
+ $os = $resultXML.environment.platform -replace ' \|.*$' , " $ ( $resultXML.environment .' os-version' ) "
64
64
<# hierarchy goes
65
65
root, [date], start [time], [Name] (always "Pester"), test results broken down as [total],[errors],[failures],[not-run] etc.
66
66
Environment (user & machine info)
@@ -80,52 +80,54 @@ $os = $resultXML.environment.platform -replace '\|.*$'," $($resultXML.e
80
80
Test-case [description] - name as rendered for display with <vars> filled in
81
81
#>
82
82
$testResults = foreach ($test in $resultXML .' test-suite' .results.' test-suite' ) {
83
- $testPs1File = $test.name
84
- # Test if there are context blocks in the hierarchy OR if we go straight from Describe to test-case
85
- if ($test.results .' test-suite' .results.' test-suite' -ne $null ) {
86
- foreach ($suite in $test.results .' test-suite' ) {
87
- $Describe = $suite.description
88
- foreach ($subsuite in $suite.results .' test-suite' ) {
89
- $Context = $subsuite.description
90
- if ($subsuite.results .' test-suite' .results.' test-case' ) {
91
- $testCases = $subsuite.results .' test-suite' .results.' test-case'
92
- }
93
- else {$testCases = $subsuite.results .' test-case' }
94
- $testCases | ForEach-Object {
95
- New-Object - TypeName psobject - Property ([ordered ]@ {
96
- Machine = $machine ; OS = $os
97
- Date = $startDate ; Time = $startTime
98
- Executed = $ (if ($_.executed -eq ' True' ) {1 })
99
- Success = $ (if ($_.success -eq ' True' ) {1 })
100
- Duration = $_.time
101
- File = $testPs1File ; Group = $Describe
102
- SubGroup = $Context ; Name = ($_.Description -replace ' \s{2,}' , ' ' )
103
- Result = $_.result ; FullDesc = ' =Group&" "&SubGroup&" "&Name' })
104
- }
105
- }
83
+ $testPs1File = $test.name
84
+ # Test if there are context blocks in the hierarchy OR if we go straight from Describe to test-case
85
+ if ($test.results .' test-suite' .results.' test-suite' -ne $null ) {
86
+ foreach ($suite in $test.results .' test-suite' ) {
87
+ $Describe = $suite.description
88
+ foreach ($subsuite in $suite.results .' test-suite' ) {
89
+ $Context = $subsuite.description
90
+ if ($subsuite.results .' test-suite' .results.' test-case' ) {
91
+ $testCases = $subsuite.results .' test-suite' .results.' test-case'
106
92
}
107
- }
108
- else {
109
- $test.results .' test-suite' | ForEach-Object {
110
- $Describe = $_.description
111
- $_.results .' test-case' | ForEach-Object {
112
- New-Object - TypeName psobject - Property ([ordered ]@ {
113
- Machine = $machine ; OS = $os
114
- Date = $startDate ; Time = $startTime
115
- Executed = $ (if ($_.executed -eq ' True' ) {1 })
116
- Success = $ (if ($_.success -eq ' True' ) {1 })
117
- Duration = $_.time
118
- File = $testPs1File ; Group = $Describe
119
- SubGroup = $null ; Name = ($_.Description -replace ' \s{2,}' , ' ' )
120
- Result = $_.result ; FullDesc = ' =Group&" "&Test' })
121
- }
93
+ else { $testCases = $subsuite.results .' test-case' }
94
+ $testCases | ForEach-Object {
95
+ New-Object - TypeName psobject - Property ([ordered ]@ {
96
+ Machine = $machine ; OS = $os
97
+ Date = $startDate ; Time = $startTime
98
+ Executed = $ (if ($_.executed -eq ' True' ) { 1 })
99
+ Success = $ (if ($_.success -eq ' True' ) { 1 })
100
+ Duration = $_.time
101
+ File = $testPs1File ; Group = $Describe
102
+ SubGroup = $Context ; Name = ($_.Description -replace ' \s{2,}' , ' ' )
103
+ Result = $_.result ; FullDesc = ' =Group&" "&SubGroup&" "&Name'
104
+ })
122
105
}
106
+ }
107
+ }
108
+ }
109
+ else {
110
+ $test.results .' test-suite' | ForEach-Object {
111
+ $Describe = $_.description
112
+ $_.results .' test-case' | ForEach-Object {
113
+ New-Object - TypeName psobject - Property ([ordered ]@ {
114
+ Machine = $machine ; OS = $os
115
+ Date = $startDate ; Time = $startTime
116
+ Executed = $ (if ($_.executed -eq ' True' ) { 1 })
117
+ Success = $ (if ($_.success -eq ' True' ) { 1 })
118
+ Duration = $_.time
119
+ File = $testPs1File ; Group = $Describe
120
+ SubGroup = $null ; Name = ($_.Description -replace ' \s{2,}' , ' ' )
121
+ Result = $_.result ; FullDesc = ' =Group&" "&Test'
122
+ })
123
+ }
123
124
}
125
+ }
124
126
}
125
- if (-not $testResults ) {Write-Warning ' No Results found' ; return }
127
+ if (-not $testResults ) { Write-Warning ' No Results found' ; return }
126
128
$clearSheet = -not $Append
127
- $excel = $testResults | Export-Excel - Path $xlFile - WorkSheetname $WorkSheetName - ClearSheet:$clearSheet - Append:$append - PassThru - BoldTopRow - FreezeTopRow - AutoSize - AutoFilter - AutoNameRange
128
- $ws = $excel.Workbook.Worksheets [$WorkSheetName ]
129
+ $excel = $testResults | Export-Excel - Path $xlFile - WorkSheetname $WorkSheetName - ClearSheet:$clearSheet - Append:$append - PassThru - BoldTopRow - FreezeTopRow - AutoSize - AutoFilter - AutoNameRange
130
+ $ws = $excel.Workbook.Worksheets [$WorkSheetName ]
129
131
<# Worksheet should look like ..
130
132
|A |B |C D |E |F |G |H |I |J |K |L |M
131
133
1|Machine |OS |Date Time |Executed |Success |Duration |File |Group |SubGroup |Name |Result |FullDescription
@@ -136,7 +138,7 @@ $ws = $excel.Workbook.Worksheets[$WorkSheetName]
136
138
Set-Column - Worksheet $ws - Column 3 - NumberFormat ' Short Date' # -AutoSize
137
139
138
140
# Hide columns E to J (Executed, Success, Duration, File, Group and Subgroup)
139
- (5 .. 10 ) | ForEach-Object {Set-ExcelColumn - Worksheet $ws - Column $_ - Hide }
141
+ (5 .. 10 ) | ForEach-Object { Set-ExcelColumn - Worksheet $ws - Column $_ - Hide }
140
142
141
143
# Use conditional formatting to make Failures red, and Successes green (skipped remains black ) ... and save
142
144
$endRow = $ws.Dimension.End.Row
0 commit comments