forked from TestStack/TestStack.Seleno
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webdriver_installs.psm1
67 lines (56 loc) · 2.44 KB
/
webdriver_installs.psm1
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
function Install-ChromeDriver() {
Install-EmbeddedFileFromNugetPackageTools "WebDriver.ChromeDriver" "chromedriver.exe"
Write-Host "Successfully added chrome web driver for use with Seleno."
}
function Install-PhantomJSDriver() {
Write-Host "Installing phantomjs.exe package"
Install-Package phantomjs.exe
Write-Host "Marking phantomjs.exe as embedded resource."
Set-RootProjectFileAsEmbeddedResource "phantomjs.exe"
Write-Host "Successfully added PhantomJS web driver for use with Seleno."
}
function Install-IE64Driver() {
Install-EmbeddedFileFromNugetPackageTools "WebDriver.IEDriver" "IEDriverServer.exe"
Write-Host "Successfully added IE web driver for use with Seleno."
}
function Install-IE32Driver() {
Install-EmbeddedFileFromNugetPackageTools "WebDriver.IEDriver.32-bit" "IEDriverServer.exe"
Write-Host "Successfully added IE web driver for use with Seleno."
}
function Install-EmbeddedFileFromNugetPackageTools($packageName, $fileInToolsDirToEmbed) {
Write-Host "Installing $packageName package"
Install-Package $packageName
Write-Host "Adding $fileInToolsDirToEmbed to project."
$file = Join-Path (Get-PackageToolsDir $packageName) $fileInToolsDirToEmbed
Update-RootProjectFile $file $fileInToolsDirToEmbed
Write-Host "Marking $fileInToolsDirToEmbed as embedded resource."
Set-RootProjectFileAsEmbeddedResource $fileInToolsDirToEmbed
}
function Get-PackageToolsDir($packageName) {
$toolsPath = $PSScriptRoot
$packagesDir = Join-Path (Join-Path $toolsPath "..") ".."
$packageDir = Get-ChildItem $packagesDir | Where-Object { $_.Name -like "$packageName.*" } | Select-Object -First 1
return Join-Path (Join-Path $packagesDir $packageDir) "tools"
}
function Update-RootProjectFile($source, $destination) {
$project = Get-Project
$item = $project.ProjectItems | Where-Object { $_.Name -eq $destination } | Select-Object -First 1
if ($item -ne $null) {
$item.Remove()
}
try {
$project.ProjectItems.AddFromFile($source)
}
catch {}
$item = $project.ProjectItems | Where-Object { $_.Name -eq $destination } | Select-Object -First 1
if ($item -eq $null) {
Write-Error "Unable to add $destination to project root."
return
}
}
function Set-RootProjectFileAsEmbeddedResource($file) {
$project = Get-Project
$item = $project.ProjectItems | Where-Object { $_.Name -eq $file } | Select-Object -First 1
$item.Properties.Item("BuildAction").Value = [int]3 # Embed
$item.Properties.Item("CopyToOutputDirectory").Value = [int]0 # Do not copy
}