aboutsummaryrefslogtreecommitdiffstats
path: root/src/ci/scripts/updateSeleniumDriver.ps1
blob: 9ca66084e71ffeb09670bf708c58e2660450ea14 (plain)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
#
#
# Powershell script updating Selenium drivers on ci server
#
# Author: Martin Stockhammer <martin_s@apache.org>
# Date  : 2017-05-14
#
# Description:
# This script checks, if the selenium drivers are available on the system and downloads
# and extracts them, if they do not exist.
#
# Parameter:
# -Verbose: Print additional output
# -Force: Remove the existing drivers and download/extract them again


param (
    [switch]$Verbose = $False,
    [switch]$Force = $False
)

$psVersion = $PSVersionTable.PSVersion
$baseDir = "F:\jenkins\tools"

if ($Verbose) {
  Write-Output "PS-Version: $psVersion"
  Write-Output "Verbose: $Verbose, Force: $Force"
}

$urls = @{
  "iedriver\2.53.1\win64\DriverServer.zip"="http://selenium-release.storage.googleapis.com/2.53/IEDriverServer_x64_2.53.1.zip"
  "iedriver\2.53.1\win32\DriverServer.zip"="http://selenium-release.storage.googleapis.com/2.53/IEDriverServer_Win32_2.53.1.zip"
  "iedriver\3.4.0\win64\DriverServer.zip"="http://selenium-release.storage.googleapis.com/3.4/IEDriverServer_x64_3.4.0.zip"
  "iedriver\3.4.0\win32\DriverServer.zip"="http://selenium-release.storage.googleapis.com/3.4/IEDriverServer_Win32_3.4.0.zip"
  "chromedriver\2.29\win32\DriverServer.zip"="http://chromedriver.storage.googleapis.com/2.29/chromedriver_win32.zip"
  "geckodriver\0.16.1\win32\DriverServer.zip"="http://github.com/mozilla/geckodriver/releases/download/v0.16.1/geckodriver-v0.16.1-win32.zip"
  "geckodriver\0.16.1\win64\DriverServer.zip"="http://github.com/mozilla/geckodriver/releases/download/v0.16.1/geckodriver-v0.16.1-win64.zip"
}

foreach ($h in $urls.GetEnumerator()) {
  $url = $h.Value
  $downloadFile = "$($baseDir)\$($h.Name)"
  $downloadDir = Split-Path $downloadFile -Parent

  if ($Force -And (Test-Path -Path $downloadDir ) ) {
    Get-ChildItem -Path $downloadDir -Recurse | Remove-Item -force -recurse
  }

  if(!(Test-Path -Path $downloadDir )){
    New-Item -ItemType directory -Path $downloadDir
  }

  if ($Force -Or !(Test-Path -Path $downloadFile )){
    Write-Output "Downloading Driver $url"
    Invoke-WebRequest -Uri $url -OutFile $downloadFile

    $shell = New-Object -ComObject shell.application
    $zip = $shell.NameSpace($downloadFile)
    foreach ($item in $zip.items()) {
      $shell.Namespace($downloadDir).CopyHere($item)
    }
    if ($Verbose) {
      Get-ChildItem -Path $downloadDir
    }
  }
}