selenium-powershell icon indicating copy to clipboard operation
selenium-powershell copied to clipboard

Command timeout

Open ili101 opened this issue 4 years ago • 0 comments

Problem

We can set timeouts with:

Set-SeDriverTimeout -TimeoutType AsynchronousJavaScript
Set-SeDriverTimeout -TimeoutType ImplicitWait
Set-SeDriverTimeout -TimeoutType PageLoad

but all timeouts above 60 cannot be used as the driver itself have a timeout of 60 seconds by default. Error:

Get-SeElement -By Id -Value 'submitb' | Invoke-SeClick

MethodInvocationException: \\scripts.ccccloud.local\PsF\Modules\Selenium\4.0.0\Selenium.psm1:802:25
Line |
 802 |                          $Element.Click() #Mitigating IE driver issue  …
     |                          ~~~~~~~~~~~~~~~~
     | Exception calling "Click" with "0" argument(s): "The HTTP request to the remote WebDriver server for URL
     | http://localhost:59213/session/b3f1057c9a99362878b2e6d93a386e0c/element/fcfd92f4-ddd1-4535-88b9-242b896b3cae/click timed out after 60 seconds."

Solution

I added the following command parameter to allow the user to set the driver timeout:

Start-SeDriver -CommandTimeout <seconds>

Example

Reproducible example if needed. Create files: Server.psd1

@{
    Server = @{
        Request = @{
            Timeout = 600
        }
    }
}

Pode.ps1 create then run in one terminal.

Import-Module -Name Pode
Import-Module -Name Pode.Web

Start-PodeServer -Threads 3 {
    # listen on localhost:8085
    Add-PodeEndpoint -Address localhost -Port 8085 -Protocol Http

    # enable error logging
    New-PodeLoggingMethod -Terminal | Enable-PodeErrorLogging

    Use-PodeWebTemplates -Title Test
    Set-PodeWebHomePage -Layouts (New-PodeWebCard -Name 'OK' -Content (
            New-PodeWebParagraph -Elements @(
                New-PodeWebText -Value 'the "Slow" page sleeps for 70 seconds'
                New-PodeWebLink -Value 'link' -Source '/pages/Slow' -id 'slow-link'
            )))
    Add-PodeWebPage -Name 'Slow' -ScriptBlock {
        Start-Sleep -Seconds 70
    }
}

Selenium.ps1 create then run in another terminal.

Import-Module -Name Selenium

$Driver = Start-SeDriver -Browser Chrome #-CommandTimeout 80
$Uri = 'http://localhost:8085'
Set-SeUrl -Url $Uri

Measure-Command {
    Get-SeElement -By Id 'slow-link' | Invoke-SeClick
}

ili101 avatar May 12 '21 14:05 ili101