Skip to content

Commit

Permalink
AcceptInsecureCertificates (Firefox, Chrome, Edge) (#189)
Browse files Browse the repository at this point in the history
  • Loading branch information
itfranck committed Dec 6, 2020
1 parent 53f09b2 commit 15fcb42
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 5 deletions.
8 changes: 7 additions & 1 deletion Internal/Start-SeChromeDriver.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ function Start-SeChromeDriver {
[OpenQA.Selenium.DriverOptions]$Options,
[String[]]$Switches,
[OpenQA.Selenium.LogLevel]$LogLevel,
$UserAgent
$UserAgent,
[Switch]$AcceptInsecureCertificates



Expand Down Expand Up @@ -52,6 +53,11 @@ function Start-SeChromeDriver {
$Options.AddArgument("--user-agent=$UserAgent")
}

if ($AcceptInsecureCertificates) {
Write-Verbose "AcceptInsecureCertificates capability set to: $($AcceptInsecureCertificates.IsPresent)"
$Options.AddAdditionalCapability([OpenQA.Selenium.Remote.CapabilityType]::AcceptInsecureCertificates, $true, $true)
}

if ($ProfilePath) {
Write-Verbose "Setting Profile directory: $ProfilePath"
$Options.AddArgument("user-data-dir=$ProfilePath")
Expand Down
8 changes: 7 additions & 1 deletion Internal/Start-SeEdgeDriver.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@ function Start-SeEdgeDriver {
[OpenQA.Selenium.DriverService]$service,
[OpenQA.Selenium.DriverOptions]$Options,
[String[]]$Switches,
[OpenQA.Selenium.LogLevel]$LogLevel
[OpenQA.Selenium.LogLevel]$LogLevel,
[Switch]$AcceptInsecureCertificates

)

if ($AcceptInsecureCertificates) {
Write-Verbose "AcceptInsecureCertificates capability set to: $($AcceptInsecureCertificates.IsPresent)"
$Options.AddAdditionalCapability([OpenQA.Selenium.Remote.CapabilityType]::AcceptInsecureCertificates, $true, $true)
}

#region check / set paths for browser and web driver and edge options
if ($PSBoundParameters['BinaryPath'] -and -not (Test-Path -Path $BinaryPath)) {
Expand Down
8 changes: 7 additions & 1 deletion Internal/Start-SeFirefoxDriver.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ function Start-SeFirefoxDriver {
[OpenQA.Selenium.DriverOptions]$Options,
[String[]]$Switches,
[OpenQA.Selenium.LogLevel]$LogLevel,
[String]$UserAgent
[String]$UserAgent,
[Switch]$AcceptInsecureCertificates

)
process {
Expand All @@ -34,6 +35,11 @@ function Start-SeFirefoxDriver {
$Options.SetPreference("general.useragent.override", $UserAgent)
}

if ($AcceptInsecureCertificates) {
Write-Verbose "AcceptInsecureCertificates capability set to: $($AcceptInsecureCertificates.IsPresent)"
$Options.AddAdditionalCapability([OpenQA.Selenium.Remote.CapabilityType]::AcceptInsecureCertificates,$true,$true)
}

if ($PrivateBrowsing) {
$Options.SetPreference("browser.privatebrowsing.autostart", $true)
}
Expand Down
18 changes: 18 additions & 0 deletions Internal/Test-SeDriverAcceptInsecureCertificates.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function Test-SeDriverAcceptInsecureCertificates {
[CmdletBinding()]
param (
$Browser, [ref]$AcceptInsecureCertificates,
$Boundparameters
)

$SupportedBrowsers = @('Chrome','Edge','Firefox')
if ($Browser -in $SupportedBrowsers) {
return
}
else {
Throw ([System.NotImplementedException]::new(@"
AcceptInsecureCertificates parameter is only supported by the following browser: $($SupportedBrowsers -join ',')
Selected browser: $Browser
"@))
}
}
5 changes: 4 additions & 1 deletion Public/New-SeDriverOptions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ function New-SeDriverOptions {
[SeDriverUserAgentTransformAttribute()]
[ValidateNotNull()]
[ArgumentCompleter( [SeDriverUserAgentCompleter])]
[String]$UserAgent
[String]$UserAgent,
[Switch]$AcceptInsecureCertificates
)
if ($PSBoundParameters.ContainsKey('UserAgent')) { Test-SeDriverUserAgent -Browser $Browser -ErrorAction Stop }
if ($PSBoundParameters.ContainsKey('AcceptInsecureCertificates')) { Test-SeDriverAcceptInsecureCertificates -Browser $Browser -ErrorAction Stop }

# [Enum]::GetNames([sebrowsers])
$output = $null
switch ($Browser) {
Expand Down
4 changes: 3 additions & 1 deletion Public/Start-SeDriver.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ function Start-SeDriver {
[SeDriverUserAgentTransformAttribute()]
[ValidateNotNull()]
[ArgumentCompleter( [SeDriverUserAgentCompleter])]
[String]$UserAgent
[String]$UserAgent,
[Switch]$AcceptInsecureCertificates
# See ParametersToRemove to view parameters that should not be passed to browsers internal implementations.
)
Begin {
if ($PSBoundParameters.ContainsKey('UserAgent')) { Test-SeDriverUserAgent -Browser $Browser -ErrorAction Stop }
if ($PSBoundParameters.ContainsKey('AcceptInsecureCertificates')) { Test-SeDriverAcceptInsecureCertificates -Browser $Browser -ErrorAction Stop }
}
process {
#Params with default value that need to be pased down to Start-SeXXDriver
Expand Down

0 comments on commit 15fcb42

Please sign in to comment.