Files
runner-images-sangeeth/images/win/scripts/Installers/Install-SeleniumWebDrivers.ps1
T

97 lines
4.3 KiB
PowerShell
Raw Normal View History

################################################################################
## File: Install-SeleniumWebDrivers.ps1
## Desc: Install Selenium Web Drivers
################################################################################
$DestinationPath = "$($env:SystemDrive)\";
2019-12-20 14:36:00 +04:00
$DriversZipFile = "SeleniumWebDrivers.zip"
Write-Host "Destination path: [$DestinationPath]";
Write-Host "Selenium drivers download and install...";
try {
Invoke-WebRequest -UseBasicParsing -Uri "https://seleniumwebdrivers.blob.core.windows.net/seleniumwebdrivers/${DriversZipFile}" -OutFile $DriversZipFile;
}
catch {
2020-02-06 19:31:18 +03:00
Write-Error "[!] Failed to download $DriversZipFile";
2019-12-20 14:36:00 +04:00
exit 1;
}
2020-02-12 19:03:32 +03:00
$TempSeleniumDir = Join-Path $Env:TEMP "SeleniumWebDrivers"
Expand-Archive -Path $DriversZipFile -DestinationPath $Env:TEMP -Force;
Remove-Item $DriversZipFile;
2020-02-12 18:02:47 +03:00
$SeleniumWebDriverPath = Join-Path $DestinationPath "SeleniumWebDrivers"
2020-02-12 19:03:32 +03:00
$IEDriverPathTemp = Join-Path $TempSeleniumDir 'IEDriver'
2020-02-12 22:32:42 +03:00
if (-not (Test-Path -Path $SeleniumWebDriverPath)) {
New-Item -Path $SeleniumWebDriverPath -ItemType "directory"
}
2020-02-12 18:02:47 +03:00
Move-Item -Path "$IEDriverPathTemp" -Destination $SeleniumWebDriverPath
# Reinstall Chrome Web Driver
2020-02-12 19:03:32 +03:00
$ChromeDriverPath = "${DestinationPath}SeleniumWebDrivers\ChromeDriver";
2020-02-12 22:32:42 +03:00
if (-not (Test-Path -Path $ChromeDriverPath)) {
New-Item -Path $ChromeDriverPath -ItemType "directory"
}
$RegistryPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths"
$ChromePath = (Get-ItemProperty "$RegistryPath\chrome.exe").'(default)';
[version]$ChromeVersion = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($ChromePath).ProductVersion;
2019-12-20 14:36:00 +04:00
Write-Host "Chrome version: [$ChromeVersion]";
$ChromeDriverVersionUri = "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_$($ChromeVersion.Major).$($ChromeVersion.Minor).$($ChromeVersion.Build)";
2019-12-20 14:36:00 +04:00
Write-Host "Chrome driver version Uri [$ChromeDriverVersionUri]";
Write-Host "Getting the Chrome driver version...";
$ChromeDriverVersion = Invoke-WebRequest -Uri $ChromeDriverVersionUri;
2019-12-20 14:36:00 +04:00
Write-Host "Current Chrome driver version: [$ChromeDriverVersion]";
$ChromeDriverZipDownloadUri = "https://chromedriver.storage.googleapis.com/$($ChromeDriverVersion.ToString())/chromedriver_win32.zip";
2019-12-20 14:36:00 +04:00
Write-Host "Chrome driver zip file download Uri: [$ChromeDriverZipDownloadUri]";
$DestFile= "$ChromeDriverPath\chromedriver_win32.zip";
$ChromeDriverVersion.Content | Out-File -FilePath "$ChromeDriverPath\versioninfo.txt" -Force;
2019-12-20 14:36:00 +04:00
Write-Host "Chrome driver download....";
Invoke-WebRequest -Uri $ChromeDriverZipDownloadUri -OutFile $DestFile;
2019-12-20 14:36:00 +04:00
Write-Host "Chrome driver install....";
Expand-Archive -Path "$ChromeDriverPath\chromedriver_win32.zip" -DestinationPath $ChromeDriverPath -Force;
Remove-Item -Path "$ChromeDriverPath\chromedriver_win32.zip" -Force;
# Install Microsoft Edge Web Driver
Write-Host "Microsoft Edge driver download...."
2020-02-03 14:04:44 +01:00
$EdgeDriverPath = "${DestinationPath}SeleniumWebDrivers\EdgeDriver"
if (-not (Test-Path -Path $EdgeDriverPath)) {
New-Item -Path $EdgeDriverPath -ItemType "directory"
}
$EdgePath = (Get-ItemProperty "$RegistryPath\msedge.exe").'(default)'
[version]$EdgeVersion = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($EdgePath).ProductVersion
$EdgeDriverVersionUrl = "https://msedgedriver.azureedge.net/LATEST_RELEASE_$($EdgeVersion.Major)"
$EdgeDriverVersionFile = "$EdgeDriverPath\versioninfo.txt"
Invoke-WebRequest -Uri $EdgeDriverVersionUrl -OutFile $EdgeDriverVersionFile
$EdgeDriverLatestVersion = Get-Content -Path $EdgeDriverVersionFile
$EdgeDriverDownloadUrl="https://msedgedriver.azureedge.net/${EdgeDriverLatestVersion}/edgedriver_win64.zip"
$DestFile = "$EdgeDriverPath\edgedriver_win64.zip"
Invoke-WebRequest -Uri $EdgeDriverDownloadUrl -OutFile $DestFile
Write-Host "Microsoft Edge driver install...."
Expand-Archive -Path $DestFile -DestinationPath $EdgeDriverPath -Force
Remove-Item -Path $DestFile -Force
Write-Host "Setting the environment variables"
setx IEWebDriver "C:\SeleniumWebDrivers\IEDriver" /M;
setx ChromeWebDriver "$ChromeDriverPath" /M;
setx EdgeWebDriver "$EdgeDriverPath" /M;
$regEnvKey = 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\';
2019-12-25 22:38:26 +04:00
$PathValue = Get-ItemPropertyValue -Path $regEnvKey -Name 'Path';
$PathValue += ";$ChromeDriverPath\";
$PathValue += ";$EdgeDriverPath\";
Set-ItemProperty -Path $regEnvKey -Name 'Path' -Value $PathValue;
exit 0;