Skip to content

Commit

Permalink
Smoke test periodically fails (#728)
Browse files Browse the repository at this point in the history
* Rework download logic

* Fix file path

* Fix clean up

* Update Testing/Functional/SmokeTest/UpdateSelenium.ps1

Co-authored-by: Addam Schroll <108814318+schrolla@users.noreply.github.com>

* Add error action to download

---------

Co-authored-by: Addam Schroll <108814318+schrolla@users.noreply.github.com>
  • Loading branch information
crutchfield and schrolla authored Dec 13, 2023
1 parent 883815c commit f7cd368
Showing 1 changed file with 43 additions and 8 deletions.
51 changes: 43 additions & 8 deletions Testing/Functional/SmokeTest/UpdateSelenium.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,42 @@ function Confirm-NeedForUpdate{
return ([System.Version]$v2).Major -lt ([System.Version]$v1).Major
}

function DownLoadDriver{
param(
[Parameter(Mandatory=$true)]
[Uri]
$DownloadUrl,
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]
$WebDriversPath,
[Parameter(Mandatory=$true)]
[ValidateScript({Test-Path -Path $_ -PathType Container})]
[string]
$DriverTempPath
)

Write-Debug -Message "Downloading $DownloadUrl"

try {
Invoke-WebRequest $DownloadUrl -OutFile "$DriverTempPath\chromeNewDriver.zip" -ErrorAction 'Stop' 2>&1 | Out-Null

Expand-Archive "$DriverTempPath\chromeNewDriver.zip" -DestinationPath $DriverTempPath -Force

if (Test-Path "$($WebDriversPath)\chromedriver.exe") {
Remove-Item -Path "$($WebDriversPath)\chromedriver.exe" -Force
}

Move-Item "$DriverTempPath\chromedriver-win64\chromedriver.exe" -Destination "$($WebDriversPath)\chromedriver.exe" -Force
}
catch {
Write-Error "Failed to get web driver for use with Selenium.`n $_"
return $false
}

return $true
}

$DebugPreference = 'Continue'
#$DebugPreference = 'SilentlyContinue'

Expand All @@ -83,23 +119,22 @@ if (Confirm-NeedForUpdate $chromeVersion $localDriverVersion){
Where-Object {$_.Platform -eq 'win64'}
$DownloadUrl = $Download.Url

Write-Debug -Message "Dowloading $DownloadUrl"
$DriverTempPath = Join-Path -Path $PSScriptRoot -ChildPath "chromeNewDriver"

if (-not (Test-Path -Path $DriverTempPath -PathType Container)){
New-Item -ItemType Directory -Path $DriverTempPath
}

Invoke-WebRequest $DownloadUrl -OutFile "$DriverTempPath\chromeNewDriver.zip"
$DownloadSuccessful = $false
$MaxRetry = 3

Expand-Archive "$DriverTempPath\chromeNewDriver.zip" -DestinationPath $DriverTempPath -Force
if (Test-Path "$($webDriversPath)\chromedriver.exe") {
Remove-Item -Path "$($webDriversPath)\chromedriver.exe" -Force
while((-not $DownloadSuccessful) -and (0 -gt $MaxRetry--)){
$DownloadSuccessful = DownloadDriver -DownloadUrl $DownloadUrl -WebDriversPath $webDriversPath -DriverTempPath $DriverTempPath
}
Move-Item "$DriverTempPath\chromedriver-win64\chromedriver.exe" -Destination "$($webDriversPath)\chromedriver.exe" -Force

# clean-up
Remove-Item "$DriverTempPath\chromeNewDriver.zip" -Force
Remove-Item $DriverTempPath\ -Recurse -Force
if (Test-Path -Path $DriverTempPath){
Remove-Item $DriverTempPath -Recurse -Force
}
}
#endregion MAIN SCRIPT

0 comments on commit f7cd368

Please sign in to comment.