Skip to content

Commit 7f03988

Browse files
committed
Change logic for $_WD_DEBUG
Now supports multiple levels of logging instead of on/off
1 parent 4098b27 commit 7f03988

File tree

1 file changed

+52
-32
lines changed

1 file changed

+52
-32
lines changed

wd_core.au3

Lines changed: 52 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@
2424
; AutoIt Version : v3.3.14.3
2525
; ==============================================================================
2626
#cs
27+
V0.1.0.13
28+
- Fixed: Remove unsupported locator constants
29+
- Fixed: Return value of _WD_WaitElement
30+
- Changed: Add support for 'displayed' option in _WD_ElementAction (BigDaddyO)
31+
- Changed: Add $lVisible parameter to _WD_WaitElement
32+
- Changed: $_WD_DEBUG now defaults to $_WD_DEBUG_Info
33+
2734
V0.1.0.12
2835
- Changed: Modified _WD_NewTab with timeout parameter
2936
- Fixed: Correctly set @error in _WD_ExecuteScript
@@ -148,6 +155,11 @@ Global Const $_WD_LOCATOR_ByTagName = "tag name"
148155

149156
Global Const $_WD_DefaultTimeout = 10000 ; 10 seconds
150157

158+
Global Enum _
159+
$_WD_DEBUG_None = 0, _ ; No logging to console
160+
$_WD_DEBUG_Error, _ ; Error logging to console
161+
$_WD_DEBUG_Info ; Full logging to console
162+
151163
Global Enum _
152164
$_WD_ERROR_Success = 0, _ ; No error
153165
$_WD_ERROR_GeneralError, _ ; General error
@@ -189,7 +201,7 @@ Global $_WD_OHTTP = ObjCreate("winhttp.winhttprequest.5.1")
189201
Global $_WD_HTTPRESULT ; Result of last WinHTTP request
190202

191203
Global $_WD_ERROR_MSGBOX = True ; Shows in compiled scripts error messages in msgboxes
192-
Global $_WD_DEBUG = True ; Trace to console and show web driver app
204+
Global $_WD_DEBUG = $_WD_DEBUG_Info ; Trace to console and show web driver app
193205

194206
#EndRegion Global Variables
195207

@@ -217,7 +229,7 @@ Func _WD_CreateSession($sDesiredCapabilities = '{}')
217229
Local $sResponse = __WD_Post($_WD_BASE_URL & ":" & $_WD_PORT & "/session", $sDesiredCapabilities)
218230
Local $iErr = @error
219231

220-
If $_WD_DEBUG Then
232+
If $_WD_DEBUG = $_WD_DEBUG_Info Then
221233
ConsoleWrite($sFuncName & ': ' & $sResponse & @CRLF)
222234
EndIf
223235

@@ -261,7 +273,7 @@ Func _WD_DeleteSession($sSession)
261273
Local $sResponse = __WD_Delete($_WD_BASE_URL & ":" & $_WD_PORT & "/session/" & $sSession)
262274
Local $iErr = @error
263275

264-
If $_WD_DEBUG Then
276+
If $_WD_DEBUG = $_WD_DEBUG_Info Then
265277
ConsoleWrite($sFuncName & ': ' & $sResponse & @CRLF)
266278
EndIf
267279

@@ -294,7 +306,7 @@ Func _WD_Status()
294306
Local $sResponse = __WD_Get($_WD_BASE_URL & ":" & $_WD_PORT & "/status")
295307
Local $iErr = @error
296308

297-
If $_WD_DEBUG Then
309+
If $_WD_DEBUG = $_WD_DEBUG_Info Then
298310
ConsoleWrite($sFuncName & ': ' & $sResponse & @CRLF)
299311
EndIf
300312

@@ -339,7 +351,7 @@ Func _WD_Timeouts($sSession, $sTimeouts = '')
339351

340352
Local $iErr = @error
341353

342-
If $_WD_DEBUG Then
354+
If $_WD_DEBUG = $_WD_DEBUG_Info Then
343355
ConsoleWrite($sFuncName & ': ' & $sResponse & @CRLF)
344356
EndIf
345357

@@ -375,7 +387,7 @@ Func _WD_Navigate($sSession, $sURL)
375387

376388
Local $iErr = @error
377389

378-
If $_WD_DEBUG Then
390+
If $_WD_DEBUG = $_WD_DEBUG_Info Then
379391
ConsoleWrite($sFuncName & ': ' & $sResponse & @CRLF)
380392
EndIf
381393

@@ -449,7 +461,7 @@ Func _WD_Action($sSession, $sCommand, $sOption = '')
449461

450462
EndSwitch
451463

452-
If $_WD_DEBUG Then
464+
If $_WD_DEBUG = $_WD_DEBUG_Info Then
453465
ConsoleWrite($sFuncName & ': ' & $sResponse & @CRLF)
454466
EndIf
455467

