Skip to content

Commit 5e28499

Browse files
authored
Merge pull request #184 from adamdriscoll/V4
V4
2 parents 12ac46d + 96bfd94 commit 5e28499

File tree

199 files changed

+10565
-9416
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

199 files changed

+10565
-9416
lines changed

CI/CI.ps1

Lines changed: 73 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,99 @@
11
param (
2-
[string[]]$BrowserList = @('Chrome', 'Firefox')
2+
[String]$ModulePath,
3+
[string[]]$BrowserList = @('Chrome', 'Firefox'),
4+
[Switch]$UseDebugVersion
35
)
6+
7+
if ([String]::IsNullOrEmpty($ModulePath)) { $ModulePath = $pwd.path.Replace('\', '/') }
8+
$env:ModulePath = $ModulePath
9+
Write-Host "ModulePath: $ModulePath"
10+
Write-Host "BrowserList: $($BrowserList -join ',')"
11+
$Global:BrowserList = $BrowserList
412
#Get the OS/PS version info for later. On Linux run headless On windows and PS 6 (but not 7) add WindowsPowershell to the module path.
513
$Platform = ([environment]::OSVersion.Platform).ToString() + ' PS' + $PSVersionTable.PSVersion.Major
6-
if ($Platform -notlike 'win*') { $env:AlwaysHeadless = $true }
14+
if ($Platform -notlike 'win*') { $Global:HeadlessOnly = $true }
715
if ($Platform -like 'win*6') {
816
$env:PSModulePath -split ';' | Where-Object { $_ -match "\w:\\Prog.*PowerShell\\modules" } | ForEach-Object {
917
$env:PSModulePath = ($_ -replace "PowerShell", "WindowsPowerShell") + ";" + $env:PSModulePath
1018
}
1119
}
1220

21+
22+
1323
#Make sure we have the modules we need
14-
Import-Module .\Output\Selenium\Selenium.psd1 -Force -ErrorAction Stop
15-
$checkImportExcel = Get-Module -ListAvailable ImportExcel
16-
if (-not ($checkImportExcel)) {
17-
Write-Verbose -Verbose 'Installing ImportExcel'
18-
Install-Module ImportExcel -Force -SkipPublisherCheck
24+
$ModulePathSuffix = 'Output/Selenium/'
25+
if ($UseDebugVersion) { $ModulePathSuffix = ''; Write-Host 'Debug version will be used' -ForegroundColor Yellow }
26+
Import-Module "$ModulePath/$($ModulePathSuffix)Selenium.psd1" -Force -ErrorAction Stop
27+
28+
# $checkImportExcel = Get-Module -ListAvailable ImportExcel
29+
# if (-not ($checkImportExcel)) {
30+
# Write-Verbose -Verbose 'Installing ImportExcel'
31+
# Install-Module ImportExcel -Force -SkipPublisherCheck
32+
# }
33+
# else { $checkImportExcel | Out-Host }
34+
# $PesterLock = @{MinimumVersion = '4.10.0.0' ; MaximumVersion = '4.99.0.0' }
35+
# $checkPester = Get-Module -ListAvailable Pester | Where-Object { $_.version.major -ge 4 -and $_.version.minor -ge 4 }
36+
# if (-not $checkPester) {
37+
# Write-Verbose -Verbose 'Installing Pester'
38+
# Install-Module Pester -Force -SkipPublisherCheck @PesterLock
39+
# }
40+
# else { $checkPester | Out-Host }
41+
42+
#Import-Module Pester -RequiredVersion 4.10.1
43+
#Import-Module ImportExcel -RequiredVersion 7.1.1
44+
45+
if (Test-path "$ModulePath/Modules") {
46+
Import-Module "$ModulePath/Modules/Pester/5.0.3/Pester.psd1"
47+
Import-Module "$ModulePath/Modules/ImportExcel/7.1.1/ImportExcel.psd1"
1948
}
20-
else { $checkImportExcel | Out-Host }
21-
$checkPester = Get-Module -ListAvailable Pester | Where-Object { $_.version.major -ge 4 -and $_.version.minor -ge 4 }
22-
if (-not $checkPester) {
23-
Write-Verbose -Verbose 'Installing Pester'
24-
Install-Module Pester -Force -SkipPublisherCheck
49+
else {
50+
Import-Module -Name Pester -RequiredVersion 5.0.3
51+
Import-Module -Name ImportExcel -RequiredVersion 7.1.1
2552
}
26-
else { $checkPester | Out-Host }
2753

28-
#Run the test and results export to an Excel file for current OS - Test picks up the selected browser from an environment variable.
54+
55+
Write-verbose -Verbose "Pester $((Get-Module -Name Pester).Version.ToString()) loaded"
56+
Write-verbose -Verbose "ImportExcel $((Get-Module -Name ImportExcel).Version.ToString()) loaded"
57+
58+
# #Run the test and results export to an Excel file for current OS - Test picks up the selected browser from an environment variable.
2959
$RunParameters = @{
3060
XLFile = '{0}/results/Results-{1}.xlsx' -f $env:BUILD_ARTIFACTSTAGINGDIRECTORY, [environment]::OSVersion.Platform.ToString()
31-
Script = Join-Path -Path (Join-Path $pwd 'Examples') -ChildPath 'Combined.tests.ps1'
61+
Path = "$ModulePath/Examples/Combined.tests.ps1"
3262
}
3363
foreach ( $b in $BrowserList) {
34-
$env:DefaultBrowser = $b
64+
$Global:DefaultBrowser = $b
3565
$RunParameters['OutputFile'] = Join-Path $pwd "TestResults-$platform$b.xml"
3666
$RunParameters['WorkSheetName'] = "$B $Platform"
3767
$RunParameters | Out-Host
3868
& "$PSScriptRoot\Pester-To-XLSx.ps1" @RunParameters
3969
}
4070

4171
#Merge the results sheets into a sheet named 'combined'.
42-
$excel = Open-ExcelPackage $RunParameters.XLFile
43-
$wslist = $excel.Workbook.Worksheets.name
44-
Close-ExcelPackage -NoSave $excel
45-
Merge-MultipleSheets -path $RunParameters.XLFile -WorksheetName $wslist -OutputSheetName combined -OutputFile $RunParameters.XLFile -HideRowNumbers -Property name, result
72+
# $excel = Open-ExcelPackage $RunParameters.XLFile
73+
# $wslist = $excel.Workbook.Worksheets.name
74+
# Close-ExcelPackage -NoSave $excel
75+
# Merge-MultipleSheets -path $RunParameters.XLFile -WorksheetName $wslist -OutputSheetName combined -OutputFile $RunParameters.XLFile -HideRowNumbers -Property name, result
4676

47-
#Hide everything on 'combined' except test name, results for each browser, and test group, Set column widths, tweak titles, apply conditional formatting.
48-
$excel = Open-ExcelPackage $RunParameters.XLFile
49-
$ws = $excel.combined
50-
2..$ws.Dimension.end.Column | ForEach-Object {
51-
if ($ws.Cells[1, $_].value -notmatch '^Name|Result$|PS\dGroup$') {
52-
Set-ExcelColumn -Worksheet $ws -Column $_ -Hid
53-
}
54-
elseif ($ws.Cells[1, $_].value -match 'Result$' ) {
55-
Set-ExcelColumn -Worksheet $ws -Column $_ -Width 17
56-
Set-ExcelRange $ws.Cells[1, $_] -WrapText
57-
}
58-
if ($ws.cells[1, $_].value -match 'PS\dGroup$') {
59-
Set-ExcelRange $ws.Cells[1, $_] -WrapText -Value 'Group'
60-
}
61-
if ($ws.cells[1, $_].value -match '^Name|PS\dGroup$' -and ($ws.Column($_).Width -gt 80)) {
62-
$ws.Column($_).Width = 80
63-
}
64-
}
65-
Set-ExcelRow -Worksheet $ws -Height 28.5
66-
$cfRange = [OfficeOpenXml.ExcelAddress]::new(2, 3, $ws.Dimension.end.Row, (3 * $wslist.count - 2)).Address
67-
Add-ConditionalFormatting -WorkSheet $ws -range $cfRange -RuleType ContainsText -ConditionValue "Failure" -BackgroundPattern None -ForegroundColor Red -Bold
68-
Add-ConditionalFormatting -WorkSheet $ws -range $cfRange -RuleType ContainsText -ConditionValue "Success" -BackgroundPattern None -ForeGroundColor Green
69-
Close-ExcelPackage $excel
77+
# #Hide everything on 'combined' except test name, results for each browser, and test group, Set column widths, tweak titles, apply conditional formatting.
78+
# $excel = Open-ExcelPackage $RunParameters.XLFile
79+
# $ws = $excel.combined
80+
# 2..$ws.Dimension.end.Column | ForEach-Object {
81+
# if ($ws.Cells[1, $_].value -notmatch '^Name|Result$|PS\dGroup$') {
82+
# Set-ExcelColumn -Worksheet $ws -Column $_ -Hid
83+
# }
84+
# elseif ($ws.Cells[1, $_].value -match 'Result$' ) {
85+
# Set-ExcelColumn -Worksheet $ws -Column $_ -Width 17
86+
# Set-ExcelRange $ws.Cells[1, $_] -WrapText
87+
# }
88+
# if ($ws.cells[1, $_].value -match 'PS\dGroup$') {
89+
# Set-ExcelRange $ws.Cells[1, $_] -WrapText -Value 'Group'
90+
# }
91+
# if ($ws.cells[1, $_].value -match '^Name|PS\dGroup$' -and ($ws.Column($_).Width -gt 80)) {
92+
# $ws.Column($_).Width = 80
93+
# }
94+
# }
95+
# Set-ExcelRow -Worksheet $ws -Height 28.5
96+
# $cfRange = [OfficeOpenXml.ExcelAddress]::new(2, 3, $ws.Dimension.end.Row, (3 * $wslist.count - 2)).Address
97+
# Add-ConditionalFormatting -WorkSheet $ws -range $cfRange -RuleType ContainsText -ConditionValue "Failure" -BackgroundPattern None -ForegroundColor Red -Bold
98+
# Add-ConditionalFormatting -WorkSheet $ws -range $cfRange -RuleType ContainsText -ConditionValue "Success" -BackgroundPattern None -ForeGroundColor Green
99+
# Close-ExcelPackage $excel

CI/Pester-To-XLSx.ps1

Lines changed: 89 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,64 @@
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')]
22
[CmdletBinding(DefaultParameterSetName = 'Default')]
33
param(
4-
[Parameter(Position=0)]
5-
[string]$XLFile,
4+
[Parameter(Position = 0)]
5+
[string]$XLFile,
66

7-
[Parameter(ParameterSetName='Default',Position=1)]
8-
[Alias('Path', 'relative_path')]
9-
[object[]]$Script = '.',
7+
[Parameter(ParameterSetName = 'Default', Position = 1)]
8+
[String]$Path = '.',
109

11-
[Parameter(ParameterSetName='Existing',Mandatory=$true)]
12-
[switch]
13-
$UseExisting,
10+
[Parameter(ParameterSetName = 'Existing', Mandatory = $true)]
11+
[switch]
12+
$UseExisting,
1413

15-
[Parameter(ParameterSetName='Default', Position=2)]
16-
[Parameter(ParameterSetName='Existing',Position=2, Mandatory=$true)]
17-
[string]$OutputFile,
14+
[Parameter(ParameterSetName = 'Default', Position = 2)]
15+
[Parameter(ParameterSetName = 'Existing', Position = 2, Mandatory = $true)]
16+
[string]$OutputFile,
1817

19-
[Parameter(ParameterSetName='Default')]
20-
[Alias("Name")]
21-
[string[]]$TestName,
18+
[Parameter(ParameterSetName = 'Default')]
19+
[Alias("Name")]
20+
[string[]]$TestName,
2221

23-
[Parameter(ParameterSetName='Default')]
24-
[switch]$EnableExit,
22+
[Parameter(ParameterSetName = 'Default')]
23+
[switch]$EnableExit,
2524

26-
[Parameter(ParameterSetName='Default')]
27-
[Alias('Tags')]
28-
[string[]]$Tag,
29-
[string[]]$ExcludeTag,
25+
[Parameter(ParameterSetName = 'Default')]
26+
[Alias('Tags')]
27+
[string[]]$Tag,
28+
[string[]]$ExcludeTag,
3029

31-
[Parameter(ParameterSetName='Default')]
32-
[switch]$Strict,
30+
[Parameter(ParameterSetName = 'Default')]
31+
[switch]$Strict,
3332

34-
[string]$WorkSheetName = 'PesterResults',
35-
[switch]$append,
36-
[switch]$Show
33+
[string]$WorkSheetName = 'PesterResults',
34+
[switch]$append,
35+
[switch]$Show
3736
)
3837

39-
$InvokePesterParams = @{OutputFormat = 'NUnitXml'} + $PSBoundParameters
40-
if (-not $InvokePesterParams['OutputFile']) {
41-
$InvokePesterParams['OutputFile'] = Join-Path -ChildPath 'Pester.xml'-Path ([environment]::GetFolderPath([System.Environment+SpecialFolder]::MyDocuments))
42-
}
43-
if ($InvokePesterParams['Show'] ) {}
44-
if ($InvokePesterParams['XLFile']) {$InvokePesterParams.Remove('XLFile')}
45-
else {$XLFile = $InvokePesterParams['OutputFile'] -replace '.xml$','.xlsx'}
38+
$InvokePesterParams = $PSBoundParameters
39+
40+
if ($InvokePesterParams['XLFile']) { $InvokePesterParams.Remove('XLFile') }
41+
else { $XLFile = $InvokePesterParams['OutputFile'] -replace '.xml$', '.xlsx' }
4642
if (-not $UseExisting) {
47-
$InvokePesterParams.Remove('Append')
48-
$InvokePesterParams.Remove('UseExisting')
49-
$InvokePesterParams.Remove('Show')
50-
$InvokePesterParams.Remove('WorkSheetName')
51-
Invoke-Pester @InvokePesterParams
43+
$InvokePesterParams.Remove('Append') | Out-Null
44+
$InvokePesterParams.Remove('UseExisting') | Out-Null
45+
$InvokePesterParams.Remove('Show') | Out-Null
46+
$InvokePesterParams.Remove('WorkSheetName') | Out-Null
47+
$InvokePesterParams.Remove('OutputFile') | Out-Null
48+
Set-Location $env:ModulePath
49+
Invoke-Pester @InvokePesterParams -CI -Output Detailed -ErrorAction Continue
5250
}
5351

54-
if (-not (Test-Path -Path $InvokePesterParams['OutputFile'])) {
55-
throw "Could not output file $($InvokePesterParams['OutputFile'])"; return
56-
}
52+
# if (-not (Test-Path -Path $InvokePesterParams['OutputFile'])) {
53+
# throw "Could not output file $($InvokePesterParams['OutputFile'])"; return
54+
# }
5755

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-
#$user = $resultXML.environment.'user-domain' + '\' + $resultXML.environment.user
63-
$os = $resultXML.environment.platform -replace '\|.*$'," $($resultXML.environment.'os-version')"
56+
$resultXML = ([xml](Get-Content -Path (Join-Path $env:ModulePath 'testResults.xml'))).'test-results'
57+
$startDate = [datetime]$resultXML.date
58+
$startTime = $resultXML.time
59+
$machine = $resultXML.environment.'machine-name'
60+
$user = $resultXML.environment.'user-domain' + '\' + $resultXML.environment.user
61+
$os = $resultXML.environment.platform -replace '\|.*$', " $($resultXML.environment.'os-version')"
6462
<#hierarchy goes
6563
root, [date], start [time], [Name] (always "Pester"), test results broken down as [total],[errors],[failures],[not-run] etc.
6664
Environment (user & machine info)
@@ -80,52 +78,54 @@ $os = $resultXML.environment.platform -replace '\|.*$'," $($resultXML.e
8078
Test-case [description] - name as rendered for display with <vars> filled in
8179
#>
8280
$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-
}
81+
$testPs1File = $test.name
82+
#Test if there are context blocks in the hierarchy OR if we go straight from Describe to test-case
83+
if ($test.results.'test-suite'.results.'test-suite' -ne $null) {
84+
foreach ($suite in $test.results.'test-suite') {
85+
$Describe = $suite.description
86+
foreach ($subsuite in $suite.results.'test-suite') {
87+
$Context = $subsuite.description
88+
if ($subsuite.results.'test-suite'.results.'test-case') {
89+
$testCases = $subsuite.results.'test-suite'.results.'test-case'
10690
}
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-
}
91+
else { $testCases = $subsuite.results.'test-case' }
92+
$testCases | ForEach-Object {
93+
New-Object -TypeName psobject -Property ([ordered]@{
94+
Machine = $machine ; OS = $os
95+
Date = $startDate ; Time = $startTime
96+
Executed = $(if ($_.executed -eq 'True') { 1 })
97+
Success = $(if ($_.success -eq 'True') { 1 })
98+
Duration = $_.time
99+
File = $testPs1File; Group = $Describe
100+
SubGroup = $Context ; Name = ($_.Description -replace '\s{2,}', ' ')
101+
Result = $_.result ; FullDesc = '=Group&" "&SubGroup&" "&Name'
102+
})
122103
}
104+
}
105+
}
106+
}
107+
else {
108+
$test.results.'test-suite' | ForEach-Object {
109+
$Describe = $_.description
110+
$_.results.'test-case' | ForEach-Object {
111+
New-Object -TypeName psobject -Property ([ordered]@{
112+
Machine = $machine ; OS = $os
113+
Date = $startDate ; Time = $startTime
114+
Executed = $(if ($_.executed -eq 'True') { 1 })
115+
Success = $(if ($_.success -eq 'True') { 1 })
116+
Duration = $_.time
117+
File = $testPs1File; Group = $Describe
118+
SubGroup = $null ; Name = ($_.Description -replace '\s{2,}', ' ')
119+
Result = $_.result ; FullDesc = '=Group&" "&Test'
120+
})
121+
}
123122
}
123+
}
124124
}
125-
if (-not $testResults) {Write-Warning 'No Results found' ; return}
125+
if (-not $testResults) { Write-Warning 'No Results found' ; return }
126126
$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]
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]
129129
<# Worksheet should look like ..
130130
|A |B |C D |E |F |G |H |I |J |K |L |M
131131
1|Machine |OS |Date Time |Executed |Success |Duration |File |Group |SubGroup |Name |Result |FullDescription
@@ -136,7 +136,7 @@ $ws = $excel.Workbook.Worksheets[$WorkSheetName]
136136
Set-Column -Worksheet $ws -Column 3 -NumberFormat 'Short Date' # -AutoSize
137137

138138
#Hide columns E to J (Executed, Success, Duration, File, Group and Subgroup)
139-
(5..10) | ForEach-Object {Set-ExcelColumn -Worksheet $ws -Column $_ -Hide }
139+
(5..10) | ForEach-Object { Set-ExcelColumn -Worksheet $ws -Column $_ -Hide }
140140

141141
#Use conditional formatting to make Failures red, and Successes green (skipped remains black ) ... and save
142142
$endRow = $ws.Dimension.End.Row

0 commit comments

Comments
 (0)