Skip to content

Detailed error reporting #448

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 7 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

Go to [legend](#legend---types-of-changes) for further information about the types of changes.

## [Unreleased]

### Added

- _WD_WaitScript (@ye7iaserag)
- _WD_Option: Support for `DetailErrors` option

### Changed
- Enable optional detailed error reporting
- _WD_Attach
- _WD_CreateSession
- _WD_DeleteSession
- _WD_FrameEnter
- _WD_FrameLeave
- _WD_LinkClickByText

## [ 0.13.0]

### Added
Expand Down
17 changes: 14 additions & 3 deletions wd_core.au3
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ Global $_WD_DefaultTimeout = 10000 ; 10 seconds
Global $_WD_WINHTTP_TIMEOUTS = True
Global $_WD_HTTPTimeOuts[4] = [0, 60000, 30000, 30000]
Global $_WD_HTTPContentType = "Content-Type: application/json"
Global $_WD_DetailedErrors = False

#EndRegion Global Variables

Expand Down Expand Up @@ -256,7 +257,7 @@ Func _WD_CreateSession($sCapabilities = Default)
Else
If $iErr = $_WD_ERROR_SessionNotCreated Then
$sMessage = Json_Get($oJSON, $_WD_JSON_Message)
Else
ElseIf Not $_WD_DetailedErrors Then
$iErr = $_WD_ERROR_Exception
EndIf
EndIf
Expand All @@ -281,7 +282,9 @@ EndFunc ;==>_WD_CreateSession
Func _WD_DeleteSession($sSession)
Local Const $sFuncName = "_WD_DeleteSession"
__WD_Delete($_WD_BASE_URL & ":" & $_WD_PORT & "/session/" & $sSession)
Local $iErr = (@error) ? ($_WD_ERROR_Exception) : ($_WD_ERROR_Success)
Local $iErr = @error

If $iErr <> $_WD_ERROR_Success And Not $_WD_DetailedErrors Then $iErr = $_WD_ERROR_Exception

Local $sMessage = ($iErr) ? ('Error occurs when trying to delete session') : ('WebDriver session deleted')
Local $iReturn = ($iErr) ? (0) : (1)
Expand Down Expand Up @@ -1041,6 +1044,7 @@ EndFunc ;==>_WD_Cookies
; |CONSOLESUFFIX - Suffix for console output
; |DEBUGTRIM - Length of response text written to the debug cocnsole
; |DEFAULTTIMEOUT - Default timeout (in miliseconds) used by other functions if no other value is supplied
; |DETAILERRORS - Return detailed error codes? (Boolean)
; |DRIVER - Full path name to web driver executable
; |DRIVERCLOSE - Close prior driver instances before launching new one (Boolean)
; |DRIVERDETECT - Use existing driver instance if it exists (Boolean)
Expand Down Expand Up @@ -1107,6 +1111,13 @@ Func _WD_Option($sOption, $vValue = Default)
EndIf
$_WD_DefaultTimeout = $vValue

Case "detailerrors"
If $vValue == "" Then Return $_WD_DetailedErrors
If Not IsBool($vValue) Then
Return SetError(__WD_Error($sFuncName, $_WD_ERROR_InvalidDataType, $sParameters & " (Required $vValue type: bool)"), 0, 0)
EndIf
$_WD_DetailedErrors = $vValue

Case "driver"
If $vValue == "" Then Return $_WD_DRIVER
If Not IsString($vValue) Then
Expand Down Expand Up @@ -1175,7 +1186,7 @@ Func _WD_Option($sOption, $vValue = Default)
Return SetError(__WD_Error($sFuncName, $_WD_ERROR_InvalidDataType, $sParameters & " (Required $vValue type: none)"), 0, 0)

Case Else
Return SetError(__WD_Error($sFuncName, $_WD_ERROR_InvalidDataType, $sParameters & " (Required $sOption: BaseURL|BinaryFormat|Console|ConsoleSuffix|DebugTrim|DefaultTimeout|Driver|DriverClose|DriverDetect|DriverParams|ErrorMsgBox|HTTPTimeouts|OutputDebug|Port|Sleep|Version)"), 0, 0)
Return SetError(__WD_Error($sFuncName, $_WD_ERROR_InvalidDataType, $sParameters & " (Required $sOption: BaseURL|BinaryFormat|Console|ConsoleSuffix|DebugTrim|DefaultTimeout|DetailErrors|Driver|DriverClose|DriverDetect|DriverParams|ErrorMsgBox|HTTPTimeouts|OutputDebug|Port|Sleep|Version)"), 0, 0)
EndSwitch

Return SetError(__WD_Error($sFuncName, $_WD_ERROR_Success, $sParameters), 0, 1)
Expand Down
11 changes: 6 additions & 5 deletions wd_helper.au3
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,9 @@ Func _WD_Attach($sSession, $sSearch, $sMode = Default)
If $sMode = Default Then $sMode = 'title'

$aHandles = _WD_Window($sSession, 'handles')
$iErr = @error

If @error = $_WD_ERROR_Success Then
If $iErr = $_WD_ERROR_Success Then
$sCurrentTab = _WD_Window($sSession, 'window')

For $sHandle In $aHandles
Expand Down Expand Up @@ -280,7 +281,7 @@ Func _WD_Attach($sSession, $sSearch, $sMode = Default)

$iErr = $_WD_ERROR_NoMatch
EndIf
Else
ElseIf Not $_WD_DetailedErrors Then
$iErr = $_WD_ERROR_GeneralError
EndIf

Expand Down Expand Up @@ -320,7 +321,7 @@ Func _WD_LinkClickByText($sSession, $sText, $bPartial = Default, $sStartNodeID =
_WD_ElementAction($sSession, $sElement, 'click')
$iErr = @error

If $iErr <> $_WD_ERROR_Success Then
If $iErr <> $_WD_ERROR_Success And Not $_WD_DetailedErrors Then
$iErr = $_WD_ERROR_Exception
EndIf
Else
Expand Down Expand Up @@ -767,7 +768,7 @@ Func _WD_FrameEnter($sSession, $vIdentifier)
Else
$sValue = True
EndIf
ElseIf $iErr <> $_WD_ERROR_InvalidArgue Then
ElseIf $iErr <> $_WD_ERROR_InvalidArgue And Not $_WD_DetailedErrors Then
$iErr = $_WD_ERROR_Exception
EndIf

Expand Down Expand Up @@ -806,7 +807,7 @@ Func _WD_FrameLeave($sSession)
Else
$sValue = True
EndIf
Else
ElseIf Not $_WD_DetailedErrors Then
$iErr = $_WD_ERROR_Exception
EndIf

Expand Down