From bf2aafad27564e9657c3b632b5b2f2c678132a02 Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Mon, 10 Feb 2020 14:38:11 +0300 Subject: [PATCH] add to firefoxdriver to path and fix some styling --- .../scripts/Installers/Install-Firefox.ps1 | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/images/win/scripts/Installers/Install-Firefox.ps1 b/images/win/scripts/Installers/Install-Firefox.ps1 index 228c6284f..d818b28b8 100644 --- a/images/win/scripts/Installers/Install-Firefox.ps1 +++ b/images/win/scripts/Installers/Install-Firefox.ps1 @@ -4,6 +4,8 @@ ################################################################################ Import-Module -Name ImageHelpers -Force +Import-Module -Name PathHelpers -Force + $temp_install_dir = 'C:\Windows\Installer' New-Item -Path $temp_install_dir -ItemType Directory -Force @@ -12,11 +14,11 @@ $latestVersion = $($versionsJson.LATEST_FIREFOX_VERSION) Write-Host "Firefox latest version: $latestVersion" # url for latest version of firefox -$urlLatestVersion = "https://download.mozilla.org/?product=firefox-latest&os=win64&lang=en-US" +$urlLatestVersion = "https://download.mozilla.org/?product=firefox-${latestVersion}&os=win64&lang=en-US" Install-EXE -Url $urlLatestVersion -Name "Firefox Setup $latestVersion.exe" -ArgumentList ("/silent", "/install") # Disable autoupdate -$firefoxDirectoryPath = '{0}\Program Files\Mozilla Firefox\' -f $env:SystemDrive; +$firefoxDirectoryPath = Join-Path $env:SystemDrive "Program Files\Mozilla Firefox" New-Item -path $firefoxDirectoryPath -Name 'mozilla.cfg' -Value '// pref("browser.shell.checkDefaultBrowser", false); pref("app.update.enabled", false);' -ItemType file -force @@ -26,7 +28,6 @@ New-Item -path $firefoxPreferencesFolder -Name 'local-settings.js' -Value 'pref( pref("general.config.filename", "mozilla.cfg");' -ItemType file -force Write-Host "Install Firefox WebDriver" -$DestinationPath = "$($env:SystemDrive)\"; $geckodriverJson = Invoke-RestMethod "https://api.github.com/repos/mozilla/geckodriver/releases/latest" $geckodriverWindowsAsset = $geckodriverJson.assets | Where-Object { $_.name -Match "win64" } | Select-Object -First 1 @@ -35,9 +36,9 @@ Write-Host "Geckodriver version: $($geckodriverJson.tag_name)" $DriversZipFile = $geckodriverWindowsAsset.name -Write-Host "Selenium drivers download and install..."; +Write-Host "Selenium drivers download and install..." -$FirefoxDriverPath = "${DestinationPath}SeleniumWebDrivers\GeckoDriver"; +$FirefoxDriverPath = Join-Path $env:SystemDrive "SeleniumWebDrivers\GeckoDriver" # Install Firefox Web Driver Write-Host "FireFox driver download...." @@ -50,8 +51,8 @@ $EdgeDriverDownloadUrl = $geckodriverWindowsAsset.browser_download_url try{ Invoke-WebRequest -Uri $EdgeDriverDownloadUrl -OutFile $DestFile } catch { - Write-Error "[!] Failed to download $name"; - exit 1; + Write-Error "[!] Failed to download $name" + exit 1 } Write-Host "FireFox driver install...." @@ -60,10 +61,10 @@ Remove-Item -Path $DestFile -Force Write-Host "Setting the environment variables" -setx GeckoWebDriver "$FireFoxDriverPath" /M; +Add-MachinePathItem -PathItem $FireFoxDriverPath -$regEnvKey = 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\'; -$PathValue = Get-ItemPropertyValue -Path $regEnvKey -Name 'Path'; -$PathValue += ";$FireFoxDriverPath"; +$regEnvKey = 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\' +$PathValue = Get-ItemPropertyValue -Path $regEnvKey -Name 'Path' +$PathValue += ";$FireFoxDriverPath" Set-ItemProperty -Path $regEnvKey -Name 'Path' -Value $PathValue -exit 0; \ No newline at end of file +exit 0 \ No newline at end of file