From e3df777d31a7c802c16f077c396ae338e7a76d5d Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov <“shibanov-1997@inbox.ru”> Date: Thu, 6 Feb 2020 19:31:18 +0300 Subject: [PATCH] add installation --- .../scripts/Installers/Install-Firefox.ps1 | 67 ++++++++++++++++++- .../Installers/Install-SeleniumWebDrivers.ps1 | 2 +- 2 files changed, 66 insertions(+), 3 deletions(-) diff --git a/images/win/scripts/Installers/Install-Firefox.ps1 b/images/win/scripts/Installers/Install-Firefox.ps1 index 560c7148e..2ab7a66f9 100644 --- a/images/win/scripts/Installers/Install-Firefox.ps1 +++ b/images/win/scripts/Installers/Install-Firefox.ps1 @@ -4,11 +4,19 @@ ################################################################################ Import-Module -Name ImageHelpers -Force - +# https://github.com/mozilla/geckodriver/releases/latest - geckodriver for firefox $temp_install_dir = 'C:\Windows\Installer' New-Item -Path $temp_install_dir -ItemType Directory -Force -Install-EXE -Url "https://seleniumwebdrivers.blob.core.windows.net/knownfirefoxversion/FirefoxSetup.exe" -Name "FirefoxSetup.exe" -ArgumentList "-ms" +$firefoxJson = Invoke-WebRequest "https://product-details.mozilla.org/1.0/firefox_versions.json" | ConvertFrom-Json + +Write-Host "Firefox json" +Write-Host $firefoxJson + +$latestVersion = $($firefoxJson.LATEST_FIREFOX_VERSION) +Write-Host "Firefox latest version $latestVersion" + +Install-EXE -Url "https://seleniumwebdrivers.blob.core.windows.net/knownfirefoxversion/FirefoxSetup.exe" -Name "Firefox Setup $latestVersion" -ArgumentList "-ms" $path = '{0}\Program Files\Mozilla Firefox\' -f $env:SystemDrive; New-Item -path $path -Name 'mozilla.cfg' -Value '// @@ -18,3 +26,58 @@ pref("app.update.enabled", false);' -ItemType file -force $path = '{0}\Program Files\Mozilla Firefox\defaults\pref\' -f $env:SystemDrive; New-Item -path $path -Name 'local-settings.js' -Value 'pref("general.config.obscure_value", 0); pref("general.config.filename", "mozilla.cfg");' -ItemType file -force + +# section for installing selenium web driver +Write-Host "Install selenium" + +gci env:* | sort-object name + +$DestinationPath = "$($env:SystemDrive)\"; + +$geckodriverJson = Invoke-RestMethod "https://api.github.com/repos/mozilla/geckodriver/releases/latest" + $geckodriverJson.assets | ForEach-Object -Process { + if ($_.name -Match "win64") + { + $name = $_.name + $adress = $_.browser_download_url + } + } + + +Write-Host "Name of firefox zip file $name" +Write-Host "Install url $adress" + +$DriversZipFile = $name +Write-Host "Destination path: [$DestinationPath]"; +Write-Host "Selenium drivers download and install..."; + +$FireFoxDriverPath = "${DestinationPath}SeleniumWebDrivers\GeckoDriver"; + +# Install Fire Fox Web Driver +Write-Host "FireFox driver download...." +if (-not (Test-Path -Path $FireFoxDriverPath)) { + New-Item -Path $FireFoxDriverPath -ItemType "directory" +} + +$DestFile = "$FireFoxDriverPath\$name" +$EdgeDriverDownloadUrl = $adress +try{ + Invoke-WebRequest -Uri $EdgeDriverDownloadUrl -OutFile $DestFile +} catch { + Write-Error "[!] Failed to download $name"; + exit 1; +} + +Write-Host "FireFox driver install...." +Expand-Archive -Path $DestFile -DestinationPath $FireFoxDriverPath -Force +Remove-Item -Path $DestFile -Force + + +Write-Host "Setting the environment variables" +setx GeckoWebDriver "$FireFoxDriverPath" /M; + +$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 diff --git a/images/win/scripts/Installers/Install-SeleniumWebDrivers.ps1 b/images/win/scripts/Installers/Install-SeleniumWebDrivers.ps1 index c6e1b3c24..aadae2c80 100644 --- a/images/win/scripts/Installers/Install-SeleniumWebDrivers.ps1 +++ b/images/win/scripts/Installers/Install-SeleniumWebDrivers.ps1 @@ -10,7 +10,7 @@ try { Invoke-WebRequest -UseBasicParsing -Uri "https://seleniumwebdrivers.blob.core.windows.net/seleniumwebdrivers/${DriversZipFile}" -OutFile $DriversZipFile; } catch { - Write-Error "[!] Failed to download $DriverZipFile"; + Write-Error "[!] Failed to download $DriversZipFile"; exit 1; }