Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fallback latest version in powershell script #224

Merged
merged 1 commit into from
Sep 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 28 additions & 12 deletions lib/setup-chromedriver.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Param(
[string]$version
)

$json_url = "https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json"
$chrome_fullversion = (Get-Item "C:\Program Files\Google\Chrome\Application\chrome.exe").VersionInfo.FileVersion

Write-Output "Chrome version: $chrome_fullversion"
Expand All @@ -13,25 +14,40 @@ else
{
$chrome_majorversion = $version.Split(".")[0]
}

if($chrome_majorversion -lt 115)
{
$response = Invoke-WebRequest "http://chromedriver.storage.googleapis.com/LATEST_RELEASE_$chrome_majorversion"
$version = $response.Content
Invoke-WebRequest "https://chromedriver.storage.googleapis.com/$version/chromedriver_win32.zip" -OutFile chromedriver_win32.zip
Expand-Archive -Path chromedriver_win32.zip -DestinationPath C:\SeleniumWebDrivers\ChromeDriver -Force
Remove-Item chromedriver_win32.zip
Return 0
}
else

if([string]::IsNullOrEmpty($version))
{
$version = $chrome_fullversion
}

$arch = "win32"
Write-Output $arch

Write-Output "Downloading $json_url..."
$json = Invoke-WebRequest $json_url -UseBasicParsing | ConvertFrom-Json
$url = $json | Select-Object -ExpandProperty versions | Where-Object { $_.version -eq $version } | Select-Object -ExpandProperty downloads | Select-Object -ExpandProperty chromedriver | Where-Object { $_.platform -eq $arch } | Select-Object -ExpandProperty url
if (!$url)
{
if([string]::IsNullOrEmpty($version))
{
$version = $chrome_fullversion
}
$arch = "win32"
Write-Output $arch
$url = Invoke-WebRequest "https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json" -UseBasicParsing | ConvertFrom-Json | Select-Object -ExpandProperty versions | Where-Object { $_.version -eq $version } | Select-Object -ExpandProperty downloads | Select-Object -ExpandProperty chromedriver | Where-Object { $_.platform -eq $arch } | Select-Object -ExpandProperty url
Invoke-WebRequest $url -OutFile chromedriver-win32.zip
Expand-Archive -Path chromedriver-win32.zip -Force
Move-Item -Path .\chromedriver-win32\chromedriver-win32\chromedriver.exe -Destination C:\SeleniumWebDrivers\ChromeDriver -Force
Remove-Item chromedriver-win32.zip
Write-Output "Falling back to latest version of ChromeDriver for $arch"
$version3 = $version.Substring(0, $version.LastIndexOf('.'))
Write-Output "VERSION3 = $version3"
$version = $json | ConvertFrom-Json | Select-Object -ExpandProperty versions | Where-Object { $_.version -like "$version3.*" } | Select-Object -Last 1 -ExpandProperty version
Write-Output "VERSION = $version"
$url = $json | Select-Object -ExpandProperty versions | Where-Object { $_.version -eq $version } | Select-Object -ExpandProperty downloads | Select-Object -ExpandProperty chromedriver | Where-Object { $_.platform -eq $arch } | Select-Object -ExpandProperty url
}
Write-Output "Installing ChromeDriver $version for $arch"
Write-Output "Downloading $url..."
Invoke-WebRequest $url -OutFile chromedriver-win32.zip
Expand-Archive -Path chromedriver-win32.zip -Force
Move-Item -Path .\chromedriver-win32\chromedriver-win32\chromedriver.exe -Destination C:\SeleniumWebDrivers\ChromeDriver -Force
Remove-Item chromedriver-win32.zip
Loading