Danp2 / au3WebDriver

Web Driver UDF for AutoIt
MIT License
107 stars 23 forks source link

_WD_CheckContext bug with _WD_Action($sSession, 'url') #361

Closed mlipok closed 1 year ago

mlipok commented 2 years ago

Bug report

Describe the bug

I started using _WD_CheckContext in all of my projects. On some systems my end users notice problems. after testing I comes to such conclusions:

using:

Local $sSession =''
.......
.......
.......
_WD_CheckContext($sSession)

on some systems this modified _WD_Action snippets :

        Case 'title', 'url'
            $sResponse = __WD_Get($sURLCommand)
    _Log(@ScriptLineNumber & ' WD TESTING: ' & $sResponse)
            $iErr = @error

            If $iErr = $_WD_ERROR_Success Then
                $oJSON = Json_Decode($sResponse)
                $sResult = Json_Get($oJSON, $_WD_JSON_Value)
            EndIf
    _Log(@ScriptLineNumber & ' WD TESTING: ' )

        Case Else

reports to me:

! [ 6 / 0 ] : 458 WD TESTING: WinHTTP request timed out before Webdriver
! [ 6 / 0 ] : 465 WD TESTING: 

on other system it reports to me:

--> wd_core:458/62599 WD TESTING: 
! [ 1 / 0 ] : wd_core:465/62605 WD TESTING: 

the problem is that in the other case there is not setting for $iErr = @error

How to reproduce

Just use:

_WD_CheckContext('')
If @error Then MsgBox($MB_OK + $MB_TOPMOST + $MB_ICONERROR, "Error occured", "@error = " & @error & @CRLF & "@extended = " & @extended)

on different system as far as you get error.

Expected behavior

_WD_Action and any other function should set error after JSON decoding like in the following snippet

    If $iErr = $_WD_ERROR_Success Then
        $oJSON = Json_Decode($sResponse)
        If Not @error Then $sResult = Json_Get($oJSON, $_WD_JSON_Value)
        If @error Then $iErr = $_WD_ERROR_JSONParsing
    EndIf

Screenshots

none

Additional context

none

System under test

As far tested with geckodriver

Failed on FF 102.0.1 64Bit Works well on FF 91.12.0esr 32Bit

mlipok commented 2 years ago

Btw I specially add new $_WD_ERROR_JSONParsing to have it possible to manage when/where the problem occurs. If you agree with my proposal in Expected behavior then I will be able to propose PR for this issue.

Danp2 commented 2 years ago

Honestly, I can't understand what you are trying to say / explain above. I would expect _WD_CheckContext('') to fail because you aren't passing it a valid session ID. This is what I got when I tried it --

__WD_Get: URL=HTTP://127.0.0.1:4444/session//url
__WD_Get ==> Unknown Command [16] : HTTP status = 405 ResponseText=HTTP method not allowed
_WD_Action ==> Unknown Command [16] : Parameters:   Command=url   Option=Default
_WD_CheckContext ==> Webdriver Exception [10]

What am I failing to comprehend? Were you expecting different results when the session ID isn't valid (technically missing because you passed in an empty string)?

As far as this statement --

_WD_Action and any other function should set error after JSON decoding like in the following snippet

I'm sure that there are areas where the error checking can be improved upon. Feel free to submit a separate PR on that. However, I don't think that I would label an error from Json_Get as a "parsing" error. To me, that's better described as "not found".

If Json_Decode or Json_Enccode return an error, then I would agree that it may be due to a "parsing" error.

mlipok commented 2 years ago

using: image

with this modified function:

Func UserTesting() ; here you can replace the code to test your stuff before you ask on the forum
    _WD_CheckContext($sSession, False)
    If @error Then ; return if session is NOT OK
        ConsoleWrite("! ---> @error=" & @error & "  @extended=" & @extended & _
                " : _WD_CheckContext reported a problem with the session" & @CRLF)
        Return
    EndIf
    Return
EndFunc

my log:

_WD_Option ==> Success [0] : Parameters:   Option=console   Value=_DEBUGOUT

_WD_Option ==> Success [0] : Parameters:   Option=errormsgbox   Value=False

_WD_Option ==> Success [0] : Parameters:   Option=OutputDebug   Value=False

_WD_GetBrowserPath ==> Success [0 / 1] : Parameters:    Browser=Firefox

_WD_GetBrowserVersion ==> Success [0 / 1] : Parameters:    Browser=Firefox

_WD_GetWebDriverVersion ==> Success [0 / 0] : Parameters:    Dir=Z:\!!!_SVN_AU3\UDF_Forum\Other_Members\Official_AutoIt_Forum\WebDriver\    EXE=geckodriver.exe

__WD_GetLatestWebdriverInfo ==> Success [0 / 0]

_WD_UpdateDriver ==> Success [0 / 0] : DriverCurrent = 0.30.0 : DriverLatest = 0.31.0

_WD_Option ==> Success [0] : Parameters:   Option=Driver   Value=geckodriver.exe

_WD_Option ==> Success [0] : Parameters:   Option=DriverParams   Value=--log trace

_WD_Option ==> Success [0] : Parameters:   Option=Port   Value=4444

