-
Notifications
You must be signed in to change notification settings - Fork 17
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
Bug in Execute #46
Comments
ありがとうございます。 |
ExecuteScript から呼び出された場合は、vbNullString を返すようにしました。 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
Dim 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
If InStr(Path, "execute") = 0 Then
Set Execute = New Dictionary
Else
Execute = vbNullString 'ExecuteScript Returns vbNullString
End If
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 [変更前] If IsNull(resp("value")) Then
Set Execute = New Dictionary 'executescript returns vbnullstring [変更後] If IsNull(Resp("value")) Then
If InStr(Path, "execute") = 0 Then
Set Execute = New Dictionary
Else
Execute = vbNullString 'ExecuteScript Returns vbNullString
End If |
ありがとうございます。 Thank you. 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 |
@ezagdd, I am not sure I understand what you are asking... From above If raise=False then Set Execute = Resp("value"). So can't the caller take action from that? An example would be Navigate. If I am misunderstanding what you mean, then please elaborate more. |
Ok @ezagdd I see now! Proposed Lazy and Ugly Solution 1:
Now, in your test example, as you suggested earlier, since you assigned raise=false, then you the caller, are responsible for error handling:
It's not pretty, but the above works on everything that I tested... To your point "Shouldn't the raise action be taken in the function that is calling Execute?". I think agree with you. In fact, I'm wondering if caller should not only handle errors, but also how to parse the results of Execute. Why should Execute have to anticipate what the caller needs in terms of return-type, in addition to how to handle errors? I will give this some thought and get back to you... Thanks for your patience in explaining the issue you raised above! |
Here is my "prettier" solution @ezagdd for your review...
Please see this discussion for more details. |
ありがとうございます! |
As discussed here , I do think there is a bug in Execute. I suspect that the sessionId and other path parameters such as (element)Id should not be keys of the "parameters" dictionary that is passed to SendRequest(method, UrlBase + path, parameters).
That applies in general to ALL commands, however with my limited testing experience it only seems to cause a fatal error when setting timeouts. The key sessionId seems to be redundant info in "parameters" passed to SendRequest as sessionId is already encoded in "path" by the time SendRequest is invoked.
Why this seems to only blow up for timeouts and not for other commands I tested is a mystery, but the commands that I have tried work fine WITHOUT the path keys sessionId and (element)Id in the parameter set passed to SendRequest. So... the most immediate (and kind of ugly!) fix is to only pass a parameter set to SendRequest that contains non-path parameters as in the following version of Execute (with optional raise input parameter):
After making the above change to Execute, I tested with the following:
The following is printed to immediate window:
I then ran a battery of different automation test subs and they all ran as expected.
Notes:
Maybe a cleaner more elegant fix to this bug is to pass two dictionaries to Execute - a path parameter dictionary and a non-path parameter dictionary.
This problem should also be corrected in the @ezagdd versions of ExecuteScript and IsElementPresent, although I have offered simplified versions of those (ExecuteScript and IsElementPresent) which call the raise-enabled Execute directly to reduce code redundancy and so, as a result, would not need to be corrected.
The text was updated successfully, but these errors were encountered: