Skip to content

V4.0.0 preview2 #196

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

Merged
merged 20 commits into from
Dec 6, 2020
Merged
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
15 changes: 15 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@

# 4.0.0-preview3 (Planned)



# 4.0.0-preview2 (Prerelease)
## Added / Modified
- 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)
- AcceptInsecureCertificates switch added to Start-SeDriver / New-SeDriverOptions (Supported by: Chrome, Firefox, Edge) (#189)
- Chrome web drivers assemblies updated to latest version

## Fixes
- Starting Edge browser broken (#188,#195)
- custom driver options, when specified, are not used (#191,#193)
- Processes management internal logic error (#190)
- Get-SeInput not working properly with -Single switch (#186)
- Screenshots fail when attempting to screenshot the page (#187)

# 4.0.0-preview1 (Prerelease)
Note: V4 have an enormous amount of breakchanges. Most of the cmdlet have been rewriten in a way or another.
Important changes includes, but are not limited to:
Expand Down
19 changes: 17 additions & 2 deletions Help/Get-SeElement.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ Finds all IWebElements within the current context using the given mechanism
### Default (Default)
```
Get-SeElement [-By <SeBySelector[]>] [-Value] <String[]> [[-Timeout] <Double>] [-All] [-Attributes <String[]>]
[-Single] [<CommonParameters>]
[-Filter <ScriptBlock>] [-Single] [<CommonParameters>]
```

### ByElement
```
Get-SeElement [-By <SeBySelector[]>] [-Value] <String[]> [-Element] <IWebElement> [-All]
[-Attributes <String[]>] [-Single] [<CommonParameters>]
[-Attributes <String[]>] [-Filter <ScriptBlock>] [-Single] [<CommonParameters>]
```

## DESCRIPTION
Expand Down Expand Up @@ -131,6 +131,21 @@ Accept pipeline input: True (ByValue)
Accept wildcard characters: False
```

### -Filter
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.

```yaml
Type: ScriptBlock
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Single
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.

Expand Down
17 changes: 16 additions & 1 deletion Help/New-SeDriverOptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ New-SeDriverOptions [-Browser <Object>] [[-StartURL] <String>] [-State <Object>]
[-DefaultDownloadPath <FileInfo>] [-PrivateBrowsing] [-ImplicitWait <Double>] [-Size <Size>]
[-Position <Point>] [-WebDriverPath <Object>] [-BinaryPath <Object>] [-Switches <String[]>]
[-Arguments <String[]>] [-ProfilePath <Object>] [-LogLevel <LogLevel>] [-UserAgent <String>]
[<CommonParameters>]
[-AcceptInsecureCertificates] [<CommonParameters>]
```

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

## PARAMETERS

### -AcceptInsecureCertificates
If set, Ignore SSL certificate error (Chrome,Edge,Firefox)

```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Arguments
Command line arguments to be passed to the browser.

Expand Down
2 changes: 1 addition & 1 deletion Help/New-SeScreenshot.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Take a screenshot of the current page

## SYNTAX

### Path (Default)
### Driver (Default)
```
New-SeScreenshot [-AsBase64EncodedString] [<CommonParameters>]
```
Expand Down
21 changes: 18 additions & 3 deletions Help/Start-SeDriver.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Launch the specified browser.
Start-SeDriver [[-StartURL] <String>] [-State <SeWindowState>] [-DefaultDownloadPath <FileInfo>]
[-PrivateBrowsing] [-ImplicitWait <Double>] [-Size <Size>] [-Position <Point>] [-WebDriverPath <Object>]
[-BinaryPath <Object>] [-Arguments <String[]>] [-ProfilePath <Object>] [-LogLevel <LogLevel>] [-Name <Object>]
[-UserAgent <String>] [<CommonParameters>]
[-UserAgent <String>] [-AcceptInsecureCertificates] [<CommonParameters>]
```

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

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

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

## PARAMETERS

### -AcceptInsecureCertificates
If set, Ignore SSL certificate error (Chrome,Edge,Firefox)

```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Arguments
Command line arguments to be passed to the browser.

Expand Down
2 changes: 1 addition & 1 deletion Internal/Get-DriverProcessId.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function Get-DriverProcessId {

if ($IsWindowsPowershell) {
$Processes = Get-CimInstance -Class Win32_Process -Filter "ParentProcessId=$ServiceProcessId"
$BrowserProcess = $Processes.Where( { $_.Name -ne 'conhost.exe' }, 'first').ProcessId
$BrowserProcess = $Processes | Where-Object { $_.Name -ne 'conhost.exe' } | Select-Object -First 1 -ExpandProperty ProcessId
}
else {
$BrowserProcess = (Get-Process).Where( { { $_.Parent.id -eq $ServiceProcessId -and $_.Name -ne 'conhost' } }, 'first').Id
Expand Down
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
34 changes: 16 additions & 18 deletions Internal/Start-SeEdgeDriver.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,37 @@ function Start-SeEdgeDriver {
[OpenQA.Selenium.DriverService]$service,
[OpenQA.Selenium.DriverOptions]$Options,
[String[]]$Switches,
[OpenQA.Selenium.LogLevel]$LogLevel
[OpenQA.Selenium.LogLevel]$LogLevel,
[Switch]$AcceptInsecureCertificates

)
$OptionSettings = @{ browserName = '' }

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)) {
throw "Could not find $BinaryPath"; return
}

if ($PSBoundParameters.ContainsKey('LogLevel')) {
Write-Warning "LogLevel parameter is not implemented for $($Options.SeParams.Browser)"
}

#Were we given a driver location and is msedgedriver there ?
#If were were given a location (which might be from an environment variable) is the driver THERE ?
# if not, were we given a path for the browser executable, and is the driver THERE ?
# and if not there either, is there one in the assemblies sub dir ? And if not bail
if ($WebDriverPath -and -not (Test-Path -Path (Join-Path -Path $WebDriverPath -ChildPath 'msedgedriver.exe'))) {
throw "Could not find msedgedriver.exe in $WebDriverPath"; return
}
elseif ($WebDriverPath -and (Test-Path (Join-Path -Path $WebDriverPath -ChildPath 'msedge.exe'))) {
Write-Verbose -Message "Using browser from $WebDriverPath"
$optionsettings['BinaryLocation'] = Join-Path -Path $WebDriverPath -ChildPath 'msedge.exe'
$Options.BinaryLocation = Join-Path -Path $WebDriverPath -ChildPath 'msedge.exe'
}
elseif ($BinaryPath) {
$optionsettings['BinaryLocation'] = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($BinaryPath)
$binaryDir = Split-Path -Path $BinaryPath -Parent
Write-Verbose -Message "Will request $($OptionSettings['BinaryLocation']) as the browser"
$Options.BinaryLocation = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($BinaryPath)
Write-Verbose -Message "Will request $($Options.BinaryLocation) as the browser"
}

if ($PSBoundParameters.ContainsKey('LogLevel')) {
Write-Warning "LogLevel parameter is not implemented for $($Options.SeParams.Browser)"
}

if (-not $WebDriverPath -and $binaryDir -and (Test-Path (Join-Path -Path $binaryDir -ChildPath 'msedgedriver.exe'))) {
$WebDriverPath = $binaryDir
}
Expand All @@ -51,17 +53,13 @@ function Start-SeEdgeDriver {
$WebDriverPath = "$PSScriptRoot\Assemblies\"
Write-Verbose -Message "Using Web driver from the default location"
}
if (-not $WebDriverPath) { throw "Could not find msedgedriver.exe"; return }


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

$options = New-Object -TypeName OpenQA.Selenium.Chrome.ChromeOptions -Property $OptionSettings

#The command line args may now be --inprivate --headless but msedge driver V81 does not pass them
if ($PrivateBrowsing) { $options.AddArguments('InPrivate') }
if ($State -eq [SeWindowState]::Headless) { $options.AddArguments('headless') }
Expand Down
22 changes: 13 additions & 9 deletions Internal/Start-SeFirefoxDriver.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,34 @@ function Start-SeFirefoxDriver {
[OpenQA.Selenium.DriverOptions]$Options,
[String[]]$Switches,
[OpenQA.Selenium.LogLevel]$LogLevel,
[String]$UserAgent
[String]$UserAgent,
[Switch]$AcceptInsecureCertificates

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

if ($State -eq [SeWindowState]::Headless) {
$Firefox_Options.AddArguments('-headless')
$Options.AddArguments('-headless')
}

if ($DefaultDownloadPath) {
Write-Verbose "Setting Default Download directory: $DefaultDownloadPath"
$Firefox_Options.setPreference("browser.download.folderList", 2);
$Firefox_Options.SetPreference("browser.download.dir", "$DefaultDownloadPath");
$Options.setPreference("browser.download.folderList", 2);
$Options.SetPreference("browser.download.dir", "$DefaultDownloadPath");
}

if ($UserAgent) {
Write-Verbose "Setting User Agent: $UserAgent"
$Firefox_Options.SetPreference("general.useragent.override", $UserAgent)
$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) {
$Firefox_Options.SetPreference("browser.privatebrowsing.autostart", $true)
$Options.SetPreference("browser.privatebrowsing.autostart", $true)
}

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


$Driver = [OpenQA.Selenium.Firefox.FirefoxDriver]::new($service, $Firefox_Options)
$Driver = [OpenQA.Selenium.Firefox.FirefoxDriver]::new($service, $Options)
if (-not $Driver) { Write-Warning "Web driver was not created"; return }
Add-Member -InputObject $Driver -MemberType NoteProperty -Name 'SeServiceProcessId' -Value $Service.ProcessID
#region post creation options
Expand Down
11 changes: 5 additions & 6 deletions Internal/Start-SeInternetExplorerDriver.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,16 @@ function Start-SeInternetExplorerDriver {
[OpenQA.Selenium.LogLevel]$LogLevel
)

$IgnoreProtectedModeSettings = Get-OptionsSwitchValue -Switches $Switches -Name 'IgnoreProtectedModeSettings'

#region IE set-up options
if ($state -eq [SeWindowState]::Headless -or $PrivateBrowsing) { Write-Warning 'The Internet explorer driver does not support headless or Inprivate operation; these switches are ignored' }

$InternetExplorer_Options = [OpenQA.Selenium.IE.InternetExplorerOptions]::new()
$InternetExplorer_Options.IgnoreZoomLevel = $true
$IgnoreProtectedModeSettings = Get-OptionsSwitchValue -Switches $Switches -Name 'IgnoreProtectedModeSettings'
if ($IgnoreProtectedModeSettings) {
$InternetExplorer_Options.IntroduceInstabilityByIgnoringProtectedModeSettings = $true
$Options.IntroduceInstabilityByIgnoringProtectedModeSettings = $true
}

if ($StartURL) { $InternetExplorer_Options.InitialBrowserUrl = $StartURL }
if ($StartURL) { $Options.InitialBrowserUrl = $StartURL }

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

#endregion

$Driver = [OpenQA.Selenium.IE.InternetExplorerDriver]::new($service, $InternetExplorer_Options)
$Driver = [OpenQA.Selenium.IE.InternetExplorerDriver]::new($service, $Options)
if (-not $Driver) { Write-Warning "Web driver was not created"; return }
Add-Member -InputObject $Driver -MemberType NoteProperty -Name 'SeServiceProcessId' -Value $Service.ProcessID
if ($PSBoundParameters.ContainsKey('LogLevel')) {
Expand Down
4 changes: 1 addition & 3 deletions Internal/Start-SeMSEdgeDriver.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ function Start-SeMSEdgeDriver {
if (-not $PSBoundParameters.ContainsKey('Service')) {
$ServiceParams = @{}
#if ($WebDriverPath) { $ServiceParams.Add('WebDriverPath', $WebDriverPath) }
$service = New-SeDriverService -Browser MSEdge @ServiceParams
$service = New-SeDriverService -Browser MSEdge @ServiceParams -ErrorAction Stop
}

$options = [OpenQA.Selenium.Edge.EdgeOptions]::new()

if ($PrivateBrowsing) { $options.UseInPrivateBrowsing = $true }
if ($StartURL) { $options.StartPage = $StartURL }
#endregion
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
"@))
}
}
15 changes: 12 additions & 3 deletions Internal/init.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,24 @@ $Script:SeKeys = [OpenQA.Selenium.Keys] | Get-Member -MemberType Property -Stati
[Dictionary[object, Stack[string]]] $Script:SeLocationMap = [Dictionary[object, Stack[string]]]::new()

#region Set path to assemblies on Linux and MacOS and Grant Execution permissions on them

$ScriptRoot = $PSScriptRoot
# This will happens only if we are debugging
if ($ScriptRoot.EndsWith('Internal')){
$ScriptRoot = Split-Path -Path $ScriptRoot
}

if ($IsLinux) {
$AssembliesPath = "$PSScriptRoot/assemblies/linux"
$AssembliesPath = "$ScriptRoot/assemblies/linux"
}
elseif ($IsMacOS) {
$AssembliesPath = "$PSScriptRoot/assemblies/macos"
$AssembliesPath = "$ScriptRoot/assemblies/macos"
} else {
$AssembliesPath = "$ScriptRoot\assemblies"
}

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