|
1 | 1 | param (
|
2 | | - [string[]]$BrowserList=@('Chrome','Firefox') |
| 2 | + [string[]]$BrowserList=@('Chrome','Firefox') |
3 | 3 | )
|
4 | 4 | #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.
|
5 | | -$Platform = ([environment]::OSVersion.Platform).ToString() + ' PS' + $PSVersionTable.PSVersion.Major |
6 | | -if ($Platform -notlike 'win*') {$env:AlwaysHeadless = $true} |
7 | | -if ($Platform -like 'win*6') { |
8 | | - $env:PSModulePath -split ';' | Where-Object {$_ -match "\w:\\Prog.*PowerShell\\modules"} | ForEach-Object { |
9 | | - $env:PSModulePath = ($_ -replace "PowerShell","WindowsPowerShell") + ";" + $env:PSModulePath |
10 | | - } |
| 5 | +$Platform = ([environment]::OSVersion.Platform).ToString() + ' PS' + $PSVersionTable.PSVersion.Major |
| 6 | +if ($Platform -notlike 'win*') { $env:AlwaysHeadless = $true} |
| 7 | +if ($Platform -like 'win*6') { |
| 8 | + $env:PSModulePath -split ';' | Where-Object {$_ -match "\w:\\Prog.*PowerShell\\modules"} | ForEach-Object { |
| 9 | + $env:PSModulePath = ($_ -replace "PowerShell","WindowsPowerShell") + ";" + $env:PSModulePath |
| 10 | + } |
11 | 11 | }
|
12 | 12 |
|
13 | 13 | #Make sure we have the modules we need
|
14 | | -Import-Module .\Selenium.psd1 -Force -ErrorAction Stop |
| 14 | +Import-Module .\Output\Selenium\Selenium.psd1 -Force -ErrorAction Stop |
15 | 15 | $checkImportExcel = Get-Module -ListAvailable ImportExcel
|
16 | 16 | if (-not ($checkImportExcel)) {
|
17 | 17 | Write-Verbose -Verbose 'Installing ImportExcel'
|
18 | 18 | Install-Module ImportExcel -Force -SkipPublisherCheck
|
19 | 19 | }
|
20 | | -else {$checkImportExcel | Out-Host} |
21 | | -$checkPester = Get-Module -ListAvailable Pester| Where-Object {$_.version.major -ge 4 -and $_.version.minor -ge 4} |
| 20 | +else {$checkImportExcel | Out-Host} |
| 21 | +$checkPester = Get-Module -ListAvailable Pester| Where-Object {$_.version.major -ge 4 -and $_.version.minor -ge 4} |
22 | 22 | if (-not $checkPester) {
|
23 | 23 | Write-Verbose -Verbose 'Installing Pester'
|
24 | 24 | Install-Module Pester -Force -SkipPublisherCheck
|
25 | 25 | }
|
26 | | -else {$checkPester | Out-Host} |
| 26 | +else {$checkPester | Out-Host} |
27 | 27 |
|
28 | 28 | #Run the test and results export to an Excel file for current OS - Test picks up the selected browser from an environment variable.
|
29 | | -$RunParameters = @{ |
30 | | - 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' |
| 29 | +$RunParameters = @{ |
| 30 | + 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' |
32 | 32 | }
|
33 | 33 | foreach ( $b in $BrowserList) {
|
34 | 34 | $env:DefaultBrowser = $b
|
35 | | - $RunParameters['OutputFile'] = Join-Path $pwd "TestResults-$platform$b.xml" |
36 | | - $RunParameters['WorkSheetName'] = "$B $Platform" |
| 35 | + $RunParameters['OutputFile'] = Join-Path $pwd "TestResults-$platform$b.xml" |
| 36 | + $RunParameters['WorkSheetName'] = "$B $Platform" |
37 | 37 | $RunParameters | Out-Host
|
38 | 38 | & "$PSScriptRoot\Pester-To-XLSx.ps1" @RunParameters
|
39 | 39 | }
|
40 | 40 |
|
41 | 41 | #Merge the results sheets into a sheet named 'combined'.
|
42 | | -$excel = Open-ExcelPackage $RunParameters.XLFile |
43 | | -$wslist = $excel.Workbook.Worksheets.name |
| 42 | +$excel = Open-ExcelPackage $RunParameters.XLFile |
| 43 | +$wslist = $excel.Workbook.Worksheets.name |
44 | 44 | Close-ExcelPackage -NoSave $excel
|
45 | | -Merge-MultipleSheets -path $RunParameters.XLFile -WorksheetName $wslist -OutputSheetName combined -OutputFile $RunParameters.XLFile -HideRowNumbers -Property name,result |
| 45 | +Merge-MultipleSheets -path $RunParameters.XLFile -WorksheetName $wslist -OutputSheetName combined -OutputFile $RunParameters.XLFile -HideRowNumbers -Property name,result |
46 | 46 |
|
47 | 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 |
| 48 | +$excel = Open-ExcelPackage $RunParameters.XLFile |
| 49 | +$ws = $excel.combined |
50 | 50 | 2..$ws.Dimension.end.Column | ForEach-Object {
|
51 | | - if ($ws.Cells[1,$_].value -notmatch '^Name|Result$|PS\dGroup$') { |
| 51 | + if ($ws.Cells[1,$_].value -notmatch '^Name|Result$|PS\dGroup$') { |
52 | 52 | Set-ExcelColumn -Worksheet $ws -Column $_ -Hid
|
53 | 53 | }
|
54 | | - elseif ($ws.Cells[1,$_].value -match 'Result$' ) { |
| 54 | + elseif ($ws.Cells[1,$_].value -match 'Result$' ) { |
55 | 55 | Set-ExcelColumn -Worksheet $ws -Column $_ -Width 17
|
56 | | - Set-ExcelRange $ws.Cells[1,$_] -WrapText |
| 56 | + Set-ExcelRange $ws.Cells[1,$_] -WrapText |
57 | 57 | }
|
58 | | - if ($ws.cells[1,$_].value -match 'PS\dGroup$') { |
59 | | - Set-ExcelRange $ws.Cells[1,$_] -WrapText -Value 'Group' |
| 58 | + if ($ws.cells[1,$_].value -match 'PS\dGroup$') { |
| 59 | + Set-ExcelRange $ws.Cells[1,$_] -WrapText -Value 'Group' |
60 | 60 | }
|
61 | | - if ($ws.cells[1,$_].value -match '^Name|PS\dGroup$' -and ($ws.Column($_).Width -gt 80)) { |
| 61 | + if ($ws.cells[1,$_].value -match '^Name|PS\dGroup$' -and ($ws.Column($_).Width -gt 80)) { |
62 | 62 | $ws.Column($_).Width = 80
|
63 | 63 | }
|
64 | 64 | }
|
65 | 65 | Set-ExcelRow -Worksheet $ws -Height 28.5
|
66 | | -$cfRange = [OfficeOpenXml.ExcelAddress]::new(2,3,$ws.Dimension.end.Row, (3*$wslist.count -2)).Address |
| 66 | +$cfRange = [OfficeOpenXml.ExcelAddress]::new(2,3,$ws.Dimension.end.Row, (3*$wslist.count -2)).Address |
67 | 67 | Add-ConditionalFormatting -WorkSheet $ws -range $cfRange -RuleType ContainsText -ConditionValue "Failure" -BackgroundPattern None -ForegroundColor Red -Bold
|
68 | 68 | Add-ConditionalFormatting -WorkSheet $ws -range $cfRange -RuleType ContainsText -ConditionValue "Success" -BackgroundPattern None -ForeGroundColor Green
|
69 | 69 | Close-ExcelPackage $excel
|
0 commit comments