Skip to content

_WD_FrameList - <frame..> support + refactoring #434

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

Merged
merged 31 commits into from
Mar 31, 2023

Conversation

mlipok
Copy link
Contributor

@mlipok mlipok commented Mar 7, 2023

Pull request

Proposed changes

Refactoring for better getting more data

Checklist

  • I have read and noticed the CODE OF CONDUCT document
  • I have read and noticed the CONTRIBUTING document
  • I have added necessary documentation or screenshots (if appropriate)

Types of changes

Please check x the type of change your PR introduces:

  • Bugfix (change which fixes an issue)
  • Feature (change which adds functionality)
  • Code style update (formatting, renaming)
  • Refactoring (functional, structural)
  • Documentation content changes
  • Other (please describe)

What is the current behavior?

getting the list of frames can stop on specific frames and do not process rest of them

What is the new behavior?

continue processing frames even if one of them fires any kind of issue.

Additional context

#397 (comment)

#433 (comment)

System under test

not related

tested with:

Func UserTesting() ; here you can replace the code to test your stuff before you ask on the forum
	
		; go to website
	_WD_Navigate($sSession, 'https://www.tutorialspoint.com/html/html_frames.htm#')
	_WD_LoadWait($sSession)

	; check if document context location is Top Window
	ConsoleWrite("> " & @ScriptLineNumber & " IsWindowTop = " & _WD_IsWindowTop($sSession) & @CRLF)

	MsgBox($MB_TOPMOST, "", 'Before checking location of multiple elements on multiple frames' & @CRLF & 'Try the same example with and without waiting about 30 seconds in order to see that many frames should be fully loaded, and to check the differences')

	$aFrameList = _WD_FrameList($sSession, True)
	ConsoleWrite("! ---> @error=" & @error & "  @extended=" & @extended & " : Example : Testing element location in frame set" & @CRLF)
	_ArrayDisplay($aFrameList, 'www.tutorialspoint.com - get frame list as array', 0, 0, Default, $sArrayHeader)
EndFunc

@Danp2 Danp2 marked this pull request as draft March 7, 2023 12:48
@mlipok mlipok marked this pull request as ready for review March 8, 2023 06:18
@mlipok mlipok changed the title _WD_FrameList - Refactoring _WD_FrameList - <frame..> support + refactoring Mar 13, 2023
@Danp2
Copy link
Owner

Danp2 commented Mar 16, 2023

@mlipok Apologies if we've discussed this previously, but can you explain the need for the $iDebugLevel parameter in __WD_FrameList_Internal? From what I can see --

  • _WD_FrameList properly saves and restored the debug level.
  • __WD_FrameList_Internal tries to "restore" the debug level before exiting, but hasn't changed it earlier in the function

Why does the debug level need to be tracked / modified in __WD_FrameList_Internal? 😕

@mlipok
Copy link
Contributor Author

mlipok commented Mar 16, 2023

  • _WD_FrameList properly saves and restored the debug level.

You mean this part:

au3WebDriver/wd_helper.au3

Lines 772 to 778 in bf98ff5

; Prevent logging multiple errors from _WD_FrameList and __WD_FrameList_Internal if not in Full debug mode - https://github.com/Danp2/au3WebDriver/pull/362#issuecomment-1220962556
If $_WD_DEBUG <> $_WD_DEBUG_Full Then $_WD_DEBUG = $_WD_DEBUG_None
Local Const $sElement_CallingFrameBody = _WD_ExecuteScript($sSession, "return window.document.body;", Default, Default, $_WD_JSON_Element)
If Not @error Then
$vResult = __WD_FrameList_Internal($sSession, 'null', '', False, $_WD_DEBUG_Saved)
EndIf

  • __WD_FrameList_Internal tries to "restore" the debug level before exiting, but hasn't changed it earlier in the function

Why does the debug level need to be tracked / modified in __WD_FrameList_Internal? 😕

Becuase I want to get log to the console

Return SetError(__WD_Error($sFuncName, $iErr, $sParameters & $sMessage), 0, $vResult)

But I want to get them only once (when exiting main document) thus all this processing is needed.

