Skip to content

Commit b729479

Browse files
authored
Misc fixes (#8)
* _WD_Attach: Additional error handling * Missing variable declarations * Bump version number
1 parent ecdc4e9 commit b729479

File tree

3 files changed

+49
-37
lines changed

3 files changed

+49
-37
lines changed

wd_core.au3

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
; AutoIt Version : v3.3.14.2
1919
; ==============================================================================
2020
#cs
21+
V0.1.0.5
22+
- Fixed: Missing variable declarations
23+
- Changed:
24+
2125
V0.1.0.5
2226
- Changed: Switched to using _WinHttp functions
2327
- Added: _WD_LinkClickByText
@@ -82,7 +86,7 @@
8286

8387

8488
#Region Global Constants
85-
Global Const $__WDVERSION = "0.1.0.5"
89+
Global Const $__WDVERSION = "0.1.0.6"
8690

8791
Global Const $_WD_LOCATOR_ByID = "id"
8892
Global Const $_WD_LOCATOR_ByName = "name"
@@ -107,9 +111,9 @@ Global Enum _
107111
$_WD_ERROR_RetValue, _ ; Error echo from Repl e.g. _WDAction("fullscreen","true") <> "true"
108112
$_WD_ERROR_Exception, _ ; Exception from web driver
109113
$_WD_ERROR_InvalidExpression, _ ; Invalid expression in XPath query or RegEx
110-
$_WD_ERROR_COUTNER ;
114+
$_WD_ERROR_COUNTER ;
111115

112-
Global Const $aWD_ERROR_DESC[$_WD_ERROR_COUTNER] = [ _
116+
Global Const $aWD_ERROR_DESC[$_WD_ERROR_COUNTER] = [ _
113117
"Success", _
114118
"General Error", _
115119
"Socket Error", _
@@ -424,7 +428,7 @@ EndFunc
424428
; ===============================================================================================================================
425429
Func _WD_Window($sSession, $sCommand, $sOption = '')
426430
Local Const $sFuncName = "_WD_Window"
427-
Local $sResponse, $sJSON, $sResult = ""
431+
Local $sResponse, $sJSON, $sResult = "", $iErr
428432

429433
$sCommand = StringLower($sCommand)
430434

@@ -599,7 +603,7 @@ EndFunc ;==>_WDFindElement
599603
; ===============================================================================================================================
600604
Func _WD_ElementAction($sSession, $sElement, $sCommand, $sOption='')
601605
Local Const $sFuncName = "_WD_ElementAction"
602-
Local $sResponse, $sResult = '', $iErr
606+
Local $sResponse, $sResult = '', $iErr, $oJson
603607

604608
$sCommand = StringLower($sCommand)
605609

wd_helper.au3

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ EndFunc
8484
; | HTML
8585
; Return values .: Success - String representing handle of matching tab
8686
; Failure - blank string
87+
; @ERROR - $_WD_ERROR_Success
88+
; - $_WD_ERROR_InvalidDataType
89+
; - $_WD_ERROR_NoMatch
90+
; - $_WD_ERROR_GeneralError
8791
; Author ........: Dan Pollak
8892
; Modified ......:
8993
; Remarks .......:
@@ -98,37 +102,41 @@ Func _WD_Attach($sSession, $sString, $sMode = 'title')
98102
Local $sCurrentTab = _WD_Window($sSession, 'window')
99103
Local $aHandles = _WD_Window($sSession, 'handles')
100104

101-
$sMode = StringLower($sMode)
102-
103-
For $sHandle In $aHandles
104-
105-
_WD_Window($sSession, 'Switch', '{"handle":"' & $sHandle & '"}')
106-
107-
Switch $sMode
108-
Case "title", "url"
109-
If StringInStr(_WD_Action($sSession, $sMode), $sString) > 0 Then
110-
$lFound = True
111-
$sTabHandle = $sHandle
112-
ExitLoop
113-
EndIf
114-
115-
Case 'html'
116-
If StringInStr(_WD_GetSource($sSession), $sString) > 0 Then
117-
$lFound = True
118-
$sTabHandle = $sHandle
119-
ExitLoop
120-
EndIf
121-
122-
Case Else
123-
SetError(__WD_Error($sFuncName, $_WD_ERROR_InvalidDataType, "(Title|URL|HTML) $sOption=>" & $sMode))
124-
Return ""
125-
EndSwitch
126-
Next
127-
128-
If Not $lFound Then
129-
; Restore prior active tab
130-
_WD_Window($sSession, 'Switch', '{"handle":"' & $sCurrentTab & '"}')
131-
SetError(__WD_Error($sFuncName, $_WD_ERROR_NoMatch))
105+
If @error = $_WD_ERROR_Success Then
106+
$sMode = StringLower($sMode)
107+
108+
For $sHandle In $aHandles
109+
110+
_WD_Window($sSession, 'Switch', '{"handle":"' & $sHandle & '"}')
111+
112+
Switch $sMode
113+
Case "title", "url"
114+
If StringInStr(_WD_Action($sSession, $sMode), $sString) > 0 Then
115+
$lFound = True
116+
$sTabHandle = $sHandle
117+
ExitLoop
118+
EndIf
119+
120+
Case 'html'
121+
If StringInStr(_WD_GetSource($sSession), $sString) > 0 Then
122+
$lFound = True
123+
$sTabHandle = $sHandle
124+
ExitLoop
125+
EndIf
126+
127+
Case Else
128+
SetError(__WD_Error($sFuncName, $_WD_ERROR_InvalidDataType, "(Title|URL|HTML) $sOption=>" & $sMode))
129+
Return ""
130+
EndSwitch
131+
Next
132+
133+
If Not $lFound Then
134+
; Restore prior active tab
135+
_WD_Window($sSession, 'Switch', '{"handle":"' & $sCurrentTab & '"}')
136+
SetError(__WD_Error($sFuncName, $_WD_ERROR_NoMatch))
137+
EndIf
138+
Else
139+
SetError(__WD_Error($sFuncName, $_WD_ERROR_GeneralError))
132140
EndIf
133141

134142
Return $sTabHandle

wd_test.au3

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ EndFunc
5757

5858
;_WDWindow($sSession, 'frame', '{"id":nullelse
5959
Func TestElements()
60-
Local $sElement
60+
Local $sElement, $aElements, $sValue
6161

6262
_WD_Navigate($sSession, "http://google.com")
6363
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='lst-ib1']")

0 commit comments

Comments
 (0)