Skip to content
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

Command timeout #211

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
31 changes: 18 additions & 13 deletions Internal/Start-SeChromeDriver.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -72,37 +73,41 @@ function Start-SeChromeDriver {
Write-Warning "LogLevel parameter is not implemented for $($Options.SeParams.Browser)"
}



switch ($State) {
{ $_ -eq [SeWindowState]::Headless } { $Options.AddArguments('headless') }
# { $_ -eq [SeWindowState]::Minimized } {} # No switches... Managed after launch
{ $_ -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
Expand Down
20 changes: 13 additions & 7 deletions Internal/Start-SeEdgeDriver.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ function Start-SeEdgeDriver {
[OpenQA.Selenium.DriverOptions]$Options,
[String[]]$Switches,
[OpenQA.Selenium.LogLevel]$LogLevel,
[Switch]$AcceptInsecureCertificates
[Switch]$AcceptInsecureCertificates,
[Double]$CommandTimeout

)

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
Expand Down Expand Up @@ -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') }
Expand All @@ -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) {
Expand All @@ -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) " +
Expand All @@ -111,7 +117,7 @@ function Start-SeEdgeDriver {
{ $_ -eq [SeWindowState]::Fullscreen } { $Driver.Manage().Window.FullScreen() }
}


#endregion

return $Driver
Expand Down
14 changes: 10 additions & 4 deletions Internal/Start-SeFirefoxDriver.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ function Start-SeFirefoxDriver {
[String[]]$Switches,
[OpenQA.Selenium.LogLevel]$LogLevel,
[String]$UserAgent,
[Switch]$AcceptInsecureCertificates

[Switch]$AcceptInsecureCertificates,
[Double]$CommandTimeout

)
process {

Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
20 changes: 13 additions & 7 deletions Internal/Start-SeInternetExplorerDriver.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand All @@ -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() }
Expand Down
2 changes: 1 addition & 1 deletion Output/Selenium/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Binary file modified Output/Selenium/Selenium.psm1
Binary file not shown.
25 changes: 13 additions & 12 deletions Public/Start-SeDriver.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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' {
Expand All @@ -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)) {
Expand All @@ -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("$_")) } }
Expand All @@ -116,15 +117,15 @@ 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
#SessionId scriptproperty validation to avoid perfomance cost of checking closed session.
$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)

Expand Down