au3WebDriver/wd_helper.au3

Lines 935 to 941 in bf98ff5

If $sLevel = 'null' Then ; script is on processing main (top level) __WD_FrameList_Internal() runtime
$_WD_DEBUG = $iDebugLevel ; restore $_WD_DEBUG_Saved log level to display error message
EndIf
$sMessage = ($sMessage And $_WD_DEBUG > $_WD_DEBUG_Error) ? (' Information: ' & $sMessage) : ("")
Return SetError(__WD_Error($sFuncName, $iErr, $sParameters & $sMessage), 0, $vResult)
EndFunc ;==>__WD_FrameList_Internal

And for this reason knowing outher value $_WD_DEBUG_Saved is needed.

$_WD_DEBUG = $iDebugLevel ; restore $_WD_DEBUG_Saved log level to display error message

@mlipok
Copy link
Contributor Author

mlipok commented Mar 16, 2023

But I want to get them only once (when exiting main document) thus all this processing is needed.

We can get all error messages, maybe it will be better.
But still we need to know what level of debuging was set by user.

Thus I can move maintaining $_WD_DEBUG_Saved to inner of __WD_FrameList_Internal

@mlipok
Copy link
Contributor Author

mlipok commented Mar 16, 2023

But I want to get them only once (when exiting main document) thus all this processing is needed.

We can get all error messages, maybe it will be better. But still we need to know what level of debuging was set by user.

ALL >> I mean one log per each __WD_FrameList_Internal calls.

@Danp2
Copy link
Owner

Danp2 commented Mar 16, 2023

Why does the debug level need to be tracked / modified in __WD_FrameList_Internal? 😕

Becuase I want to get log to the console

OIC

Thus I can move maintaining $_WD_DEBUG_Saved to inner of __WD_FrameList_Internal

Yes... as long as it isn't required in _WD_FrameList.

I mean one log per each __WD_FrameList_Internal calls.

Is that what you want?

@mlipok
Copy link
Contributor Author

mlipok commented Mar 16, 2023

Working on

@mlipok
Copy link
Contributor Author

mlipok commented Mar 16, 2023

Why does the debug level need to be tracked / modified in __WD_FrameList_Internal? 😕

Becuase I want to get log to the console

OIC

I changed concept. but still prevnting redundant logs (most of logs)

Thus I can move maintaining $_WD_DEBUG_Saved to inner of __WD_FrameList_Internal

Yes... as long as it isn't required in _WD_FrameList.

the current commits only allow one outer log comming from this::

Local Const $sElement_CallingFrameBody = _WD_ExecuteScript($sSession, "return window.document.body;", Default, Default, $_WD_JSON_Element)

and on finall log:

au3WebDriver/wd_helper.au3

Lines 821 to 823 in aa03f90

$sMessage = ($sMessage And $_WD_DEBUG > $_WD_DEBUG_Error) ? (' Information: ' & $sMessage) : ("")
Return SetError(__WD_Error($sFuncName, $iErr, $sParameters & $sMessage, $iFrameCount), $iFrameCount, $vResult)
EndFunc ;==>_WD_FrameList

Which can occurs onces per each _WD_FrameList() call.

All others are internall and will be prevented from redundant logging

I mean one log per each __WD_FrameList_Internal calls.

Is that what you want?

I rethink my approach (about internall processing).
It will be good to have at least one/finall message per each frame

au3WebDriver/wd_helper.au3

Lines 938 to 940 in aa03f90

$sMessage = ($sMessage And $_WD_DEBUG > $_WD_DEBUG_Error) ? (' Information: ' & $sMessage) : ("")
Return SetError(__WD_Error($sFuncName, $iErr, $sParameters & $sMessage), 0, $vResult)
EndFunc ;==>__WD_FrameList_Internal

Please take a look on this: $_WD_DEBUG_Saved usage moved to internall

@Danp2
Copy link
Owner

Danp2 commented Mar 17, 2023

Please take a look on this: $_WD_DEBUG_Saved usage moved to internall

I like the direction this is headed towards as the code is much easier to follow IMO. I do have questions about this --

au3WebDriver/wd_helper.au3

