Improve Windows browsers provisioners stability (#725)

* Improve Chrome provisioner

* Improve Edge provisioner

* Improve Firefox provisioner

* Resolve conflicts in Install-Chrome.ps1
This commit is contained in:
Maksim Petrov
2020-05-06 07:19:15 +03:00
committed by GitHub
parent 3fba9caa4f
commit 3f36d8ef35
3 changed files with 96 additions and 125 deletions

View File

@@ -3,23 +3,25 @@
## Desc: Install Google Chrome ## Desc: Install Google Chrome
################################################################################ ################################################################################
Import-Module -Name ImageHelpers -Force; Import-Module -Name ImageHelpers -Force
$ChromeInstallerFile = "chrome_installer.exe"; # Download and install latest Chrome browser
$ChromeInstallerUrl = "https://dl.google.com/chrome/install/375.126/${ChromeInstallerFile}"; $ChromeInstallerFile = "chrome_installer.exe"
$ChromeInstallerUrl = "https://dl.google.com/chrome/install/375.126/${ChromeInstallerFile}"
Install-Binary -Url $ChromeInstallerUrl -Name $ChromeInstallerFile -ArgumentList ("/silent", "/install") Install-Binary -Url $ChromeInstallerUrl -Name $ChromeInstallerFile -ArgumentList ("/silent", "/install")
Write-Host "Adding the firewall rule for Google update blocking"; # Prepare firewall rules
New-NetFirewallRule -DisplayName "BlockGoogleUpdate" -Direction Outbound -Action Block -Program "C:\Program Files (x86)\Google\Update\GoogleUpdate.exe"; 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"
$GoogleSvcs = ('gupdate','gupdatem'); $GoogleSvcs = ('gupdate','gupdatem')
$GoogleSvcs | Stop-SvcWithErrHandling -StopOnError; $GoogleSvcs | Stop-SvcWithErrHandling -StopOnError
$GoogleSvcs | Set-SvcWithErrHandling -Arguments @{StartupType = "Disabled"}; $GoogleSvcs | Set-SvcWithErrHandling -Arguments @{StartupType = "Disabled"}
$regGoogleUpdatePath = "HKLM:\SOFTWARE\Policies\Google\Update"; $regGoogleUpdatePath = "HKLM:\SOFTWARE\Policies\Google\Update"
$regGoogleUpdateChrome = "HKLM:\SOFTWARE\Policies\Google\Chrome"; $regGoogleUpdateChrome = "HKLM:\SOFTWARE\Policies\Google\Chrome"
($regGoogleUpdatePath, $regGoogleUpdateChrome) | ForEach-Object { ($regGoogleUpdatePath, $regGoogleUpdateChrome) | ForEach-Object {
New-Item -Path $_ -Force; New-Item -Path $_ -Force
} }
$regGoogleParameters = @( $regGoogleParameters = @(
@@ -31,52 +33,45 @@ $regGoogleParameters = @(
) )
$regGoogleParameters | ForEach-Object { $regGoogleParameters | ForEach-Object {
$Arguments = $_; $Arguments = $_
if (-not ($Arguments.Path)) { if (-not ($Arguments.Path))
$Arguments.Add("Path", $regGoogleUpdatePath); {
$Arguments.Add("Path", $regGoogleUpdatePath)
} }
$Arguments.Add("Force", $true); $Arguments.Add("Force", $true)
New-ItemProperty @Arguments; New-ItemProperty @Arguments
} }
# Reinstall Chrome Web Driver # Install Chrome WebDriver
Write-Host "Install Chrome WebDriver" Write-Host "Install Chrome WebDriver..."
$DestinationPath = "$($env:SystemDrive)\"; $ChromeDriverPath = "$($env:SystemDrive)\SeleniumWebDrivers\ChromeDriver"
$ChromeDriverPath = "${DestinationPath}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"
} }
Write-Host "Get the Chrome WebDriver version..."
$RegistryPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths" $RegistryPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths"
$ChromePath = (Get-ItemProperty "$RegistryPath\chrome.exe").'(default)'; $ChromePath = (Get-ItemProperty "$RegistryPath\chrome.exe").'(default)'
[version]$ChromeVersion = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($ChromePath).ProductVersion; [version]$ChromeVersion = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($ChromePath).ProductVersion
Write-Host "Chrome version: [$ChromeVersion]"; $ChromeDriverVersionUrl = "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_$($ChromeVersion.Major).$($ChromeVersion.Minor).$($ChromeVersion.Build)"
$ChromeDriverVersionUri = "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_$($ChromeVersion.Major).$($ChromeVersion.Minor).$($ChromeVersion.Build)"; $ChromeDriverVersionFile = Start-DownloadWithRetry -Url $ChromeDriverVersionUrl -Name "versioninfo.txt" -DownloadPath $ChromeDriverPath
Write-Host "Chrome driver version Uri [$ChromeDriverVersionUri]";
Write-Host "Getting the Chrome driver version...";
$ChromeDriverVersion = Invoke-WebRequest -Uri $ChromeDriverVersionUri;
Write-Host "Current Chrome driver version: [$ChromeDriverVersion]";
$ChromeDriverZipDownloadUri = "https://chromedriver.storage.googleapis.com/$($ChromeDriverVersion.ToString())/chromedriver_win32.zip"; Write-Host "Download Chrome WebDriver..."
Write-Host "Chrome driver zip file download Uri: [$ChromeDriverZipDownloadUri]"; $ChromeDriverVersion = Get-Content -Path $ChromeDriverVersionFile
$ChromeDriverArchName = "chromedriver_win32.zip"
$ChromeDriverZipDownloadUrl = "https://chromedriver.storage.googleapis.com/${ChromeDriverVersion}/${ChromeDriverArchName}"
$DestFile= "$ChromeDriverPath\chromedriver_win32.zip"; $ChromeDriverArchPath = Start-DownloadWithRetry -Url $ChromeDriverZipDownloadUrl -Name $ChromeDriverArchName
$ChromeDriverVersion.Content | Out-File -FilePath "$ChromeDriverPath\versioninfo.txt" -Force;
Write-Host "Chrome driver download...."; Write-Host "Expand Chrome WebDriver archive..."
Invoke-WebRequest -Uri $ChromeDriverZipDownloadUri -OutFile $DestFile; Expand-Archive -Path $ChromeDriverArchPath -DestinationPath $ChromeDriverPath -Force
Write-Host "Chrome driver install...."; Write-Host "Setting the environment variables..."
Expand-Archive -Path "$ChromeDriverPath\chromedriver_win32.zip" -DestinationPath $ChromeDriverPath -Force; setx ChromeWebDriver "$ChromeDriverPath" /M
Remove-Item -Path "$ChromeDriverPath\chromedriver_win32.zip" -Force;
Write-Host "Setting the environment variables" $regEnvKey = 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\'
$PathValue = Get-ItemPropertyValue -Path $regEnvKey -Name 'Path'
setx ChromeWebDriver "$ChromeDriverPath" /M; $PathValue += ";$ChromeDriverPath\"
Set-ItemProperty -Path $regEnvKey -Name 'Path' -Value $PathValue
$regEnvKey = 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\';
$PathValue = Get-ItemPropertyValue -Path $regEnvKey -Name 'Path';
$PathValue += ";$ChromeDriverPath\";
Set-ItemProperty -Path $regEnvKey -Name 'Path' -Value $PathValue;