@@ -580,7 +592,7 @@ Func _WD_Window($sSession, $sCommand, $sOption = '')
580592

581593
EndSwitch
582594

583-
If $_WD_DEBUG Then
595+
If $_WD_DEBUG = $_WD_DEBUG_Info Then
584596
ConsoleWrite($sFuncName & ': ' & $sResponse & @CRLF)
585597
EndIf
586598

@@ -660,7 +672,7 @@ Func _WD_FindElement($sSession, $sStrategy, $sSelector, $sStartElement = "", $lM
660672
EndIf
661673
EndIf
662674

663-
If $_WD_DEBUG Then
675+
If $_WD_DEBUG = $_WD_DEBUG_Info Then
664676
ConsoleWrite($sFuncName & ': ' & $sResponse & @CRLF)
665677
EndIf
666678

@@ -751,7 +763,7 @@ Func _WD_ElementAction($sSession, $sElement, $sCommand, $sOption = '')
751763

752764
EndSwitch
753765

754-
If $_WD_DEBUG Then
766+
If $_WD_DEBUG = $_WD_DEBUG_Info Then
755767
ConsoleWrite($sFuncName & ': ' & $sResponse & @CRLF)
756768
EndIf
757769

@@ -788,7 +800,7 @@ Func _WD_ExecuteScript($sSession, $sScript, $sArguments = "[]")
788800

789801
$sResponse = __WD_Post($_WD_BASE_URL & ":" & $_WD_PORT & "/session/" & $sSession & "/execute/sync", $sData)
790802

791-
If $_WD_DEBUG Then
803+
If $_WD_DEBUG = $_WD_DEBUG_Info Then
792804
ConsoleWrite($sFuncName & ': ' & $sResponse & @CRLF)
793805
EndIf
794806

@@ -871,7 +883,7 @@ Func _WD_Alert($sSession, $sCommand, $sOption = '')
871883
Return SetError(__WD_Error($sFuncName, $_WD_ERROR_InvalidDataType, "(Dismiss|Accept|GetText|SendText|Status) $sCommand=>" & $sCommand), 0, "")
872884
EndSwitch
873885

874-
If $_WD_DEBUG Then
886+
If $_WD_DEBUG = $_WD_DEBUG_Info Then
875887
ConsoleWrite($sFuncName & ': ' & $sResponse & @CRLF)
876888
EndIf
877889

@@ -912,7 +924,7 @@ Func _WD_GetSource($sSession)
912924
$sResult = Json_Get($sJSON, "[value]")
913925
EndIf
914926

915-
If $_WD_DEBUG Then
927+
If $_WD_DEBUG = $_WD_DEBUG_Info Then
916928
ConsoleWrite($sFuncName & ': ' & $sResponse & @CRLF)
917929
EndIf
918930

@@ -983,7 +995,7 @@ Func _WD_Cookies($sSession, $sCommand, $sOption = '')
983995
Return SetError(__WD_Error($sFuncName, $_WD_ERROR_InvalidDataType, "(GetAll|Get|Add|Delete) $sCommand=>" & $sCommand), "")
984996
EndSwitch
985997

986-
If $_WD_DEBUG Then
998+
If $_WD_DEBUG = $_WD_DEBUG_Info Then
987999
ConsoleWrite($sFuncName & ': ' & $sResponse & @CRLF)
9881000
EndIf
9891001

@@ -1084,7 +1096,7 @@ Func _WD_Startup()
10841096

10851097
Local $sCommand = StringFormat('"%s" %s ', $_WD_DRIVER, $_WD_DRIVER_PARAMS)
10861098

1087-
If $_WD_DEBUG Then
1099+
If $_WD_DEBUG = $_WD_DEBUG_Info Then
10881100
ConsoleWrite("_WDStartup: OS:" & @TAB & @OSVersion & " " & @OSType & " " & @OSBuild & " " & @OSServicePack & @CRLF)
10891101
ConsoleWrite("_WDStartup: AutoIt:" & @TAB & @AutoItVersion & @CRLF)
10901102
ConsoleWrite("_WDStartup: WD.au3:" & @TAB & $__WDVERSION & @CRLF)
@@ -1095,7 +1107,7 @@ Func _WD_Startup()
10951107
ConsoleWrite('_WDStartup: ' & $sCommand & @CRLF)
10961108
EndIf
10971109

1098-
Local $pid = Run($sCommand, "", $_WD_DEBUG ? @SW_SHOW : @SW_HIDE)
1110+
Local $pid = Run($sCommand, "", ($_WD_DEBUG = $_WD_DEBUG_Info) ? @SW_SHOW : @SW_HIDE)
10991111

11001112
If @error Then
11011113
Return SetError(__WD_Error($sFuncName, $_WD_ERROR_GeneralError, "Error launching web driver!"), 0, 0)
@@ -1144,7 +1156,7 @@ Func __WD_Get($sURL)
11441156
Local Const $sFuncName = "__WD_Get"
11451157
Local $iResult, $sResponseText
11461158

1147-
If $_WD_DEBUG Then
1159+
If $_WD_DEBUG = $_WD_DEBUG_Info Then
11481160
ConsoleWrite($sFuncName & ': URL=' & $sURL & @CRLF)
11491161
EndIf
11501162

@@ -1169,7 +1181,7 @@ Func __WD_Get($sURL)
11691181
EndIf
11701182
EndIf
11711183

1172-
If $_WD_DEBUG Then
1184+
If $_WD_DEBUG = $_WD_DEBUG_Info Then
11731185
ConsoleWrite($sFuncName & ': StatusCode=' & $_WD_HTTPRESULT & "; $sResponseText=" & $sResponseText & @CRLF)
11741186
EndIf
11751187

@@ -1208,7 +1220,7 @@ Func __WD_Post($sURL, $sData)
12081220
Local Const $sFuncName = "__WD_Post"
12091221
Local $iResult, $sResponseText, $iErr
12101222

1211-
If $_WD_DEBUG Then
1223+
If $_WD_DEBUG = $_WD_DEBUG_Info Then
12121224
ConsoleWrite($sFuncName & ': URL=' & $sURL & "; $sData=" & $sData & @CRLF)
12131225
EndIf
12141226

@@ -1234,7 +1246,7 @@ Func __WD_Post($sURL, $sData)
12341246
EndIf
12351247
EndIf
12361248

1237-
If $_WD_DEBUG Then
1249+
If $_WD_DEBUG = $_WD_DEBUG_Info Then
12381250
ConsoleWrite($sFuncName & ': StatusCode=' & $_WD_HTTPRESULT & "; ResponseText=" & $sResponseText & @CRLF)
12391251
EndIf
12401252

@@ -1267,7 +1279,7 @@ Func __WD_Delete($sURL)
12671279

12681280
Local $iResult, $sResponseText
12691281

1270-
If $_WD_DEBUG Then
1282+
If $_WD_DEBUG = $_WD_DEBUG_Info Then
12711283
ConsoleWrite($sFuncName & ': URL=' & $sURL & @CRLF)
12721284
EndIf
12731285

@@ -1292,7 +1304,7 @@ Func __WD_Delete($sURL)
12921304
EndIf
12931305
EndIf
12941306

1295-
If $_WD_DEBUG Then
1307+
If $_WD_DEBUG = $_WD_DEBUG_Info Then
12961308
ConsoleWrite($sFuncName & ': StatusCode=' & $_WD_HTTPRESULT & "; ResponseText=" & $sResponseText & @CRLF)
12971309
EndIf
12981310

@@ -1325,19 +1337,27 @@ EndFunc ;==>__WD_Delete
13251337
; ===============================================================================================================================
13261338
Func __WD_Error($sWhere, $i_WD_ERROR, $sMessage = "")
13271339
Local $sMsg
1328-
Sleep(200)
13291340

1330-
$sMsg = $sWhere & " ==> " & $aWD_ERROR_DESC[$i_WD_ERROR]
1341+
Switch $_WD_DEBUG
1342+
Case $_WD_DEBUG_None
13311343

1332-
If $sMessage <> "" Then
1333-
$sMsg = $sMsg & ": " & $sMessage
1334-
EndIf
1344+
Case $_WD_DEBUG_Error
1345+
If $i_WD_ERROR <> $_WD_ERROR_Success Then ContinueCase
13351346

1336-
ConsoleWrite($sMsg & @CRLF)
1337-
If @Compiled Then
1338-
If $_WD_ERROR_MSGBOX And $i_WD_ERROR < 6 Then MsgBox(16, "WD_Core.au3 Error:", $sMsg)
1339-
DllCall("kernel32.dll", "none", "OutputDebugString", "str", $sMsg)
1340-
EndIf
1347+
Case $_WD_DEBUG_Info
1348+
$sMsg = $sWhere & " ==> " & $aWD_ERROR_DESC[$i_WD_ERROR]
1349+
1350+
If $sMessage <> "" Then
1351+
$sMsg = $sMsg & ": " & $sMessage
1352+
EndIf
1353+
1354+
ConsoleWrite($sMsg & @CRLF)
1355+
1356+
If @Compiled Then
1357+
If $_WD_ERROR_MSGBOX And $i_WD_ERROR < 6 Then MsgBox(16, "WD_Core.au3 Error:", $sMsg)
1358+
DllCall("kernel32.dll", "none", "OutputDebugString", "str", $sMsg)
1359+
EndIf
1360+
EndSwitch
13411361

13421362
Return $i_WD_ERROR
13431363
EndFunc ;==>__WD_Error

0 commit comments

Comments
 (0)