Lines 850 to 852 in aa03f90

Local Static $_WD_DEBUG_Saved = Null ; this is static because this function will be run recurently and we need to keep outer debug level
If $_WD_DEBUG_Saved = Null Then $_WD_DEBUG_Saved = $_WD_DEBUG ; save current DEBUG level
If $_WD_DEBUG <> $_WD_DEBUG_Full Then $_WD_DEBUG = $_WD_DEBUG_None ; Prevent logging multiple errors from __WD_FrameList_Internal

and

au3WebDriver/wd_helper.au3

Lines 930 to 931 in aa03f90

$_WD_DEBUG = $_WD_DEBUG_Saved ; restore DEBUG level
$_WD_DEBUG_Saved = Null ; reset staticly defined saved debug level in order to get new one when function will be called from user script

I'm having difficulty wrapping my head around how this will work. Won't $_WD_DEBUG get reset when exiting a nested frame? If so, then I don't think that is what you want.

@mlipok
Copy link
Contributor Author

mlipok commented Mar 17, 2023

Using this new commit: better $sMessage's
And: usage of $_WD_DEBUG_Saved / $sMessage

image

In time when _WD_FrameList() was in runtime, I closed FireFox browser and I get single error from each __WD_FrameList_Internal()

__WD_Post ==> Success [0] : HTTP status = 200
_WD_ExecuteScript ==> Success [0]
__WD_FrameList_Internal ==> Invalid Browsing Context [17] : Parameters:    Level=null    IsHidden=False	Information: Error occurred on "null" level after processing subframe "null/0"
__WD_FrameList_Internal ==> Invalid Browsing Context [17] : Parameters:    Level=null    IsHidden=False	Information: Error occurred on "null" level when trying to check attributes of subframe "null/1"
__WD_FrameList_Internal ==> Invalid Browsing Context [17] : Parameters:    Level=null    IsHidden=False	Information: Error occurred on "null" level when trying to check attributes of subframe "null/2"
__WD_FrameList_Internal ==> Invalid Browsing Context [17] : Parameters:    Level=null    IsHidden=False	Information: Error occurred on "null" level when trying to check attributes of subframe "null/3"
__WD_FrameList_Internal ==> Webdriver Exception [10] : Parameters:    Level=null    IsHidden=False	Information: Error occurred on "null" level when trying to check attributes of subframe "null/4"
__WD_FrameList_Internal ==> Invalid session ID [16] : Parameters:    Level=null    IsHidden=False	Information: Error occurred on "null" level when trying to check attributes of subframe "null/5"
__WD_FrameList_Internal ==> Invalid session ID [16] : Parameters:    Level=null    IsHidden=False	Information: Error occurred on "null" level when trying to check attributes of subframe "null/6"
__WD_FrameList_Internal ==> Invalid session ID [16] : Parameters:    Level=null    IsHidden=False	Information: Error occurred on "null" level when trying to check attributes of subframe "null/7"
__WD_FrameList_Internal ==> Invalid session ID [16] : Parameters:    Level=null    IsHidden=False	Information: Error occurred on "null" level when trying to check attributes of subframe "null/8"
__WD_FrameList_Internal ==> Invalid session ID [16] : Parameters:    Level=null    IsHidden=False	Information: Error occurred on "null" level when trying to check attributes of subframe "null/9"
__WD_FrameList_Internal ==> Invalid session ID [16] : Parameters:    Level=null    IsHidden=False	Information: Error occurred on "null" level when trying to check attributes of subframe "null/10"
__WD_FrameList_Internal ==> Invalid session ID [16] : Parameters:    Level=null    IsHidden=False	Information: Error occurred on "null" level when trying to check attributes of subframe "null/11"
__WD_FrameList_Internal ==> Invalid session ID [16] : Parameters:    Level=null    IsHidden=False	Information: Error occurred on "null" level when trying to check attributes of subframe "null/12"
__WD_FrameList_Internal ==> Invalid session ID [16] : Parameters:    Level=null    IsHidden=False	Information: Error occurred on "null" level when trying to check attributes of subframe "null/13"
__WD_FrameList_Internal ==> Invalid session ID [16] : Parameters:    Level=null    IsHidden=False	Information: Error occurred on "null" level when trying to check attributes of subframe "null/14"
__WD_FrameList_Internal ==> Invalid session ID [16] : Parameters:    Level=null    IsHidden=False	Information: Error occurred on "null" level when trying to check attributes of subframe "null/15"
__WD_FrameList_Internal ==> Invalid session ID [16] : Parameters:    Level=null    IsHidden=False	Information: Error occurred on "null" level when trying to check attributes of subframe "null/16"
__WD_FrameList_Internal ==> Invalid session ID [16] : Parameters:    Level=null    IsHidden=False	Information: Error occurred on "null" level when trying to check attributes of subframe "null/17"
__WD_FrameList_Internal ==> Invalid session ID [16] : Parameters:    Level=null    IsHidden=False	Information: Error occurred on "null" level when trying to check attributes of subframe "null/18"
__WD_FrameList_Internal ==> Invalid session ID [16] : Parameters:    Level=null    IsHidden=False	Information: Error occurred on "null" level when trying to check attributes of subframe "null/19"
__WD_FrameList_Internal ==> Invalid session ID [16] : Parameters:    Level=null    IsHidden=False	Information: Error occurred on "null" level when trying to check attributes of subframe "null/20"
__WD_FrameList_Internal ==> Invalid session ID [16] : Parameters:    Level=null    IsHidden=False	Information: Error occurred on "null" level when trying to check attributes of subframe "null/21"
__WD_FrameList_Internal ==> Invalid session ID [16] : Parameters:    Level=null    IsHidden=False	Information: Error occurred on "null" level when trying to check attributes of subframe "null/22"
__WD_FrameList_Internal ==> Invalid session ID [16] : Parameters:    Level=null    IsHidden=False	Information: Error occurred on "null" level when trying to check attributes of subframe "null/23"
__WD_FrameList_Internal ==> Invalid session ID [16] : Parameters:    Level=null    IsHidden=False	Information: Error occurred on "null" level when trying to check attributes of subframe "null/24"
__WD_FrameList_Internal ==> Invalid session ID [16] : Parameters:    Level=null    IsHidden=False	Information: Error occurred on "null" level when trying to check attributes of subframe "null/25"
__WD_FrameList_Internal ==> Invalid session ID [16] : Parameters:    Level=null    IsHidden=False	Information: Error occurred on "null" level when trying to check attributes of subframe "null/26"
_WD_FrameList ==> Invalid session ID [16 / 0] : Parameters:    ReturnAsArray=True	Information: Was not able to check "calling frame".

