Skip to content

Add custom DriverPath to Start-SeChrome (#59) #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions Selenium.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ function Start-SeChrome {
[switch]$Maximized,
[switch]$Minimized,
[switch]$Fullscreen,
[System.IO.FileInfo]$ChromeBinaryPath
[System.IO.FileInfo]$ChromeBinaryPath,

[ValidateScript({ if ($_) {Test-Path -Path $_ -PathType Container} })]
[string]$DriverPath
)

BEGIN{
Expand Down Expand Up @@ -118,11 +121,14 @@ function Start-SeChrome {
Write-Verbose "Download the right chromedriver from 'http://chromedriver.chromium.org/downloads'"
}

if($IsLinux -or $IsMacOS){
if ($DriverPath){
$Driver = New-Object -TypeName "OpenQA.Selenium.Chrome.ChromeDriver" -ArgumentList $DriverPath,$Chrome_Options
}
elseif($IsLinux -or $IsMacOS){
$Driver = New-Object -TypeName "OpenQA.Selenium.Chrome.ChromeDriver" -ArgumentList $AssembliesPath,$Chrome_Options
}
else{
$Driver = New-Object -TypeName "OpenQA.Selenium.Chrome.ChromeDriver" -ArgumentList $Chrome_Options
$Driver = New-Object -TypeName "OpenQA.Selenium.Chrome.ChromeDriver" -ArgumentList $Chrome_Options
}

if($Minimized -and $Driver){
Expand Down
42 changes: 42 additions & 0 deletions Selenium.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,48 @@ Describe "Start-SeChrome with Options" {
}
}

Describe 'Start-SeChrome with Custom DriverPath' {
BeforeEach {
# It is unknown which alternate drivers are present on CI agent, so use existing driver as a custom DriverPath for tests
if ($IsLinux) {
$driverPath = Join-Path $PSScriptRoot 'assemblies/macos'
}
elseif($IsMacOS) {
$driverPath = Join-Path $PSScriptRoot 'assemblies/linux'
}
else { #windows
$driverPath = Join-Path $PSScriptRoot 'assemblies'
}

$badDriverPath = Join-Path $PSScriptRoot 'bad-assembly-path'
}

Context 'DriverPath With no additional arguments' {
It 'Start-SeChrome from Custom DriverPath with no arguments' {
$Driver = Start-SeChrome -DriverPath $driverPath
$Driver | Should Not BeNullOrEmpty
Stop-SeDriver $Driver
}

It 'Start-SeChrome should fail if custom DriverPath does not exist' {
{ Start-SeChrome -DriverPath $badDriverPath } | Should Throw
}
}

Context 'DriverPath With additional arguments' {
It 'Start-SeChrome from Custom DriverPath with Multiple arguments' {
$Driver = Start-SeChrome -DriverPath $driverPath -Arguments @('Incognito','start-maximized')
$Driver | Should Not BeNullOrEmpty
Stop-SeDriver $Driver
}

It 'Start-SeChrome with multiple arguments should fail if custom DriverPath does not exist' {
{
Start-SeChrome -DriverPath $badDriverPath -Arguments @('Incognito','start-maximized') } | Should Throw
}
}
}

Describe "Start-SeFirefox"{
Context "Should Start Firefox Driver" {
$Driver = Start-SeFirefox
Expand Down