Skip to content

Commit 4d771ce

Browse files
authored
V4.0.0 preview2 (#196)
* Start-SeEdgeDriver throw error on launch (#188) * Edge fix + general debug fix * .Where is not a method for CIM Instance object (#190) * Firefox not using the proper DriverOption (#191) * Filter parameter to get-seelement and applied to Get-SeInput (#186 #192 ) Also fixed a logic error with $Value that was used both as a parameter and a variable, which caused issues. * Legacy code removal causing error with screenshots (#187) * Fix - Filter + Filter error message * Select input by attributes fix. * Edge (new) driver option need to be of type ChromeOptions (#195) * Edge driver option fix (#193) * Edge - semi revert (#197) Since Start-SeDriver have priority over options, options should not handle stuff that depends on parameters. * IE fix (#193) * MSEdge Fix (#193) * ErrorAction Stop when MSEdge Service fail to create. * AcceptInsecureCertificates (Firefox, Chrome, Edge) (#189) * #177 Get-SeInput view (initial commit) * V4.0.0-preview2 build * Drivers update * V4.0.0-preview2 changelog * Version update
1 parent c7c1bef commit 4d771ce

39 files changed

+420
-89
lines changed

ChangeLog.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11

2+
# 4.0.0-preview3 (Planned)
23

34

5+
6+
# 4.0.0-preview2 (Prerelease)
7+
## Added / Modified
8+
- Get-SeElement -Filter; Add a new parameter to do additional filtering before returning. This is equivalent to doing a Where afterward but with the Get-SeElement error management logic applied before returning. (#192)
9+
- AcceptInsecureCertificates switch added to Start-SeDriver / New-SeDriverOptions (Supported by: Chrome, Firefox, Edge) (#189)
10+
- Chrome web drivers assemblies updated to latest version
11+
12+
## Fixes
13+
- Starting Edge browser broken (#188,#195)
14+
- custom driver options, when specified, are not used (#191,#193)
15+
- Processes management internal logic error (#190)
16+
- Get-SeInput not working properly with -Single switch (#186)
17+
- Screenshots fail when attempting to screenshot the page (#187)
18+
419
# 4.0.0-preview1 (Prerelease)
520
Note: V4 have an enormous amount of breakchanges. Most of the cmdlet have been rewriten in a way or another.
621
Important changes includes, but are not limited to:

Help/Get-SeElement.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ Finds all IWebElements within the current context using the given mechanism
1616
### Default (Default)
1717
```
1818
Get-SeElement [-By <SeBySelector[]>] [-Value] <String[]> [[-Timeout] <Double>] [-All] [-Attributes <String[]>]
19-
[-Single] [<CommonParameters>]
19+
[-Filter <ScriptBlock>] [-Single] [<CommonParameters>]
2020
```
2121

2222
### ByElement
2323
```
2424
Get-SeElement [-By <SeBySelector[]>] [-Value] <String[]> [-Element] <IWebElement> [-All]
25-
[-Attributes <String[]>] [-Single] [<CommonParameters>]
25+
[-Attributes <String[]>] [-Filter <ScriptBlock>] [-Single] [<CommonParameters>]
2626
```
2727

2828
## DESCRIPTION
@@ -131,6 +131,21 @@ Accept pipeline input: True (ByValue)
131131
Accept wildcard characters: False
132132
```
133133

134+
### -Filter
135+
Filter the obtained output with additional conditions. This is equivalent to doing a Where-Object afterward with the benefit of going trough the Get-SeElement error management.
136+
137+
```yaml
138+
Type: ScriptBlock
139+
Parameter Sets: (All)
140+
Aliases:
141+
142+
Required: False
143+
Position: Named
144+
Default value: None
145+
Accept pipeline input: False
146+
Accept wildcard characters: False
147+
```
148+
134149
### -Single
135150
Expectation that only one element will be returned. An error will be returned if that parameter is set and more than one corresponding element is found.
136151

Help/New-SeDriverOptions.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ New-SeDriverOptions [-Browser <Object>] [[-StartURL] <String>] [-State <Object>]
1717
[-DefaultDownloadPath <FileInfo>] [-PrivateBrowsing] [-ImplicitWait <Double>] [-Size <Size>]
1818
[-Position <Point>] [-WebDriverPath <Object>] [-BinaryPath <Object>] [-Switches <String[]>]
1919
[-Arguments <String[]>] [-ProfilePath <Object>] [-LogLevel <LogLevel>] [-UserAgent <String>]
20-
[<CommonParameters>]
20+
[-AcceptInsecureCertificates] [<CommonParameters>]
2121
```
2222

2323
## DESCRIPTION
@@ -38,6 +38,21 @@ Create a Chrome driver option object to perform additional things unsupported di
3838

3939
## PARAMETERS
4040

41+
### -AcceptInsecureCertificates
42+
If set, Ignore SSL certificate error (Chrome,Edge,Firefox)
43+
44+
```yaml
45+
Type: SwitchParameter
46+
Parameter Sets: (All)
47+
Aliases:
48+
49+
Required: False
50+
Position: Named
51+
Default value: None
52+
Accept pipeline input: False
53+
Accept wildcard characters: False
54+
```
55+
4156
### -Arguments
4257
Command line arguments to be passed to the browser.
4358

Help/New-SeScreenshot.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Take a screenshot of the current page
1212

1313
## SYNTAX
1414

15-
### Path (Default)
15+
### Driver (Default)
1616
```
1717
New-SeScreenshot [-AsBase64EncodedString] [<CommonParameters>]
1818
```

Help/Start-SeDriver.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Launch the specified browser.
1717
Start-SeDriver [[-StartURL] <String>] [-State <SeWindowState>] [-DefaultDownloadPath <FileInfo>]
1818
[-PrivateBrowsing] [-ImplicitWait <Double>] [-Size <Size>] [-Position <Point>] [-WebDriverPath <Object>]
1919
[-BinaryPath <Object>] [-Arguments <String[]>] [-ProfilePath <Object>] [-LogLevel <LogLevel>] [-Name <Object>]
20-
[-UserAgent <String>] [<CommonParameters>]
20+
[-UserAgent <String>] [-AcceptInsecureCertificates] [<CommonParameters>]
2121
```
2222

2323
### DriverOptions
@@ -26,7 +26,7 @@ Start-SeDriver [-Browser <Object>] [[-StartURL] <String>] [-State <SeWindowState
2626
[-DefaultDownloadPath <FileInfo>] [-PrivateBrowsing] [-ImplicitWait <Double>] [-Size <Size>]
2727
[-Position <Point>] [-WebDriverPath <Object>] [-BinaryPath <Object>] [-Service <DriverService>]
2828
-Options <DriverOptions> [-Arguments <String[]>] [-ProfilePath <Object>] [-LogLevel <LogLevel>]
29-
[-Name <Object>] [-UserAgent <String>] [<CommonParameters>]
29+
[-Name <Object>] [-UserAgent <String>] [-AcceptInsecureCertificates] [<CommonParameters>]
3030
```
3131

3232
### Default
@@ -35,7 +35,7 @@ Start-SeDriver [-Browser <Object>] [[-StartURL] <String>] [-State <SeWindowState
3535
[-DefaultDownloadPath <FileInfo>] [-PrivateBrowsing] [-ImplicitWait <Double>] [-Size <Size>]
3636
[-Position <Point>] [-WebDriverPath <Object>] [-BinaryPath <Object>] [-Switches <String[]>]
3737
[-Arguments <String[]>] [-ProfilePath <Object>] [-LogLevel <LogLevel>] [-Name <Object>] [-UserAgent <String>]
38-
[<CommonParameters>]
38+
[-AcceptInsecureCertificates] [<CommonParameters>]
3939
```
4040

4141
## DESCRIPTION
@@ -52,6 +52,21 @@ Start a Chrome browser at the specified position and starting URL
5252

5353
## PARAMETERS
5454

55+
### -AcceptInsecureCertificates
56+
If set, Ignore SSL certificate error (Chrome,Edge,Firefox)
57+
58+
```yaml
59+
Type: SwitchParameter
60+
Parameter Sets: (All)
61+
Aliases:
62+
63+
Required: False
64+
Position: Named
65+
Default value: None
66+
Accept pipeline input: False
67+
Accept wildcard characters: False
68+
```
69+
5570
### -Arguments
5671
Command line arguments to be passed to the browser.
5772

Internal/Get-DriverProcessId.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function Get-DriverProcessId {
88

99
if ($IsWindowsPowershell) {
1010
$Processes = Get-CimInstance -Class Win32_Process -Filter "ParentProcessId=$ServiceProcessId"
11-
$BrowserProcess = $Processes.Where( { $_.Name -ne 'conhost.exe' }, 'first').ProcessId
11+
$BrowserProcess = $Processes | Where-Object { $_.Name -ne 'conhost.exe' } | Select-Object -First 1 -ExpandProperty ProcessId
1212
}
1313
else {
1414
$BrowserProcess = (Get-Process).Where( { { $_.Parent.id -eq $ServiceProcessId -and $_.Name -ne 'conhost' } }, 'first').Id

Internal/Start-SeChromeDriver.ps1

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ function Start-SeChromeDriver {
1414
[OpenQA.Selenium.DriverOptions]$Options,
1515
[String[]]$Switches,
1616
[OpenQA.Selenium.LogLevel]$LogLevel,
17-
$UserAgent
17+
$UserAgent,
18+
[Switch]$AcceptInsecureCertificates
1819

1920

2021

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

56+
if ($AcceptInsecureCertificates) {
57+
Write-Verbose "AcceptInsecureCertificates capability set to: $($AcceptInsecureCertificates.IsPresent)"
58+
$Options.AddAdditionalCapability([OpenQA.Selenium.Remote.CapabilityType]::AcceptInsecureCertificates, $true, $true)
59+
}
60+
5561
if ($ProfilePath) {
5662
Write-Verbose "Setting Profile directory: $ProfilePath"
5763
$Options.AddArgument("user-data-dir=$ProfilePath")

Internal/Start-SeEdgeDriver.ps1

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,37 @@ function Start-SeEdgeDriver {
1414
[OpenQA.Selenium.DriverService]$service,
1515
[OpenQA.Selenium.DriverOptions]$Options,
1616
[String[]]$Switches,
17-
[OpenQA.Selenium.LogLevel]$LogLevel
17+
[OpenQA.Selenium.LogLevel]$LogLevel,
18+
[Switch]$AcceptInsecureCertificates
1819

1920
)
20-
$OptionSettings = @{ browserName = '' }
21+
22+
if ($AcceptInsecureCertificates) {
23+
Write-Verbose "AcceptInsecureCertificates capability set to: $($AcceptInsecureCertificates.IsPresent)"
24+
$Options.AddAdditionalCapability([OpenQA.Selenium.Remote.CapabilityType]::AcceptInsecureCertificates, $true, $true)
25+
}
26+
2127
#region check / set paths for browser and web driver and edge options
2228
if ($PSBoundParameters['BinaryPath'] -and -not (Test-Path -Path $BinaryPath)) {
2329
throw "Could not find $BinaryPath"; return
2430
}
2531

26-
if ($PSBoundParameters.ContainsKey('LogLevel')) {
27-
Write-Warning "LogLevel parameter is not implemented for $($Options.SeParams.Browser)"
28-
}
29-
30-
#Were we given a driver location and is msedgedriver there ?
31-
#If were were given a location (which might be from an environment variable) is the driver THERE ?
32-
# if not, were we given a path for the browser executable, and is the driver THERE ?
33-
# and if not there either, is there one in the assemblies sub dir ? And if not bail
3432
if ($WebDriverPath -and -not (Test-Path -Path (Join-Path -Path $WebDriverPath -ChildPath 'msedgedriver.exe'))) {
3533
throw "Could not find msedgedriver.exe in $WebDriverPath"; return
3634
}
3735
elseif ($WebDriverPath -and (Test-Path (Join-Path -Path $WebDriverPath -ChildPath 'msedge.exe'))) {
3836
Write-Verbose -Message "Using browser from $WebDriverPath"
39-
$optionsettings['BinaryLocation'] = Join-Path -Path $WebDriverPath -ChildPath 'msedge.exe'
37+
$Options.BinaryLocation = Join-Path -Path $WebDriverPath -ChildPath 'msedge.exe'
4038
}
4139
elseif ($BinaryPath) {
42-
$optionsettings['BinaryLocation'] = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($BinaryPath)
43-
$binaryDir = Split-Path -Path $BinaryPath -Parent
44-
Write-Verbose -Message "Will request $($OptionSettings['BinaryLocation']) as the browser"
40+
$Options.BinaryLocation = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($BinaryPath)
41+
Write-Verbose -Message "Will request $($Options.BinaryLocation) as the browser"
4542
}
43+
44+
if ($PSBoundParameters.ContainsKey('LogLevel')) {
45+
Write-Warning "LogLevel parameter is not implemented for $($Options.SeParams.Browser)"
46+
}
47+
4648
if (-not $WebDriverPath -and $binaryDir -and (Test-Path (Join-Path -Path $binaryDir -ChildPath 'msedgedriver.exe'))) {
4749
$WebDriverPath = $binaryDir
4850
}
@@ -51,17 +53,13 @@ function Start-SeEdgeDriver {
5153
$WebDriverPath = "$PSScriptRoot\Assemblies\"
5254
Write-Verbose -Message "Using Web driver from the default location"
5355
}
54-
if (-not $WebDriverPath) { throw "Could not find msedgedriver.exe"; return }
55-
5656

5757
if (-not $PSBoundParameters.ContainsKey('Service')) {
5858
$ServiceParams = @{}
5959
if ($WebDriverPath) { $ServiceParams.Add('WebDriverPath', $WebDriverPath) }
6060
$service = New-SeDriverService -Browser Edge @ServiceParams
6161
}
6262

63-
$options = New-Object -TypeName OpenQA.Selenium.Chrome.ChromeOptions -Property $OptionSettings
64-
6563
#The command line args may now be --inprivate --headless but msedge driver V81 does not pass them
6664
if ($PrivateBrowsing) { $options.AddArguments('InPrivate') }
6765
if ($State -eq [SeWindowState]::Headless) { $options.AddArguments('headless') }

Internal/Start-SeFirefoxDriver.ps1

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,34 @@ function Start-SeFirefoxDriver {
1414
[OpenQA.Selenium.DriverOptions]$Options,
1515
[String[]]$Switches,
1616
[OpenQA.Selenium.LogLevel]$LogLevel,
17-
[String]$UserAgent
17+
[String]$UserAgent,
18+
[Switch]$AcceptInsecureCertificates
1819

1920
)
2021
process {
21-
#region firefox set-up options
22-
$Firefox_Options = [OpenQA.Selenium.Firefox.FirefoxOptions]::new()
2322

2423
if ($State -eq [SeWindowState]::Headless) {
25-
$Firefox_Options.AddArguments('-headless')
24+
$Options.AddArguments('-headless')
2625
}
2726

2827
if ($DefaultDownloadPath) {
2928
Write-Verbose "Setting Default Download directory: $DefaultDownloadPath"
30-
$Firefox_Options.setPreference("browser.download.folderList", 2);
31-
$Firefox_Options.SetPreference("browser.download.dir", "$DefaultDownloadPath");
29+
$Options.setPreference("browser.download.folderList", 2);
30+
$Options.SetPreference("browser.download.dir", "$DefaultDownloadPath");
3231
}
3332

3433
if ($UserAgent) {
3534
Write-Verbose "Setting User Agent: $UserAgent"
36-
$Firefox_Options.SetPreference("general.useragent.override", $UserAgent)
35+
$Options.SetPreference("general.useragent.override", $UserAgent)
36+
}
37+
38+
if ($AcceptInsecureCertificates) {
39+
Write-Verbose "AcceptInsecureCertificates capability set to: $($AcceptInsecureCertificates.IsPresent)"
40+
$Options.AddAdditionalCapability([OpenQA.Selenium.Remote.CapabilityType]::AcceptInsecureCertificates,$true,$true)
3741
}
3842

3943
if ($PrivateBrowsing) {
40-
$Firefox_Options.SetPreference("browser.privatebrowsing.autostart", $true)
44+
$Options.SetPreference("browser.privatebrowsing.autostart", $true)
4145
}
4246

4347
if ($PSBoundParameters.ContainsKey('LogLevel')) {
@@ -52,7 +56,7 @@ function Start-SeFirefoxDriver {
5256
}
5357

5458

55-
$Driver = [OpenQA.Selenium.Firefox.FirefoxDriver]::new($service, $Firefox_Options)
59+
$Driver = [OpenQA.Selenium.Firefox.FirefoxDriver]::new($service, $Options)
5660
if (-not $Driver) { Write-Warning "Web driver was not created"; return }
5761
Add-Member -InputObject $Driver -MemberType NoteProperty -Name 'SeServiceProcessId' -Value $Service.ProcessID
5862
#region post creation options

Internal/Start-SeInternetExplorerDriver.ps1

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,16 @@ function Start-SeInternetExplorerDriver {
1515
[OpenQA.Selenium.LogLevel]$LogLevel
1616
)
1717

18-
$IgnoreProtectedModeSettings = Get-OptionsSwitchValue -Switches $Switches -Name 'IgnoreProtectedModeSettings'
18+
1919
#region IE set-up options
2020
if ($state -eq [SeWindowState]::Headless -or $PrivateBrowsing) { Write-Warning 'The Internet explorer driver does not support headless or Inprivate operation; these switches are ignored' }
2121

22-
$InternetExplorer_Options = [OpenQA.Selenium.IE.InternetExplorerOptions]::new()
23-
$InternetExplorer_Options.IgnoreZoomLevel = $true
22+
$IgnoreProtectedModeSettings = Get-OptionsSwitchValue -Switches $Switches -Name 'IgnoreProtectedModeSettings'
2423
if ($IgnoreProtectedModeSettings) {
25-
$InternetExplorer_Options.IntroduceInstabilityByIgnoringProtectedModeSettings = $true
24+
$Options.IntroduceInstabilityByIgnoringProtectedModeSettings = $true
2625
}
2726

28-
if ($StartURL) { $InternetExplorer_Options.InitialBrowserUrl = $StartURL }
27+
if ($StartURL) { $Options.InitialBrowserUrl = $StartURL }
2928

3029
if (-not $PSBoundParameters.ContainsKey('Service')) {
3130
$ServiceParams = @{}
@@ -35,7 +34,7 @@ function Start-SeInternetExplorerDriver {
3534

3635
#endregion
3736

38-
$Driver = [OpenQA.Selenium.IE.InternetExplorerDriver]::new($service, $InternetExplorer_Options)
37+
$Driver = [OpenQA.Selenium.IE.InternetExplorerDriver]::new($service, $Options)
3938
if (-not $Driver) { Write-Warning "Web driver was not created"; return }
4039
Add-Member -InputObject $Driver -MemberType NoteProperty -Name 'SeServiceProcessId' -Value $Service.ProcessID
4140
if ($PSBoundParameters.ContainsKey('LogLevel')) {

Internal/Start-SeMSEdgeDriver.ps1

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@ function Start-SeMSEdgeDriver {
2222
if (-not $PSBoundParameters.ContainsKey('Service')) {
2323
$ServiceParams = @{}
2424
#if ($WebDriverPath) { $ServiceParams.Add('WebDriverPath', $WebDriverPath) }
25-
$service = New-SeDriverService -Browser MSEdge @ServiceParams
25+
$service = New-SeDriverService -Browser MSEdge @ServiceParams -ErrorAction Stop
2626
}
2727

28-
$options = [OpenQA.Selenium.Edge.EdgeOptions]::new()
29-
3028
if ($PrivateBrowsing) { $options.UseInPrivateBrowsing = $true }
3129
if ($StartURL) { $options.StartPage = $StartURL }
3230
#endregion
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function Test-SeDriverAcceptInsecureCertificates {
2+
[CmdletBinding()]
3+
param (
4+
$Browser, [ref]$AcceptInsecureCertificates,
5+
$Boundparameters
6+
)
7+
8+
$SupportedBrowsers = @('Chrome','Edge','Firefox')
9+
if ($Browser -in $SupportedBrowsers) {
10+
return
11+
}
12+
else {
13+
Throw ([System.NotImplementedException]::new(@"
14+
AcceptInsecureCertificates parameter is only supported by the following browser: $($SupportedBrowsers -join ',')
15+
Selected browser: $Browser
16+
"@))
17+
}
18+
}

Internal/init.ps1

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,24 @@ $Script:SeKeys = [OpenQA.Selenium.Keys] | Get-Member -MemberType Property -Stati
3333
[Dictionary[object, Stack[string]]] $Script:SeLocationMap = [Dictionary[object, Stack[string]]]::new()
3434

3535
#region Set path to assemblies on Linux and MacOS and Grant Execution permissions on them
36+
37+
$ScriptRoot = $PSScriptRoot
38+
# This will happens only if we are debugging
39+
if ($ScriptRoot.EndsWith('Internal')){
40+
$ScriptRoot = Split-Path -Path $ScriptRoot
41+
}
42+
3643
if ($IsLinux) {
37-
$AssembliesPath = "$PSScriptRoot/assemblies/linux"
44+
$AssembliesPath = "$ScriptRoot/assemblies/linux"
3845
}
3946
elseif ($IsMacOS) {
40-
$AssembliesPath = "$PSScriptRoot/assemblies/macos"
47+
$AssembliesPath = "$ScriptRoot/assemblies/macos"
48+
} else {
49+
$AssembliesPath = "$ScriptRoot\assemblies"
4150
}
4251

4352
# Grant Execution permission to assemblies on Linux and MacOS
44-
if ($AssembliesPath) {
53+
if ($IsLinux -or $IsMacOS) {
4554
# Check if powershell is NOT running as root
4655
Get-Item -Path "$AssembliesPath/chromedriver", "$AssembliesPath/geckodriver" | ForEach-Object {
4756
if ($IsLinux) { $FileMod = stat -c "%a" $_.FullName }

0 commit comments

Comments
 (0)