that's what I was thinking when I wrote:

But I want to get them only once (when exiting main document) thus all this processing is needed.

We can get all error messages, maybe it will be better. But still we need to know what level of debuging was set by user.

ALL >> I mean one log per each __WD_FrameList_Internal calls.

@mlipok
Copy link
Contributor Author

mlipok commented Mar 17, 2023

WIP.....

still WIP

@mlipok
Copy link
Contributor Author

mlipok commented Mar 18, 2023

Won't $_WD_DEBUG get reset when exiting a nested frame? If so, then I don't think that is what you want.

Check current chnages from this: usage of $_WD_DEBUG_Saved / $sMessage

btw.
My previous comment is not WIP ;)

Danp2
Danp2 previously requested changes Mar 26, 2023
Copy link
Owner

@Danp2 Danp2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, a function doesn't belong in the related section simply because it is called internally by the UDF being documented. And this information gets used to generate links in the help file, and it doesn't make sense to me to have links to many of these functions from _WD_FrameList. I think that we should evaluate if this is the proper method of documenting these error codes.

@mlipok
Copy link
Contributor Author

mlipok commented Mar 27, 2023

I think that we should evaluate if this is the proper method of documenting these error codes.

Please propose solution by adding new commit.

@Danp2 Danp2 dismissed their stale review March 27, 2023 22:10

No longer relevant

@Danp2 Danp2 merged commit 0751aa4 into Danp2:master Mar 31, 2023
@mlipok mlipok deleted the _WD_FrameList---Refactoring branch March 31, 2023 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants