-
Notifications
You must be signed in to change notification settings - Fork 204
/
Copy pathGet-PesterReport.ps1
128 lines (114 loc) · 4.5 KB
/
Get-PesterReport.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#Requires -Version 5.0
<#
.SYNOPSIS
Creates an html report from the pester test report
.DESCRIPTION
.NOTES
This PowerShell script was developed and optimized for ScriptRunner. The use of the scripts requires ScriptRunner.
The customer or user is authorized to copy the script from the repository and use them in ScriptRunner.
The terms of use for ScriptRunner do not apply to this script. In particular, ScriptRunner Software GmbH assumes no liability for the function,
the use and the consequences of the use of this freely available script.
PowerShell is a product of Microsoft Corporation. ScriptRunner is a product of ScriptRunner Software GmbH.
© ScriptRunner Software GmbH
.COMPONENT
.LINK
https://github.com/scriptrunner/ActionPacks/tree/master/Reporting
.Parameter Report
[sr-en] Pester test report XML file
[sr-de] Pester Test XML-Reportdatei
#>
param(
[Parameter(Mandatory = $true)]
[string]$Report
)
try{
[int]$tCases = 0
[int]$tSkipped = 0
[int]$sSkipped = 0
[string]$headerHtml = ''
[string]$suitesSummary = ''
[string]$htmlResult = ''
[string]$tmpHtml = ''
[string]$overHtml = ''
#region functions
function CheckPSDrive(){
<#
.SYNOPSIS
Checks if a ps drive has already been created for sharing and creates this if necessary
.Parameter Path
Path to the share file or share directory
#>
param(
[string]$Path
)
if($Path.StartsWith('\\') -eq $true){
[string]$tmp = ''
[string[]]$splitted = $Path.split('\')
if($splitted[$splitted.Count-1].IndexOf('.') -le 0){ # is directory
$tmp = $Path
}
else{ # is file
$tmp = $Path.Replace("\$($splitted[$splitted.Count-1])",'')
}
$chkDrive = Get-PSDrive -PSProvider FileSystem
if(($chkDrive.Root -contains $tmp) -eq $false){
[string]$newName = [System.Guid]::NewGuid().ToString()
$Script:drives += $newName
if($null -ne $ShareAccessAccount){
$null = New-PSDrive -Scope Script -Name $newName -Root $tmp -PSProvider FileSystem -Credential $ShareAccessAccount -Confirm:$false
}
else{
$null = New-PSDrive -Scope Script -Name $newName -Root $tmp -PSProvider FileSystem -Confirm:$false
}
}
}
}
#endregion functions
CheckPSDrive -Path $Report
if((Test-Path -Path $Report) -eq $false){
throw "Import file $($Report) not found"
}
[xml]$xmlReport = Get-Content -Path $Report
# Header
GetHtmlHeader -TestName $xmlReport.SelectSingleNode('//testsuites').Attributes['name'].Value -Header ([ref]$headerHtml)
# Suites
$suiteNodes = $xmlReport.SelectNodes('//testsuite')
foreach($suite in $suiteNodes){
BuildSuiteSummaryHtml -SuiteNode $suite -Id $tCases -SuiteCollection ($suiteNodes.Count -gt 1) -Skipped ([ref]$sSkipped) -SuiteResult ([ref]$tmpHtml) -OverviewResult ([ref]$overHtml)
$tSkipped += $sSkipped
$suitesSummary += $overHtml
$htmlResult += $tmpHtml
BuildSuiteParameterHtml -SuiteNode $suite -Id $tCases -HtmlResult ([ref]$tmpHtml)
$htmlResult += $tmpHtml
BuildSuiteTestcasesHtml -SuiteNode $suite -Id $tCases -HtmlResult ([ref]$tmpHtml)
$htmlResult += $tmpHtml
$tCases++
}
# suites summary
if($tCases -gt 1){
BuildSuitesSummaryHeaderHtml -HtmlResult ([ref]$suitesSummary)
$htmlResult = $suitesSummary + $htmlResult
}
# Report summary
BuildReportSummaryHtml -SuitesNode $xmlReport.SelectSingleNode('//testsuites') -SuiteCount $tCases -SkippedCount $tSkipped -HtmlResult ([ref]$tmpHtml)
$htmlResult = $tmpHtml + $htmlResult
# footer
GetHtmlFooter -Footer ([ref]$tmpHtml)
$htmlResult += $tmpHtml
[int]$bodyIdx = $headerHtml.IndexOf('<body>') + 6
<#
$tmpHtml = "$($headerHtml.Substring(0,$bodyIdx))$($htmlResult)$($headerHtml.Substring($bodyIdx))"
$tmpHtml | Out-File C:\Transfer\Pester\newreport.html # todo #>
$SRXEnv.ResultHtml = "$($headerHtml.Substring(0,$bodyIdx))$($htmlResult)$($headerHtml.Substring($bodyIdx))"
if($null -ne $SRXEnv) {
$SRXEnv.ResultMessage = "Report created"
}
else{
Write-Output "Report created"
}
}
catch{
throw
}
finally{
}