Last active
October 1, 2023 00:13
-
-
Save JoshuaKGoldberg/01b011b3dc84c732aeb36746ca9edfcf to your computer and use it in GitHub Desktop.
PowerShell script to download major browser WebDriver drivers for Selenium.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Net.ServicePointManager]::SecurityProtocol = "Ssl3, Tls, Tls11, Tls12"; | |
$currentDir = (Get-Item -Path "./").FullName; | |
$driversDirName = Join-Path $currentDir ".drivers"; | |
$isWindows = [System.Boolean](Get-CimInstance -ClassName Win32_OperatingSystem -ErrorAction SilentlyContinue); | |
$webClient = New-Object System.Net.WebClient; | |
function Ensure-Driver-Exists($browserName, $exeName, $download, $zipName) { | |
$localExeName = Join-Path $driversDirName $exeName; | |
if (Test-Path $localExeName) { | |
Write-Host "${browserName}: driver already located at $localExeName." -f DarkGray; | |
return; | |
} | |
if ($zipName -eq $null) { | |
$localDownloadLocation = Join-Path $driversDirName $exeName; | |
} else { | |
$download = "$download/$zipName"; | |
$localDownloadLocation = Join-Path $driversDirName $zipName; | |
} | |
Write-Host "${browserName}: downloading driver from $download..." -f DarkGray; | |
$webClient.downloadFile($download, $localDownloadLocation); | |
if (!($zipName -eq $null)) { | |
Write-Host "${browserName}: extracting driver from $localDownloadLocation..." -f DarkGray; | |
Expand-Archive -DestinationPath $driversDirName -Path $localDownloadLocation; | |
Remove-Item $localDownloadLocation; | |
} | |
Write-Host "${browserName}: driver placed in $localExeName." -f DarkGray; | |
} | |
function Ensure-Chrome-Driver() { | |
Ensure-Driver-Exists "Chrome" "chromedriver.exe" "http://chromedriver.storage.googleapis.com/2.38" "chromedriver_win32.zip" | |
} | |
function Ensure-Gecko-Driver() { | |
Ensure-Driver-Exists "Gecko (Firefox)" "geckodriver.exe" "https://github.com/mozilla/geckodriver/releases/download/v0.20.1" "geckodriver-v0.20.1-win64.zip"; | |
} | |
function Ensure-Edge-Driver() { | |
if ($isWindows) { | |
Ensure-Driver-Exists "Edge" "MicrosoftWebDriver.exe" "https://download.microsoft.com/download/F/8/A/F8AF50AB-3C3A-4BC4-8773-DC27B32988DD/MicrosoftWebDriver.exe" | |
} | |
} | |
function Ensure-Internet-Explorer-Driver() { | |
if ($isWindows) { | |
Ensure-Driver-Exists "Internet Explorer" "IEDriverServer.exe" "http://selenium-release.storage.googleapis.com/3.9" "IEDriverServer_Win32_3.9.0.zip" | |
} | |
} | |
New-Item -Force -ItemType directory -Path $driversDirName > $null; | |
Ensure-Chrome-Driver; | |
Ensure-Gecko-Driver; | |
Ensure-Edge-Driver; | |
Ensure-Internet-Explorer-Driver; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment