mirror of
https://github.com/actions/runner-images-sangeeth.git
synced 2025-12-20 06:29:50 +00:00
Try installing Google Chrome for Testing (#7997)
This commit is contained in:
committed by
GitHub
parent
0c0af47317
commit
d9169bba1e
@@ -3,80 +3,43 @@
|
|||||||
## Desc: Install Google Chrome
|
## Desc: Install Google Chrome
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
# Download and install latest Chrome browser
|
# Get versions info
|
||||||
$ChromeInstallerFile = "googlechromestandaloneenterprise64.msi"
|
$ChromeVersionsUrl = "https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json"
|
||||||
$ChromeInstallerUrl = "https://dl.google.com/tag/s/dl/chrome/install/${ChromeInstallerFile}"
|
$ChromeVersions = Invoke-RestMethod -Uri $ChromeVersionsUrl
|
||||||
Install-Binary -Url $ChromeInstallerUrl -Name $ChromeInstallerFile -ArgumentList @()
|
$ChromeVersionInfo = $ChromeVersions.channels.Stable
|
||||||
|
|
||||||
# Prepare firewall rules
|
# Install Google Chrome for Testing
|
||||||
Write-Host "Adding the firewall rule for Google update blocking..."
|
$ChromeVersion = $ChromeVersionInfo.version
|
||||||
New-NetFirewallRule -DisplayName "BlockGoogleUpdate" -Direction Outbound -Action Block -Program "C:\Program Files (x86)\Google\Update\GoogleUpdate.exe"
|
$ChromeUrl = ($ChromeVersionInfo.downloads.chrome | Where-Object platform -eq "win64").url
|
||||||
|
|
||||||
$GoogleSvcs = ('gupdate','gupdatem')
|
Write-Host "Installing Google Chrome for Testing version $ChromeVersion"
|
||||||
$GoogleSvcs | Stop-SvcWithErrHandling -StopOnError
|
$ChromePath = "$($env:SystemDrive)\Program Files\Google\Chrome"
|
||||||
$GoogleSvcs | Set-SvcWithErrHandling -Arguments @{StartupType = "Disabled"}
|
if (-not (Test-Path -Path $ChromePath)) {
|
||||||
|
New-Item -Path $ChromePath -ItemType Directory -Force
|
||||||
$regGoogleUpdatePath = "HKLM:\SOFTWARE\Policies\Google\Update"
|
|
||||||
$regGoogleUpdateChrome = "HKLM:\SOFTWARE\Policies\Google\Chrome"
|
|
||||||
($regGoogleUpdatePath, $regGoogleUpdateChrome) | ForEach-Object {
|
|
||||||
New-Item -Path $_ -Force
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$regGoogleParameters = @(
|
$ChromeArchivePath = Start-DownloadWithRetry -Url $ChromeUrl
|
||||||
@{ Name = "AutoUpdateCheckPeriodMinutes"; Value = 00000000},
|
Extract-7Zip -Path $ChromeArchivePath -DestinationPath $ChromePath
|
||||||
@{ Name = "UpdateDefault"; Value = 00000000 },
|
Rename-Item "$ChromePath\chrome-win64" "$ChromePath\Application"
|
||||||
@{ Name = "DisableAutoUpdateChecksCheckboxValue"; Value = 00000001 },
|
|
||||||
@{ Name = "Update{8A69D345-D564-463C-AFF1-A69D9E530F96}"; Value = 00000000 },
|
|
||||||
@{ Path = $regGoogleUpdateChrome; Name = "DefaultBrowserSettingEnabled"; Value = 00000000 }
|
|
||||||
)
|
|
||||||
|
|
||||||
$regGoogleParameters | ForEach-Object {
|
$chromeRegPath = "HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe"
|
||||||
$Arguments = $_
|
New-Item $chromeRegPath
|
||||||
if (-not ($Arguments.Path))
|
Set-ItemProperty $chromeRegPath "(default)" "$ChromePath\Application\chrome.exe"
|
||||||
{
|
|
||||||
$Arguments.Add("Path", $regGoogleUpdatePath)
|
|
||||||
}
|
|
||||||
$Arguments.Add("Force", $true)
|
|
||||||
New-ItemProperty @Arguments
|
|
||||||
}
|
|
||||||
|
|
||||||
# Install Chrome WebDriver
|
# Install Chrome Driver
|
||||||
Write-Host "Install Chrome WebDriver..."
|
$ChromeDriverVersion = $ChromeVersionInfo.version
|
||||||
|
$ChromeDriverUrl = ($ChromeVersionInfo.downloads.chromedriver | Where-Object platform -eq "win64").url
|
||||||
|
|
||||||
|
Write-Host "Installing ChromeDriver version $ChromeDriverVersion"
|
||||||
$ChromeDriverPath = "$($env:SystemDrive)\SeleniumWebDrivers\ChromeDriver"
|
$ChromeDriverPath = "$($env:SystemDrive)\SeleniumWebDrivers\ChromeDriver"
|
||||||
if (-not (Test-Path -Path $ChromeDriverPath))
|
if (-not (Test-Path -Path $ChromeDriverPath)) {
|
||||||
{
|
|
||||||
New-Item -Path $ChromeDriverPath -ItemType Directory -Force
|
New-Item -Path $ChromeDriverPath -ItemType Directory -Force
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "Get the Chrome WebDriver download URL..."
|
$ChromeDriverVersion | Out-File -FilePath "$ChromeDriverPath\versioninfo.txt" -Force;
|
||||||
$RegistryPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths"
|
$ChromeDriverArchivePath = Start-DownloadWithRetry -Url $ChromeDriverUrl
|
||||||
$ChromePath = (Get-ItemProperty "$RegistryPath\chrome.exe").'(default)'
|
Extract-7Zip -Path $ChromeDriverArchivePath -DestinationPath $ChromeDriverPath -ExtractMethod "e"
|
||||||
[version]$ChromeVersion = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($ChromePath).ProductVersion
|
|
||||||
$ChromeBuild = "$($ChromeVersion.Major).$($ChromeVersion.Minor).$($ChromeVersion.Build)"
|
|
||||||
$ChromeDriverVersionsUrl = "https://googlechromelabs.github.io/chrome-for-testing/latest-patch-versions-per-build-with-downloads.json"
|
|
||||||
|
|
||||||
Write-Host "Chrome version is $ChromeVersion"
|
|
||||||
$ChromeDriverVersions = Invoke-RestMethod -Uri $ChromeDriverVersionsUrl
|
|
||||||
$ChromeDriverVersion = $ChromeDriverVersions.builds.$ChromeBuild
|
|
||||||
|
|
||||||
if (-not ($ChromeDriverVersion)) {
|
|
||||||
$availableVersions = $ChromeDriverVersions.builds | Get-Member | Select-Object -ExpandProperty Name
|
|
||||||
Write-Host "Available chromedriver builds are $availableVersions"
|
|
||||||
Throw "Can't determine chromedriver version that matches chrome build $ChromeBuild"
|
|
||||||
}
|
|
||||||
|
|
||||||
$ChromeDriverVersion.version | Out-File -FilePath "$ChromeDriverPath\versioninfo.txt" -Force;
|
|
||||||
|
|
||||||
Write-Host "Chrome WebDriver version to install is $($ChromeDriverVersion.version)"
|
|
||||||
$ChromeDriverZipDownloadUrl = ($ChromeDriverVersion.downloads.chromedriver | Where-Object platform -eq "win64").url
|
|
||||||
|
|
||||||
Write-Host "Download Chrome WebDriver from $ChromeDriverZipDownloadUrl..."
|
|
||||||
$ChromeDriverArchPath = Start-DownloadWithRetry -Url $ChromeDriverZipDownloadUrl
|
|
||||||
|
|
||||||
Write-Host "Expand Chrome WebDriver archive (without using directory names)..."
|
|
||||||
Extract-7Zip -Path $ChromeDriverArchPath -DestinationPath $ChromeDriverPath -ExtractMethod "e"
|
|
||||||
|
|
||||||
Write-Host "Setting the environment variables..."
|
|
||||||
setx ChromeWebDriver "$ChromeDriverPath" /M
|
setx ChromeWebDriver "$ChromeDriverPath" /M
|
||||||
|
|
||||||
$regEnvKey = 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\'
|
$regEnvKey = 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\'
|
||||||
|
|||||||
@@ -28,18 +28,9 @@ Describe "Chrome" {
|
|||||||
$versionInfo | Should -Not -BeNullOrEmpty
|
$versionInfo | Should -Not -BeNullOrEmpty
|
||||||
}
|
}
|
||||||
|
|
||||||
It "gupdate service is stopped" {
|
It "Chrome Product Name should be 'Google Chrome for Testing'" -TestCases @{chromePath = $chromePath } {
|
||||||
$svc = Get-Service -Name gupdate
|
$productName = (Get-Item $chromePath).VersionInfo.ProductName
|
||||||
$svc.Status | Should -BeExactly Stopped
|
$productName | Should -BeExactly "Google Chrome for Testing"
|
||||||
}
|
|
||||||
|
|
||||||
It "gupdatem service is stopped" {
|
|
||||||
$svc = Get-Service -Name gupdatem
|
|
||||||
$svc.Status | Should -BeExactly Stopped
|
|
||||||
}
|
|
||||||
|
|
||||||
It "BlockGoogleUpdate firewall rule exists" {
|
|
||||||
Get-NetFirewallRule -DisplayName BlockGoogleUpdate | Should -Not -BeNullOrEmpty
|
|
||||||
}
|
}
|
||||||
|
|
||||||
It "<chromePath> is installed" -TestCases @{chromePath = $chromePath} {
|
It "<chromePath> is installed" -TestCases @{chromePath = $chromePath} {
|
||||||
|
|||||||
Reference in New Issue
Block a user