diff --git a/Internal/Start-SeChromeDriver.ps1 b/Internal/Start-SeChromeDriver.ps1 index 9daa6a5..c92a81e 100644 --- a/Internal/Start-SeChromeDriver.ps1 +++ b/Internal/Start-SeChromeDriver.ps1 @@ -15,21 +15,22 @@ function Start-SeChromeDriver { [String[]]$Switches, [OpenQA.Selenium.LogLevel]$LogLevel, $UserAgent, - [Switch]$AcceptInsecureCertificates - + [Switch]$AcceptInsecureCertificates, + [Double]$CommandTimeout + # [System.IO.FileInfo]$ProfilePath, # $BinaryPath, - + # "user-data-dir=$ProfilePath" - + ) process { - #Additional Switches + #Additional Switches $EnablePDFViewer = Get-OptionsSwitchValue -Switches $Switches -Name 'EnablePDFViewer' $DisableAutomationExtension = Get-OptionsSwitchValue -Switches $Switches -Name 'DisableAutomationExtension' @@ -72,7 +73,7 @@ function Start-SeChromeDriver { Write-Warning "LogLevel parameter is not implemented for $($Options.SeParams.Browser)" } - + switch ($State) { { $_ -eq [SeWindowState]::Headless } { $Options.AddArguments('headless') } @@ -80,29 +81,33 @@ function Start-SeChromeDriver { { $_ -eq [SeWindowState]::Maximized } { $Options.AddArguments('start-maximized') } { $_ -eq [SeWindowState]::Fullscreen } { $Options.AddArguments('start-fullscreen') } } - + if ($PrivateBrowsing) { $Options.AddArguments('Incognito') } # $Location = @('--window-position=1921,0', '--window-size=1919,1080') - if ($PSBoundParameters.ContainsKey('Size')) { + if ($PSBoundParameters.ContainsKey('Size')) { $Options.AddArguments("--window-size=$($Size.Width),$($Size.Height)") } if ($PSBoundParameters.ContainsKey('Position')) { $Options.AddArguments("--window-position=$($Position.X),$($Position.Y)") } - - + + if (-not $PSBoundParameters.ContainsKey('Service')) { $ServiceParams = @{} if ($WebDriverPath) { $ServiceParams.Add('WebDriverPath', $WebDriverPath) } $service = New-SeDriverService -Browser Chrome @ServiceParams } - - - $Driver = [OpenQA.Selenium.Chrome.ChromeDriver]::new($service, $Options) + + if ($PSBoundParameters.ContainsKey('CommandTimeout')) { + $Driver = [OpenQA.Selenium.Chrome.ChromeDriver]::new($service, $Options, [TimeSpan]::FromMilliseconds($CommandTimeout * 1000)) + } + else { + $Driver = [OpenQA.Selenium.Chrome.ChromeDriver]::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 diff --git a/Internal/Start-SeEdgeDriver.ps1 b/Internal/Start-SeEdgeDriver.ps1 index 1f25ab5..18f3be8 100644 --- a/Internal/Start-SeEdgeDriver.ps1 +++ b/Internal/Start-SeEdgeDriver.ps1 @@ -15,7 +15,8 @@ function Start-SeEdgeDriver { [OpenQA.Selenium.DriverOptions]$Options, [String[]]$Switches, [OpenQA.Selenium.LogLevel]$LogLevel, - [Switch]$AcceptInsecureCertificates + [Switch]$AcceptInsecureCertificates, + [Double]$CommandTimeout ) @@ -23,7 +24,7 @@ function Start-SeEdgeDriver { 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 @@ -53,13 +54,13 @@ function Start-SeEdgeDriver { $WebDriverPath = "$PSScriptRoot\Assemblies\" Write-Verbose -Message "Using Web driver from the default location" } - + if (-not $PSBoundParameters.ContainsKey('Service')) { $ServiceParams = @{} if ($WebDriverPath) { $ServiceParams.Add('WebDriverPath', $WebDriverPath) } $service = New-SeDriverService -Browser Edge @ServiceParams } - + #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') } @@ -75,7 +76,12 @@ function Start-SeEdgeDriver { } #endregion - $Driver = [OpenQA.Selenium.Chrome.ChromeDriver]::new($service, $options) + if ($PSBoundParameters.ContainsKey('CommandTimeout')) { + $Driver = [OpenQA.Selenium.Chrome.ChromeDriver]::new($service, $Options, [TimeSpan]::FromMilliseconds($CommandTimeout * 1000)) + } + else { + $Driver = [OpenQA.Selenium.Chrome.ChromeDriver]::new($service, $options) + } #region post driver checks and option checks If we have a version know to have problems with passing arguments, generate a warning if we tried to send any. if (-not $Driver) { @@ -88,7 +94,7 @@ function Start-SeEdgeDriver { Write-Verbose "Web Driver version $driverversion" Write-Verbose ("Browser: {0,9} {1}" -f $Driver.Capabilities.ToDictionary().browserName, $Driver.Capabilities.ToDictionary().browserVersion) - + $browserCmdline = (Get-CimInstance -Verbose:$false -Query ( "Select * From win32_process " + "Where parentprocessid = $($service.ProcessId) " + @@ -111,7 +117,7 @@ function Start-SeEdgeDriver { { $_ -eq [SeWindowState]::Fullscreen } { $Driver.Manage().Window.FullScreen() } } - + #endregion return $Driver diff --git a/Internal/Start-SeFirefoxDriver.ps1 b/Internal/Start-SeFirefoxDriver.ps1 index 29efb52..3214043 100644 --- a/Internal/Start-SeFirefoxDriver.ps1 +++ b/Internal/Start-SeFirefoxDriver.ps1 @@ -15,8 +15,9 @@ function Start-SeFirefoxDriver { [String[]]$Switches, [OpenQA.Selenium.LogLevel]$LogLevel, [String]$UserAgent, - [Switch]$AcceptInsecureCertificates - + [Switch]$AcceptInsecureCertificates, + [Double]$CommandTimeout + ) process { @@ -56,7 +57,12 @@ function Start-SeFirefoxDriver { } - $Driver = [OpenQA.Selenium.Firefox.FirefoxDriver]::new($service, $Options) + if ($PSBoundParameters.ContainsKey('CommandTimeout')) { + $Driver = [OpenQA.Selenium.Firefox.FirefoxDriver]::new($service, $Options, [TimeSpan]::FromMilliseconds($CommandTimeout * 1000)) + } + else { + $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 @@ -71,7 +77,7 @@ function Start-SeFirefoxDriver { { $_ -eq [SeWindowState]::Maximized } { $Driver.Manage().Window.Maximize() ; break } { $_ -eq [SeWindowState]::Fullscreen } { $Driver.Manage().Window.FullScreen() ; break } } - + if ($StartURL) { $Driver.Navigate().GoToUrl($StartURL) } #endregion diff --git a/Internal/Start-SeInternetExplorerDriver.ps1 b/Internal/Start-SeInternetExplorerDriver.ps1 index e1be142..066a761 100644 --- a/Internal/Start-SeInternetExplorerDriver.ps1 +++ b/Internal/Start-SeInternetExplorerDriver.ps1 @@ -12,29 +12,35 @@ function Start-SeInternetExplorerDriver { [OpenQA.Selenium.DriverService]$service, [OpenQA.Selenium.DriverOptions]$Options, [String[]]$Switches, - [OpenQA.Selenium.LogLevel]$LogLevel + [OpenQA.Selenium.LogLevel]$LogLevel, + [Double]$CommandTimeout ) - + #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' } - $IgnoreProtectedModeSettings = Get-OptionsSwitchValue -Switches $Switches -Name 'IgnoreProtectedModeSettings' + $IgnoreProtectedModeSettings = Get-OptionsSwitchValue -Switches $Switches -Name 'IgnoreProtectedModeSettings' if ($IgnoreProtectedModeSettings) { $Options.IntroduceInstabilityByIgnoringProtectedModeSettings = $true } if ($StartURL) { $Options.InitialBrowserUrl = $StartURL } - + if (-not $PSBoundParameters.ContainsKey('Service')) { $ServiceParams = @{} if ($WebDriverPath) { $ServiceParams.Add('WebDriverPath', $WebDriverPath) } $service = New-SeDriverService -Browser InternetExplorer @ServiceParams } - + #endregion - $Driver = [OpenQA.Selenium.IE.InternetExplorerDriver]::new($service, $Options) + if ($PSBoundParameters.ContainsKey('CommandTimeout')) { + $Driver = [OpenQA.Selenium.IE.InternetExplorerDriver]::new($service, $Options, [TimeSpan]::FromMilliseconds($CommandTimeout * 1000)) + } + else { + $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')) { @@ -46,7 +52,7 @@ function Start-SeInternetExplorerDriver { if ($PSBoundParameters.ContainsKey('Position')) { $Driver.Manage().Window.Position = $Position } $Driver.Manage().Timeouts().ImplicitWait = [TimeSpan]::FromMilliseconds($ImplicitWait * 1000) - + switch ($State) { { $_ -eq [SeWindowState]::Minimized } { $Driver.Manage().Window.Minimize(); } { $_ -eq [SeWindowState]::Maximized } { $Driver.Manage().Window.Maximize() } diff --git a/Output/Selenium/ChangeLog.md b/Output/Selenium/ChangeLog.md index 2fb00b4..011923f 100644 --- a/Output/Selenium/ChangeLog.md +++ b/Output/Selenium/ChangeLog.md @@ -1,5 +1,5 @@ -# 4.0.0-preview3 (Planned) +# 4.0.0-preview3 ## Added / Modified - Get-SeElementAttribute now return a hashtable instead of a pscustom object when multiple attributes are queried diff --git a/Output/Selenium/Selenium.psm1 b/Output/Selenium/Selenium.psm1 index 6c563b7..296f863 100644 Binary files a/Output/Selenium/Selenium.psm1 and b/Output/Selenium/Selenium.psm1 differ diff --git a/Public/Start-SeDriver.ps1 b/Public/Start-SeDriver.ps1 index 960e615..fdc8457 100644 --- a/Public/Start-SeDriver.ps1 +++ b/Public/Start-SeDriver.ps1 @@ -38,7 +38,8 @@ function Start-SeDriver { [ValidateNotNull()] [ArgumentCompleter( [SeDriverUserAgentCompleter])] [String]$UserAgent, - [Switch]$AcceptInsecureCertificates + [Switch]$AcceptInsecureCertificates, + [Double]$CommandTimeout # See ParametersToRemove to view parameters that should not be passed to browsers internal implementations. ) Begin { @@ -58,9 +59,9 @@ function Start-SeDriver { $ParametersToRemove = @('Arguments', 'Browser', 'Name', 'PassThru') $SelectedBrowser = $Browser switch ($PSCmdlet.ParameterSetName) { - 'Default' { + 'Default' { $Options = New-SeDriverOptions -Browser $Browser - $PSBoundParameters.Add('Options', $Options) + $PSBoundParameters.Add('Options', $Options) } 'DriverOptions' { @@ -73,10 +74,10 @@ function Start-SeDriver { } } - $Options = $PSBoundParameters.Item('Options') + $Options = $PSBoundParameters.Item('Options') $SelectedBrowser = $Options.SeParams.Browser - # Start-SeDrivers params overrides whatever is in the options. + # Start-SeDrivers params overrides whatever is in the options. # Any options parameter not specified by Start-SeDriver get added to the psboundparameters foreach ($Key in $Options.SeParams.Keys) { if (! $PSBoundParameters.ContainsKey($Key)) { @@ -93,17 +94,17 @@ function Start-SeDriver { } } - + $FriendlyName = $null - if ($PSBoundParameters.ContainsKey('Name')) { - $FriendlyName = $Name - + if ($PSBoundParameters.ContainsKey('Name')) { + $FriendlyName = $Name + $AlreadyExist = $Script:SeDrivers.Where( { $_.SeFriendlyName -eq $FriendlyName }, 'first').Count -gt 0 if ($AlreadyExist) { throw "A driver with the name $FriendlyName is already in the active list of started driver." } } - + #Remove params exclusive to this cmdlet before going further. $ParametersToRemove | ForEach-Object { if ($PSBoundParameters.ContainsKey("$_")) { [void]($PSBoundParameters.Remove("$_")) } } @@ -116,7 +117,7 @@ function Start-SeDriver { 'MSEdge' { $Driver = Start-SeMSEdgeDriver @PSBoundParameters; break } } if ($null -ne $Driver) { - if ($null -eq $FriendlyName) { $FriendlyName = $Driver.SessionId } + if ($null -eq $FriendlyName) { $FriendlyName = $Driver.SessionId } Write-Verbose -Message "Opened $($Driver.Capabilities.browsername) $($Driver.Capabilities.ToDictionary().browserVersion)" #Se prefix used to avoid clash with anything from Selenium in the future @@ -124,7 +125,7 @@ function Start-SeDriver { $Headless = if ($state -eq [SeWindowState]::Headless) { " (headless)" } else { "" } $mp = @{InputObject = $Driver ; MemberType = 'NoteProperty' } Add-Member @mp -Name 'SeBrowser' -Value "$SelectedBrowser$($Headless)" - Add-Member @mp -Name 'SeFriendlyName' -Value "$FriendlyName" + Add-Member @mp -Name 'SeFriendlyName' -Value "$FriendlyName" Add-Member @mp -Name 'SeSelectedElements' -Value $null Add-Member -InputObject $Driver -MemberType NoteProperty -Name 'SeProcessId' -Value (Get-DriverProcessId -ServiceProcessId $Driver.SeServiceProcessId)