From 031f9d95d07c136bc3e56902b84a234113751ce4 Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Thu, 27 Jul 2023 02:50:54 +0900 Subject: [PATCH] Support Chrome for Testing on Windows --- .github/workflows/windows.yml | 13 ++++++++++--- lib/setup-chromedriver.ps1 | 33 +++++++++++++++++++++++++++------ 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 3d08f1b3..962b0881 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -40,9 +40,16 @@ jobs: run: | $chrome_fullversion = (Get-Item $Env:CHROMEAPP).VersionInfo.FileVersion $chrome_majorversion = $chrome_fullversion.Split(".")[0] - $response = Invoke-WebRequest "http://chromedriver.storage.googleapis.com/LATEST_RELEASE_$chrome_majorversion" - $version = $response.Content - echo "CHROMEDRIVER_VERSION=$version" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append + if($chrome_majorversion -lt 115) + { + $response = Invoke-WebRequest "http://chromedriver.storage.googleapis.com/LATEST_RELEASE_$chrome_majorversion" + $version = $response.Content + echo "CHROMEDRIVER_VERSION=$version" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append + } + else + { + echo "CHROMEDRIVER_VERSION=$chrome_fullversion" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append + } - uses: ./ if: matrix.branch == 'now' with: diff --git a/lib/setup-chromedriver.ps1 b/lib/setup-chromedriver.ps1 index e6f434bd..486e9afa 100644 --- a/lib/setup-chromedriver.ps1 +++ b/lib/setup-chromedriver.ps1 @@ -2,15 +2,36 @@ Param( [string]$version ) +$chrome_fullversion = (Get-Item "C:\Program Files\Google\Chrome\Application\chrome.exe").VersionInfo.FileVersion + +Write-Output "Chrome version: $chrome_fullversion" if([string]::IsNullOrEmpty($version)) { - $chrome_fullversion = (Get-Item "C:\Program Files\Google\Chrome\Application\chrome.exe").VersionInfo.FileVersion $chrome_majorversion = $chrome_fullversion.Split(".")[0] +} +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 +} +else +{ + 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 } - -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