Selenium-Binary-Updater.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
param( [Parameter(Mandatory=$true)][ValidateSet('Chrome','Firefox','Edge')]$Browser ) $TempDir = [System.IO.Path]::GetTempPath() switch ($Browser){ 'Chrome'{ $LatestChromeStableRelease = Invoke-WebRequest 'https://chromedriver.storage.googleapis.com/LATEST_RELEASE' | Select-Object -ExpandProperty Content $ChromeBuilds = @('chromedriver_linux64','chromedriver_mac64','chromedriver_win32') foreach ($Build in $ChromeBuilds){ switch($Build){ 'chromedriver_linux64'{ $AssembliesDir = "$PSScriptRoot/assemblies/linux" $BinaryFileName = 'chromedriver' } 'chromedriver_mac64'{ $AssembliesDir = "$PSScriptRoot/assemblies/macos" $BinaryFileName = 'chromedriver' } 'chromedriver_win32'{ $AssembliesDir = "$PSScriptRoot/assemblies" $BinaryFileName = 'chromedriver.exe' } default{throw 'Incorrect Build Type'} } $BuildFileName = "$Build.zip" Write-Verbose "Downloading: $BuildFileName" Invoke-WebRequest -OutFile "$($TempDir + $BuildFileName)" "https://chromedriver.storage.googleapis.com/$LatestChromeStableRelease/$BuildFileName" # Expand the ZIP Archive to the correct Assemblies Dir Write-Verbose "Explanding: $($TempDir + $BuildFileName) to $AssembliesDir" Expand-Archive -Path "$($TempDir + $BuildFileName)" -DestinationPath $AssembliesDir -Force # Generate Hash Files Write-Verbose "Generating SHA256 Hash File: $AssembliesDir/$BinaryFileName.sha256" Get-FileHash -Path "$AssembliesDir/$BinaryFileName" -Algorithm SHA256 | Select-Object -ExpandProperty Hash | Set-Content -Path "$AssembliesDir/$BinaryFileName.sha256" -Force } } 'Firefox'{ Write-Host 'Not Supported Yet' } 'Edge'{ Write-Host 'Not Supported Yet' } } |