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
|
||||
################################################################################
|
||||
|
||||
# Download and install latest Chrome browser
|
||||
$ChromeInstallerFile = "googlechromestandaloneenterprise64.msi"
|
||||
$ChromeInstallerUrl = "https://dl.google.com/tag/s/dl/chrome/install/${ChromeInstallerFile}"
|
||||
Install-Binary -Url $ChromeInstallerUrl -Name $ChromeInstallerFile -ArgumentList @()
|
||||
# Get versions info
|
||||
$ChromeVersionsUrl = "https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json"
|
||||
$ChromeVersions = Invoke-RestMethod -Uri $ChromeVersionsUrl
|
||||
$ChromeVersionInfo = $ChromeVersions.channels.Stable
|
||||
|
||||
# Prepare firewall rules
|
||||
Write-Host "Adding the firewall rule for Google update blocking..."
|
||||
New-NetFirewallRule -DisplayName "BlockGoogleUpdate" -Direction Outbound -Action Block -Program "C:\Program Files (x86)\Google\Update\GoogleUpdate.exe"
|
||||
# Install Google Chrome for Testing
|
||||
$ChromeVersion = $ChromeVersionInfo.version
|
||||
$ChromeUrl = ($ChromeVersionInfo.downloads.chrome | Where-Object platform -eq "win64").url
|
||||
|
||||
$GoogleSvcs = ('gupdate','gupdatem')
|
||||
$GoogleSvcs | Stop-SvcWithErrHandling -StopOnError
|
||||
$GoogleSvcs | Set-SvcWithErrHandling -Arguments @{StartupType = "Disabled"}
|
||||
|
||||
$regGoogleUpdatePath = "HKLM:\SOFTWARE\Policies\Google\Update"
|
||||
$regGoogleUpdateChrome = "HKLM:\SOFTWARE\Policies\Google\Chrome"
|
||||
($regGoogleUpdatePath, $regGoogleUpdateChrome) | ForEach-Object {
|
||||
New-Item -Path $_ -Force
|
||||
Write-Host "Installing Google Chrome for Testing version $ChromeVersion"
|
||||
$ChromePath = "$($env:SystemDrive)\Program Files\Google\Chrome"
|
||||
if (-not (Test-Path -Path $ChromePath)) {
|
||||
New-Item -Path $ChromePath -ItemType Directory -Force
|
||||
}
|
||||
|
||||
$regGoogleParameters = @(
|
||||
@{ Name = "AutoUpdateCheckPeriodMinutes"; Value = 00000000},
|
||||
@{ Name = "UpdateDefault"; Value = 00000000 },
|
||||
@{ Name = "DisableAutoUpdateChecksCheckboxValue"; Value = 00000001 },
|
||||
@{ Name = "Update{8A69D345-D564-463C-AFF1-A69D9E530F96}"; Value = 00000000 },
|
||||
@{ Path = $regGoogleUpdateChrome; Name = "DefaultBrowserSettingEnabled"; Value = 00000000 }
|
||||
)
|
||||
$ChromeArchivePath = Start-DownloadWithRetry -Url $ChromeUrl
|
||||
Extract-7Zip -Path $ChromeArchivePath -DestinationPath $ChromePath
|
||||
Rename-Item "$ChromePath\chrome-win64" "$ChromePath\Application"
|
||||
|
||||
$regGoogleParameters | ForEach-Object {
|
||||
$Arguments = $_
|
||||
if (-not ($Arguments.Path))
|
||||
{
|
||||
$Arguments.Add("Path", $regGoogleUpdatePath)
|
||||
}
|
||||
$Arguments.Add("Force", $true)
|
||||
New-ItemProperty @Arguments
|
||||
}
|
||||
$chromeRegPath = "HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe"
|
||||
New-Item $chromeRegPath
|
||||
Set-ItemProperty $chromeRegPath "(default)" "$ChromePath\Application\chrome.exe"
|
||||
|
||||
# Install Chrome WebDriver
|
||||
Write-Host "Install Chrome WebDriver..."
|
||||
# Install Chrome Driver
|
||||
$ChromeDriverVersion = $ChromeVersionInfo.version
|
||||
$ChromeDriverUrl = ($ChromeVersionInfo.downloads.chromedriver | Where-Object platform -eq "win64").url
|
||||
|
||||
Write-Host "Installing ChromeDriver version $ChromeDriverVersion"
|
||||
$ChromeDriverPath = "$($env:SystemDrive)\SeleniumWebDrivers\ChromeDriver"
|
||||
if (-not (Test-Path -Path $ChromeDriverPath))
|
||||
{
|
||||
if (-not (Test-Path -Path $ChromeDriverPath)) {
|
||||
New-Item -Path $ChromeDriverPath -ItemType Directory -Force
|
||||
}
|
||||
|
||||
Write-Host "Get the Chrome WebDriver download URL..."
|
||||
$RegistryPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths"
|
||||
$ChromePath = (Get-ItemProperty "$RegistryPath\chrome.exe").'(default)'
|
||||
[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"
|
||||
$ChromeDriverVersion | Out-File -FilePath "$ChromeDriverPath\versioninfo.txt" -Force;
|
||||
$ChromeDriverArchivePath = Start-DownloadWithRetry -Url $ChromeDriverUrl
|
||||
Extract-7Zip -Path $ChromeDriverArchivePath -DestinationPath $ChromeDriverPath -ExtractMethod "e"
|
||||
|
||||
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
|
||||
|
||||
$regEnvKey = 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\'
|
||||
|
||||
@@ -28,18 +28,9 @@ Describe "Chrome" {
|
||||
$versionInfo | Should -Not -BeNullOrEmpty
|
||||
}
|
||||
|
||||
It "gupdate service is stopped" {
|
||||
$svc = Get-Service -Name gupdate
|
||||
$svc.Status | Should -BeExactly Stopped
|
||||
}
|
||||
|
||||
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 "Chrome Product Name should be 'Google Chrome for Testing'" -TestCases @{chromePath = $chromePath } {
|
||||
$productName = (Get-Item $chromePath).VersionInfo.ProductName
|
||||
$productName | Should -BeExactly "Google Chrome for Testing"
|
||||
}
|
||||
|
||||
It "<chromePath> is installed" -TestCases @{chromePath = $chromePath} {
|
||||
|
||||
Reference in New Issue
Block a user