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

Add optional Timeout and Raise parameters #40

Open
GCuser99 opened this issue Dec 27, 2021 · 2 comments
Open

Add optional Timeout and Raise parameters #40

GCuser99 opened this issue Dec 27, 2021 · 2 comments

Comments

@GCuser99
Copy link

GCuser99 commented Dec 27, 2021

Consider adding optional Timeout and Raise parameters similar to SeleniumBasic WebDriver methods as in:

WebDriver.ExecuteScript (Script, , , , Timeout, Raise)
WebDriver.Navigate (url,  , Timeout, Raise)

Optional Timeout in milliseconds (if not specified, defaults to WebDriver default or previously user-specified timeouts)
Optional Raise as Boolean to turn on/off error messaging

@GCuser99
Copy link
Author

GCuser99 commented Dec 30, 2021

One more idea... if you can at least expose "raise" and "timeout" parameters for Navigate, then convert Navigate to a function with Boolean return of True if no error, and False if error, as in this below:

Public Function Navigate(ByVal url As String, Optional ByVal SessionId As String = vbNullString, Optional ByVal timeOutms, Optional ByVal raise As Boolean = True) As Boolean
    Dim Data As New Dictionary, resp As Object, savtimeOutms 
    
    If SessionId <> vbNullString Then
        Data.Add "sessionId", SessionId
    End If
    
    Data.Add "url", url

    If Not IsMissing(timeOutms) Then
        savtimeOutms = Me.GetPageLoadTimeout(SessionId)
        If savtimeOutms <> timeOutms Then Me.SetPageLoadTimeout timeOutms, SessionId
    End If
    
    Set resp = Execute(CMD_GET, Data, raise)

    If Not IsMissing(timeOutms) Then
        If savtimeOutms <> timeOutms Then Me.SetPageLoadTimeout savtimeOutms, SessionId
    End If

    If resp("error") = "" Then
        Navigate = True
    Else
        Navigate = False
        Debug.Print resp("error")
    End If
End Function

Then user could do something like this:

    Do Until web.Navigate(url, , 4000, False) 'is success
        'oops - timedout - kick back, chill, and then ping again
    Loop

@GCuser99
Copy link
Author

GCuser99 commented Dec 30, 2021

Here is what raise-enabled Execute looks like (edited to fix Execute bug #46):

Public Function Execute(driverCommand, Optional parameters As Dictionary = Nothing, Optional ByVal raise As Boolean = True)
    Dim method As String: method = driverCommand(0)
    Dim path As String: path = driverCommand(1)
    
    If parameters Is Nothing Then
        Set parameters = New Dictionary
    End If
    
    ' Set default session id if session id is missing
    If Not parameters.Exists("sessionId") Then
        parameters.Add "sessionId", DefaultSessionId
    End If
    
    'Set path params to path, and save non-path params to nonPathParameters
    Dim paramKey As Variant, nonPathParameters As New Dictionary
    For Each paramKey In parameters
        If InStr(path, "$" & paramKey) > 0 Then 'path parameter
            path = Replace(path, "$" & paramKey, parameters(paramKey))
        Else 'non-path parameter
            nonPathParameters.Add paramKey, parameters(paramKey)
        End If
    Next paramKey
    
    ' Send request to selenium server
    Dim resp As Dictionary
    Set resp = SendRequest(method, UrlBase + path, nonPathParameters)
    
    ' Return value(s)
    If IsNull(resp("value")) Then
        Set Execute = New Dictionary 'executescript returns vbnullstring
    ElseIf TypeName(resp("value")) = "Collection" Then
        Set Execute = resp("value")
    ElseIf VarType(resp("value")) = vbObject Then
        If resp("value").Exists("error") And raise Then
            'make this user optional
            Err.raise 513, "WebDriver.Execute", JsonConverter.ConvertToJson(resp("value"))
        Else
            Set Execute = resp("value")
        End If
    Else
        Execute = resp("value")
    End If
      
End Function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants