mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-06 00:23:20 +00:00
Tweaked format
This commit is contained in:
@@ -1,66 +1,66 @@
|
|||||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSPossibleIncorrectComparisonWithNull','',Justification='Intentional use to select non null array items')]
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSPossibleIncorrectComparisonWithNull', '', Justification = 'Intentional use to select non null array items')]
|
||||||
[CmdletBinding(DefaultParameterSetName = 'Default')]
|
[CmdletBinding(DefaultParameterSetName = 'Default')]
|
||||||
param(
|
param(
|
||||||
[Parameter(Position=0)]
|
[Parameter(Position = 0)]
|
||||||
[string]$XLFile,
|
[string]$XLFile,
|
||||||
|
|
||||||
[Parameter(ParameterSetName='Default',Position=1)]
|
[Parameter(ParameterSetName = 'Default', Position = 1)]
|
||||||
[Alias('Path', 'relative_path')]
|
[Alias('Path', 'relative_path')]
|
||||||
[object[]]$Script = '.',
|
[object[]]$Script = '.',
|
||||||
|
|
||||||
[Parameter(ParameterSetName='Existing',Mandatory=$true)]
|
[Parameter(ParameterSetName = 'Existing', Mandatory = $true)]
|
||||||
[switch]
|
[switch]
|
||||||
$UseExisting,
|
$UseExisting,
|
||||||
|
|
||||||
[Parameter(ParameterSetName='Default', Position=2)]
|
[Parameter(ParameterSetName = 'Default', Position = 2)]
|
||||||
[Parameter(ParameterSetName='Existing',Position=2, Mandatory=$true)]
|
[Parameter(ParameterSetName = 'Existing', Position = 2, Mandatory = $true)]
|
||||||
[string]$OutputFile,
|
[string]$OutputFile,
|
||||||
|
|
||||||
[Parameter(ParameterSetName='Default')]
|
[Parameter(ParameterSetName = 'Default')]
|
||||||
[Alias("Name")]
|
[Alias("Name")]
|
||||||
[string[]]$TestName,
|
[string[]]$TestName,
|
||||||
|
|
||||||
[Parameter(ParameterSetName='Default')]
|
[Parameter(ParameterSetName = 'Default')]
|
||||||
[switch]$EnableExit,
|
[switch]$EnableExit,
|
||||||
|
|
||||||
[Parameter(ParameterSetName='Default')]
|
[Parameter(ParameterSetName = 'Default')]
|
||||||
[Alias('Tags')]
|
[Alias('Tags')]
|
||||||
[string[]]$Tag,
|
[string[]]$Tag,
|
||||||
[string[]]$ExcludeTag,
|
[string[]]$ExcludeTag,
|
||||||
|
|
||||||
[Parameter(ParameterSetName='Default')]
|
[Parameter(ParameterSetName = 'Default')]
|
||||||
[switch]$Strict,
|
[switch]$Strict,
|
||||||
|
|
||||||
[string]$WorkSheetName = 'PesterResults',
|
[string]$WorkSheetName = 'PesterResults',
|
||||||
[switch]$append,
|
[switch]$append,
|
||||||
[switch]$Show
|
[switch]$Show
|
||||||
)
|
)
|
||||||
|
|
||||||
$InvokePesterParams = @{OutputFormat = 'NUnitXml'} + $PSBoundParameters
|
$InvokePesterParams = @{OutputFormat = 'NUnitXml' } + $PSBoundParameters
|
||||||
if (-not $InvokePesterParams['OutputFile']) {
|
if (-not $InvokePesterParams['OutputFile']) {
|
||||||
$InvokePesterParams['OutputFile'] = Join-Path -ChildPath 'Pester.xml'-Path ([environment]::GetFolderPath([System.Environment+SpecialFolder]::MyDocuments))
|
$InvokePesterParams['OutputFile'] = Join-Path -ChildPath 'Pester.xml'-Path ([environment]::GetFolderPath([System.Environment+SpecialFolder]::MyDocuments))
|
||||||
}
|
}
|
||||||
if ($InvokePesterParams['Show'] ) {}
|
if ($InvokePesterParams['Show'] ) { }
|
||||||
if ($InvokePesterParams['XLFile']) {$InvokePesterParams.Remove('XLFile')}
|
if ($InvokePesterParams['XLFile']) { $InvokePesterParams.Remove('XLFile') }
|
||||||
else {$XLFile = $InvokePesterParams['OutputFile'] -replace '.xml$','.xlsx'}
|
else { $XLFile = $InvokePesterParams['OutputFile'] -replace '.xml$', '.xlsx' }
|
||||||
if (-not $UseExisting) {
|
if (-not $UseExisting) {
|
||||||
$InvokePesterParams.Remove('Append')
|
$InvokePesterParams.Remove('Append')
|
||||||
$InvokePesterParams.Remove('UseExisting')
|
$InvokePesterParams.Remove('UseExisting')
|
||||||
$InvokePesterParams.Remove('Show')
|
$InvokePesterParams.Remove('Show')
|
||||||
$InvokePesterParams.Remove('WorkSheetName')
|
$InvokePesterParams.Remove('WorkSheetName')
|
||||||
Invoke-Pester @InvokePesterParams
|
Invoke-Pester @InvokePesterParams
|
||||||
}
|
}
|
||||||
|
|
||||||
if (-not (Test-Path -Path $InvokePesterParams['OutputFile'])) {
|
if (-not (Test-Path -Path $InvokePesterParams['OutputFile'])) {
|
||||||
throw "Could not output file $($InvokePesterParams['OutputFile'])"; return
|
throw "Could not output file $($InvokePesterParams['OutputFile'])"; return
|
||||||
}
|
}
|
||||||
|
|
||||||
$resultXML = ([xml](Get-Content $InvokePesterParams['OutputFile'])).'test-results'
|
$resultXML = ([xml](Get-Content $InvokePesterParams['OutputFile'])).'test-results'
|
||||||
$startDate = [datetime]$resultXML.date
|
$startDate = [datetime]$resultXML.date
|
||||||
$startTime = $resultXML.time
|
$startTime = $resultXML.time
|
||||||
$machine = $resultXML.environment.'machine-name'
|
$machine = $resultXML.environment.'machine-name'
|
||||||
#$user = $resultXML.environment.'user-domain' + '\' + $resultXML.environment.user
|
#$user = $resultXML.environment.'user-domain' + '\' + $resultXML.environment.user
|
||||||
$os = $resultXML.environment.platform -replace '\|.*$'," $($resultXML.environment.'os-version')"
|
$os = $resultXML.environment.platform -replace '\|.*$', " $($resultXML.environment.'os-version')"
|
||||||
<#hierarchy goes
|
<#hierarchy goes
|
||||||
root, [date], start [time], [Name] (always "Pester"), test results broken down as [total],[errors],[failures],[not-run] etc.
|
root, [date], start [time], [Name] (always "Pester"), test results broken down as [total],[errors],[failures],[not-run] etc.
|
||||||
Environment (user & machine info)
|
Environment (user & machine info)
|
||||||
@@ -80,52 +80,54 @@ $os = $resultXML.environment.platform -replace '\|.*$'," $($resultXML.e
|
|||||||
Test-case [description] - name as rendered for display with <vars> filled in
|
Test-case [description] - name as rendered for display with <vars> filled in
|
||||||
#>
|
#>
|
||||||
$testResults = foreach ($test in $resultXML.'test-suite'.results.'test-suite') {
|
$testResults = foreach ($test in $resultXML.'test-suite'.results.'test-suite') {
|
||||||
$testPs1File = $test.name
|
$testPs1File = $test.name
|
||||||
#Test if there are context blocks in the hierarchy OR if we go straight from Describe to test-case
|
#Test if there are context blocks in the hierarchy OR if we go straight from Describe to test-case
|
||||||
if ($test.results.'test-suite'.results.'test-suite' -ne $null) {
|
if ($test.results.'test-suite'.results.'test-suite' -ne $null) {
|
||||||
foreach ($suite in $test.results.'test-suite') {
|
foreach ($suite in $test.results.'test-suite') {
|
||||||
$Describe = $suite.description
|
$Describe = $suite.description
|
||||||
foreach ($subsuite in $suite.results.'test-suite') {
|
foreach ($subsuite in $suite.results.'test-suite') {
|
||||||
$Context = $subsuite.description
|
$Context = $subsuite.description
|
||||||
if ($subsuite.results.'test-suite'.results.'test-case') {
|
if ($subsuite.results.'test-suite'.results.'test-case') {
|
||||||
$testCases = $subsuite.results.'test-suite'.results.'test-case'
|
$testCases = $subsuite.results.'test-suite'.results.'test-case'
|
||||||
}
|
|
||||||
else {$testCases = $subsuite.results.'test-case'}
|
|
||||||
$testCases | ForEach-Object {
|
|
||||||
New-Object -TypeName psobject -Property ([ordered]@{
|
|
||||||
Machine = $machine ; OS = $os
|
|
||||||
Date = $startDate ; Time = $startTime
|
|
||||||
Executed = $(if ($_.executed -eq 'True') {1})
|
|
||||||
Success = $(if ($_.success -eq 'True') {1})
|
|
||||||
Duration = $_.time
|
|
||||||
File = $testPs1File; Group = $Describe
|
|
||||||
SubGroup = $Context ; Name =($_.Description -replace '\s{2,}', ' ')
|
|
||||||
Result = $_.result ; FullDesc = '=Group&" "&SubGroup&" "&Name'})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
else { $testCases = $subsuite.results.'test-case' }
|
||||||
else {
|
$testCases | ForEach-Object {
|
||||||
$test.results.'test-suite' | ForEach-Object {
|
New-Object -TypeName psobject -Property ([ordered]@{
|
||||||
$Describe = $_.description
|
Machine = $machine ; OS = $os
|
||||||
$_.results.'test-case'| ForEach-Object {
|
Date = $startDate ; Time = $startTime
|
||||||
New-Object -TypeName psobject -Property ([ordered]@{
|
Executed = $(if ($_.executed -eq 'True') { 1 })
|
||||||
Machine = $machine ; OS = $os
|
Success = $(if ($_.success -eq 'True') { 1 })
|
||||||
Date = $startDate ; Time = $startTime
|
Duration = $_.time
|
||||||
Executed = $(if ($_.executed -eq 'True') {1})
|
File = $testPs1File; Group = $Describe
|
||||||
Success = $(if ($_.success -eq 'True') {1})
|
SubGroup = $Context ; Name = ($_.Description -replace '\s{2,}', ' ')
|
||||||
Duration = $_.time
|
Result = $_.result ; FullDesc = '=Group&" "&SubGroup&" "&Name'
|
||||||
File = $testPs1File; Group = $Describe
|
})
|
||||||
SubGroup = $null ; Name =($_.Description -replace '\s{2,}', ' ')
|
|
||||||
Result = $_.result ; FullDesc = '=Group&" "&Test'})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$test.results.'test-suite' | ForEach-Object {
|
||||||
|
$Describe = $_.description
|
||||||
|
$_.results.'test-case' | ForEach-Object {
|
||||||
|
New-Object -TypeName psobject -Property ([ordered]@{
|
||||||
|
Machine = $machine ; OS = $os
|
||||||
|
Date = $startDate ; Time = $startTime
|
||||||
|
Executed = $(if ($_.executed -eq 'True') { 1 })
|
||||||
|
Success = $(if ($_.success -eq 'True') { 1 })
|
||||||
|
Duration = $_.time
|
||||||
|
File = $testPs1File; Group = $Describe
|
||||||
|
SubGroup = $null ; Name = ($_.Description -replace '\s{2,}', ' ')
|
||||||
|
Result = $_.result ; FullDesc = '=Group&" "&Test'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (-not $testResults) {Write-Warning 'No Results found' ; return}
|
if (-not $testResults) { Write-Warning 'No Results found' ; return }
|
||||||
$clearSheet = -not $Append
|
$clearSheet = -not $Append
|
||||||
$excel = $testResults | Export-Excel -Path $xlFile -WorkSheetname $WorkSheetName -ClearSheet:$clearSheet -Append:$append -PassThru -BoldTopRow -FreezeTopRow -AutoSize -AutoFilter -AutoNameRange
|
$excel = $testResults | Export-Excel -Path $xlFile -WorkSheetname $WorkSheetName -ClearSheet:$clearSheet -Append:$append -PassThru -BoldTopRow -FreezeTopRow -AutoSize -AutoFilter -AutoNameRange
|
||||||
$ws = $excel.Workbook.Worksheets[$WorkSheetName]
|
$ws = $excel.Workbook.Worksheets[$WorkSheetName]
|
||||||
<# Worksheet should look like ..
|
<# Worksheet should look like ..
|
||||||
|A |B |C D |E |F |G |H |I |J |K |L |M
|
|A |B |C D |E |F |G |H |I |J |K |L |M
|
||||||
1|Machine |OS |Date Time |Executed |Success |Duration |File |Group |SubGroup |Name |Result |FullDescription
|
1|Machine |OS |Date Time |Executed |Success |Duration |File |Group |SubGroup |Name |Result |FullDescription
|
||||||
@@ -136,7 +138,7 @@ $ws = $excel.Workbook.Worksheets[$WorkSheetName]
|
|||||||
Set-Column -Worksheet $ws -Column 3 -NumberFormat 'Short Date' # -AutoSize
|
Set-Column -Worksheet $ws -Column 3 -NumberFormat 'Short Date' # -AutoSize
|
||||||
|
|
||||||
#Hide columns E to J (Executed, Success, Duration, File, Group and Subgroup)
|
#Hide columns E to J (Executed, Success, Duration, File, Group and Subgroup)
|
||||||
(5..10) | ForEach-Object {Set-ExcelColumn -Worksheet $ws -Column $_ -Hide }
|
(5..10) | ForEach-Object { Set-ExcelColumn -Worksheet $ws -Column $_ -Hide }
|
||||||
|
|
||||||
#Use conditional formatting to make Failures red, and Successes green (skipped remains black ) ... and save
|
#Use conditional formatting to make Failures red, and Successes green (skipped remains black ) ... and save
|
||||||
$endRow = $ws.Dimension.End.Row
|
$endRow = $ws.Dimension.End.Row
|
||||||
|
|||||||
Reference in New Issue
Block a user