View File

@@ -6,36 +6,35 @@
Choco-Install -PackageName microsoft-edge Choco-Install -PackageName microsoft-edge
# Install Microsoft Edge WebDriver # Install Microsoft Edge WebDriver
Write-Host "Install Edge WebDriver" Write-Host "Install Edge WebDriver..."
$DestinationPath = "$($env:SystemDrive)\"; $EdgeDriverPath = "$($env:SystemDrive)\SeleniumWebDrivers\EdgeDriver"
if (-not (Test-Path -Path $EdgeDriverPath))
$EdgeDriverPath = "${DestinationPath}SeleniumWebDrivers\EdgeDriver" {
if (-not (Test-Path -Path $EdgeDriverPath)) { New-Item -Path $EdgeDriverPath -ItemType Directory -Force
New-Item -Path $EdgeDriverPath -ItemType "directory"
} }
Write-Host "Get the Microsoft Edge WebDriver version..."
$RegistryPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths" $RegistryPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths"
$EdgePath = (Get-ItemProperty "$RegistryPath\msedge.exe").'(default)' $EdgePath = (Get-ItemProperty "$RegistryPath\msedge.exe").'(default)'
[version]$EdgeVersion = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($EdgePath).ProductVersion [version]$EdgeVersion = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($EdgePath).ProductVersion
$EdgeDriverVersionUrl = "https://msedgedriver.azureedge.net/LATEST_RELEASE_$($EdgeVersion.Major)" $EdgeDriverVersionUrl = "https://msedgedriver.azureedge.net/LATEST_RELEASE_$($EdgeVersion.Major)"
$EdgeDriverVersionFile = "$EdgeDriverPath\versioninfo.txt"
Invoke-WebRequest -Uri $EdgeDriverVersionUrl -OutFile $EdgeDriverVersionFile
Write-Host "Microsoft Edge driver download started" $EdgeDriverVersionFile = Start-DownloadWithRetry -Url $EdgeDriverVersionUrl -Name "versioninfo.txt" -DownloadPath $EdgeDriverPath
Write-Host "Download Microsoft Edge WebDriver..."
$EdgeDriverLatestVersion = Get-Content -Path $EdgeDriverVersionFile $EdgeDriverLatestVersion = Get-Content -Path $EdgeDriverVersionFile
$EdgeDriverDownloadUrl="https://msedgedriver.azureedge.net/${EdgeDriverLatestVersion}/edgedriver_win64.zip" $EdgeDriverArchName = "edgedriver_win64.zip"
$DestFile = "$EdgeDriverPath\edgedriver_win64.zip" $EdgeDriverDownloadUrl="https://msedgedriver.azureedge.net/${EdgeDriverLatestVersion}/${EdgeDriverArchName}"
Invoke-WebRequest -Uri $EdgeDriverDownloadUrl -OutFile $DestFile
Write-Host "Microsoft Edge driver installation started" $EdgeDriverArchPath = Start-DownloadWithRetry -Url $EdgeDriverDownloadUrl -Name $EdgeDriverArchName
Expand-Archive -Path $DestFile -DestinationPath $EdgeDriverPath -Force
Remove-Item -Path $DestFile -Force
Write-Host "Setting the environment variables" Write-Host "Expand Microsoft Edge WebDriver archive..."
Expand-Archive -Path $EdgeDriverArchPath -DestinationPath $EdgeDriverPath -Force
setx EdgeWebDriver "$EdgeDriverPath" /M; Write-Host "Setting the environment variables..."
setx EdgeWebDriver "$EdgeDriverPath" /M
$regEnvKey = 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\'; $regEnvKey = 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\'
$PathValue = Get-ItemPropertyValue -Path $regEnvKey -Name 'Path'; $PathValue = Get-ItemPropertyValue -Path $regEnvKey -Name 'Path'
$PathValue += ";$EdgeDriverPath\"; $PathValue += ";$EdgeDriverPath\"
Set-ItemProperty -Path $regEnvKey -Name 'Path' -Value $PathValue; Set-ItemProperty -Path $regEnvKey -Name 'Path' -Value $PathValue