_WD_CapabilitiesStartup: #148 : > {"capabilities":"{}"} > IsObj = 1

_WD_CapabilitiesAdd: #177 :      $key = alwaysMatch     $value1 = firefox     $value2 = 

_WD_CapabilitiesAdd: #205 :  $_WD_NOTATION__MATCHTYPE = [capabilities][alwaysMatch] $_WD_NOTATION__SPECIFICVENDOR = ["moz:firefoxOptions"]

_WD_CapabilitiesAdd ==> Success [0] : Successfully used [alwaysMatch]  with specified browser: firefox

_WD_CapabilitiesAdd: #177 :      $key = browserName     $value1 = firefox     $value2 = 

_WD_CapabilitiesAdd: #217 #275 :      $key = browserName     $value1 = firefox     $value2 =     $s_Notation = [capabilities][alwaysMatch]["browserName"]   <<<<  firefox

_WD_CapabilitiesAdd ==> Success [0] : Successfully added capability

_WD_CapabilitiesAdd: #177 :      $key = acceptInsecureCerts     $value1 = True     $value2 = 

_WD_CapabilitiesAdd: #217 #275 :      $key = acceptInsecureCerts     $value1 = True     $value2 =     $s_Notation = [capabilities][alwaysMatch]["acceptInsecureCerts"]   <<<<  True

_WD_CapabilitiesAdd ==> Success [0] : Successfully added capability

_WD_CapabilitiesDump: JSON structure starts below: 1091

{
    "capabilities":{
        "alwaysMatch":{
            "browserName":"firefox",
            "acceptInsecureCerts":true
        }
    }
}

_WD_CapabilitiesDump: JSON structure ends above.

_WD_IsLatestRelease ==> Success [0] : True

_WD_Startup: OS:    WIN_10 WIN32_NT 19044 

_WD_Startup: AutoIt:    3.3.17.1

_WD_Startup: Webdriver UDF: 0.10.1 (Up to date)

_WD_Startup: WinHTTP:   1.6.4.2

_WD_Startup: Driver:    geckodriver.exe (32 Bit)

_WD_Startup: Params:    --log trace

_WD_Startup: Port:  4444

_WD_Startup: Command:   "geckodriver.exe" --log trace 

_WD_Startup ==> Success [0]

__WD_Post: URL=HTTP://127.0.0.1:4444/session; Data={
    "capabilities":{
        "alwaysMatch":{
            "browserName":"firefox",
            "acceptInsecureCerts":true
        }
    }
}

__WD_Post ==> Success [0] : HTTP status = 200 ResponseText={"value":{"sessionId":"7a00a95e-7a0d-4f1a-8b19-ca4992ef9579","capabilities":{"acceptInsecureCerts":true,"browserName":"firefox","browserVersion":"91.12.0","moz:accessibilityChecks":false,"moz:buildID":"20220718130424","moz:geckodriverVersion":"0.30.0","moz:headless":false,"moz:processID":11248,"moz:profile":"C:\\Users\\Szef\\AppData\\Local\\Temp\\rust_mozprofileD9P1w7","moz:shutdownTimeout":60000,"moz:useNonSpecCompliantPointerOrigin":false,"moz:webdriverClick":true,"pageLoadStrategy":"normal","platformName":"windows","platformVersion":"10.0","proxy":{},"setWindowRect":true,"strictFileInteractability":false,"timeouts":{"implicit":0,"pageLoad":300000,"script":30000},"unhandledPromptBehavior":"dismiss and notify"}}}

_WD_CreateSession ==> Success [0] : 7a00a95e-7a0d-4f1a-8b19-ca4992ef9579

__WD_Get: URL=HTTP://127.0.0.1:4444/session/7a00a95e-7a0d-4f1a-8b19-ca4992ef9579/url

__WD_Get ==> Success [0] : HTTP status = 200 ResponseText={"value":"about:blank"}

_WD_Action ==> Success [0] : Parameters:   Command=url   Option=Default

_WD_CheckContext ==> Success [0]

my client log: work in progress.... image

Danp2 commented 2 years ago

That makes no sense to me. Did you post the wrong picture?

mlipok commented 2 years ago

Please wait little more - I had some other problem to diagnose.

Danp2 commented 2 years ago

Is there a real issue here or pebcak?

mlipok commented 2 years ago

real issue but needs more investigation as I use different capabilities setting then normally in wd_demo.au3 and thus I'm investigating this remontly on my client's computer where the issue occurs. But I must to ask for computer time.

mlipok commented 2 years ago

btw. it occured on two different location (pc/client/city).

Danp2 commented 2 years ago

it occured on two different location (pc/client/city).

I suggest that you take some time to better define the problem because it's not clear to me what isn't working correctly.

mlipok commented 2 years ago

You can assign this to me.

Danp2 commented 1 year ago

@mlipok Any updates on this issue?

mlipok commented 1 year ago

Oh soon. I must dig to TeamViewer log and check where it was hit. Then I can ask client to connect me to this computer and make new test.

It can take few days. Give me until the end of February.

mlipok commented 1 year ago

Not able to replicate..... Closing for now.