View File

@@ -5,71 +5,48 @@
Import-Module -Name ImageHelpers -Force Import-Module -Name ImageHelpers -Force
$temp_install_dir = 'C:\Windows\Installer' # Install and configure Firefox browser
New-Item -Path $temp_install_dir -ItemType Directory -Force Write-Host "Install latest Firefox browser..."
$VersionsManifest = Invoke-RestMethod "https://product-details.mozilla.org/1.0/firefox_versions.json"
$InstallerName = "firefox-browser.exe"
$InstallerUrl = "https://download.mozilla.org/?product=firefox-$($VersionsManifest.LATEST_FIREFOX_VERSION)&os=win64&lang=en-US"
$ArgumentList = ("/silent", "/install")
$versionsJson = Invoke-RestMethod "https://product-details.mozilla.org/1.0/firefox_versions.json" Install-Binary -Url $InstallerUrl -Name $InstallerName -ArgumentList $ArgumentList
$latestVersion = $versionsJson.LATEST_FIREFOX_VERSION
Write-Host "Firefox latest version: $latestVersion"
# url for latest version of firefox Write-Host "Disable autoupdate..."
$urlLatestVersion = "https://download.mozilla.org/?product=firefox-${latestVersion}&os=win64&lang=en-US" $FirefoxDirectoryPath = Join-Path $env:ProgramFiles "Mozilla Firefox"
Install-Binary -Url $urlLatestVersion -Name "Firefox Setup $latestVersion.exe" -ArgumentList ("/silent", "/install") New-Item -path $FirefoxDirectoryPath -Name 'mozilla.cfg' -Value '//
# Disable autoupdate
$firefoxDirectoryPath = Join-Path $env:ProgramFiles "Mozilla Firefox"
New-Item -path $firefoxDirectoryPath -Name 'mozilla.cfg' -Value '//
pref("browser.shell.checkDefaultBrowser", false); pref("browser.shell.checkDefaultBrowser", false);
pref("app.update.enabled", false);' -ItemType file -force pref("app.update.enabled", false);' -ItemType file -force
$firefoxPreferencesFolder = Join-Path $firefoxDirectoryPath "defaults\pref" $FirefoxPreferencesFolder = Join-Path $FirefoxDirectoryPath "defaults\pref"
New-Item -path $firefoxPreferencesFolder -Name 'local-settings.js' -Value 'pref("general.config.obscure_value", 0); New-Item -path $FirefoxPreferencesFolder -Name 'local-settings.js' -Value 'pref("general.config.obscure_value", 0);
pref("general.config.filename", "mozilla.cfg");' -ItemType file -force pref("general.config.filename", "mozilla.cfg");' -ItemType file -force
# Install Firefox gecko Web Driver # Download and install Gecko WebDriver
Write-Host "Install Firefox WebDriver" Write-Host "Install Gecko WebDriver..."
$DestinationPath = "$($env:SystemDrive)\"; $GeckoDriverPath = "$($env:SystemDrive)\SeleniumWebDrivers\GeckoDriver"
$SeleniumWebDriverPath = Join-Path $DestinationPath "SeleniumWebDrivers" if (-not (Test-Path -Path $GeckoDriverPath))
{
$geckodriverJson = Invoke-RestMethod "https://api.github.com/repos/mozilla/geckodriver/releases/latest" New-Item -Path $GeckoDriverPath -ItemType Directory -Force
$geckodriverWindowsAsset = $geckodriverJson.assets | Where-Object { $_.name -Match "win64" } | Select-Object -First 1
$geckodriverVersion = $geckodriverJson.tag_name
Write-Host "Geckodriver version: $geckodriverVersion"
$DriversZipFile = $geckodriverWindowsAsset.name
Write-Host "Selenium drivers download and install..."
$FirefoxDriverPath = Join-Path $SeleniumWebDriverPath "GeckoDriver"
if (-not (Test-Path -Path $FirefoxDriverPath)) {
New-Item -Path $FirefoxDriverPath -ItemType "directory"
} }
$geckodriverVersion.Substring(1) | Out-File -FilePath "$FirefoxDriverPath\versioninfo.txt" -Force; Write-Host "Get the Gecko WebDriver version..."
$GeckoDriverJson = Invoke-RestMethod "https://api.github.com/repos/mozilla/geckodriver/releases/latest"
$GeckoDriverWindowsAsset = $GeckoDriverJson.assets | Where-Object { $_.name -Match "win64" } | Select-Object -First 1
$GeckoDriverVersion = $GeckoDriverJson.tag_name
$GeckoDriverVersion.Substring(1) | Out-File -FilePath "$GeckoDriverPath\versioninfo.txt" -Force;
# Install Firefox Web Driver Write-Host "Download Gecko WebDriver WebDriver..."
Write-Host "FireFox driver download...." $GeckoDriverArchName = $GeckoDriverWindowsAsset.name
if (-not (Test-Path -Path $FireFoxDriverPath)) { $GeckoDriverDownloadUrl = $GeckoDriverWindowsAsset.browser_download_url
New-Item -Path $FireFoxDriverPath -ItemType "directory"
}
$DestFile = Join-Path $FireFoxDriverPath $DriversZipFile $GeckoDriverArchPath = Start-DownloadWithRetry -Url $GeckoDriverDownloadUrl -Name $GeckoDriverArchName
$FireFoxDriverDownloadUrl = $geckodriverWindowsAsset.browser_download_url
try{
Invoke-WebRequest -Uri $FireFoxDriverDownloadUrl -OutFile $DestFile
} catch {
Write-Error "[!] Failed to download $DriversZipFile"
exit 1
}
Write-Host "FireFox driver install...." Write-Host "Expand Gecko WebDriver archive..."
Expand-Archive -Path $DestFile -DestinationPath $FireFoxDriverPath -Force Expand-Archive -Path $GeckoDriverArchPath -DestinationPath $GeckoDriverPath -Force
Remove-Item -Path $DestFile -Force
Write-Host "Setting the environment variables..."
Write-Host "Setting the environment variables" Add-MachinePathItem -PathItem $GeckoDriverPath
Add-MachinePathItem -PathItem $FireFoxDriverPath setx GeckoWebDriver "$GeckoDriverPath" /M
setx GeckoWebDriver "$FirefoxDriverPath" /M;
exit 0