#include #include ;#=#Function#===========================================================================# ;# Title .........: _OnAutoItError() # ;# Description....: AutoIt3 Error Handler & Debugger GUI # ;# Parameters.....: (None) # ;# Date ..........: 7.9.08 # ;# Authors .......: jennico (jennicoattminusonlinedotde) # ;# @MrCreatoR # ;# https://www.autoitscript.com/forum/topic/79950-autoit-error-handler-and-debugger/ # ;#======================================================================================# #include-once Func OnAutoItError() If StringInStr($CmdLineRaw,"/AutoIt3ExecuteScript") Then Return Opt("TrayIconHide",1) ; run a second instance $iPID=Run(@AutoItExe&' /ErrorStdOut /AutoIt3ExecuteScript "'&@ScriptFullPath&'"',@ScriptDir,0,6) ProcessWait($iPID) $sErrorMsg="" ; trap the error message While 1 $sErrorMsg&=StdoutRead($iPID) If @error Then ExitLoop Sleep(1) WEnd If $sErrorMsg="" Then Exit WinSetState(@ScriptName,"",@SW_HIDE) $a=StringSplit($sErrorMsg,@CRLF,1) $scitePath=RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\SciTE.exe","") Dim $b=StringSplit($a[1],") : ==> ",1),$number=StringMid($b[1],StringInStr($b[1],"(")+1) Dim $code="Error Code: "&@TAB&StringTrimRight($b[2],2),$line="Line: "&@TAB&$number&" => "&$a[3] Dim $file="File: "&@TAB&StringReplace($b[1]," ("&$number,""),$count=StringLen($code),$height=180 ; caseNoUpdate($caseNo, $caseTitle, $currentCaseNo, $currentCaseTitle) FileWrite($sLogFile, "Current caseNo: " & $caseNo & ". Current caseTitle: " & $caseTitle & @CRLF) FileWrite($sLogFile, " Case Fail." & @CRLF) FileWrite($sLogFile, $code & @CRLF) FileWrite($sLogFile, $file & @CRLF) FileWrite($sLogFile, $line & @CRLF) GUICreate(@ScriptName,385,90,Default,Default,-2134376448);BitOR($WS_CAPTION,$WS_POPUP,$WS_SYSMENU) GUISetBkColor(0xE0DFE2) GUICtrlSetBkColor(GUICtrlCreateLabel("",1,1,383,1),0x41689E) GUICtrlSetBkColor(GUICtrlCreateLabel("",1,88,383,1),0x41689E) GUICtrlSetBkColor(GUICtrlCreateLabel("",1,1,1,88),0x41689E) GUICtrlSetBkColor(GUICtrlCreateLabel("",383,1,1,88),0x41689E) GUICtrlCreateIcon("user32.dll",103,11,11,32,32) GUICtrlSetBkColor(GUICtrlCreateLabel("An error occurred in the application.",52,21,175,15),-2) GUICtrlSetBkColor(GUICtrlCreateLabel("",10,60,110,22),0x706E63) GUICtrlSetState(-1,128) $send=GUICtrlCreateLabel(" send bug report",28,64,92,15) GUICtrlSetBkColor(-1,-2) GUICtrlSetColor(-1,0xFFFFFF) GUICtrlSetCursor(-1,0) $sen=GUICtrlCreateIcon("explorer.exe",254,13,63,16,16) GUICtrlSetCursor(-1,0) GUICtrlSetBkColor(GUICtrlCreateLabel("",124,60,114,22),0xEFEEF2) GUICtrlSetState(-1,128) $show=GUICtrlCreateLabel(" show bug report",143,64,95,15) If @Compiled=0 Then GUICtrlSetData(-1," De-Bug Script") GUICtrlSetBkColor(-1,-2) GUICtrlSetCursor(-1,0) $sho=GUICtrlCreateIcon("shell32.dll",23,127,63,16,16) If @Compiled=0 Then GUICtrlSetImage(-1,"shell32.dll",-81) GUICtrlSetCursor(-1,0) GUICtrlSetBkColor(GUICtrlCreateLabel("",246,60,131,22),0xEFEEF2) GUICtrlSetState(-1,128) $close=GUICtrlCreateLabel(" close application",265,64,115,15) GUICtrlSetBkColor(-1,-2) GUICtrlSetCursor(-1,0) $clos=GUICtrlCreateIcon("shell32.dll",240,249,63,16,16) GUICtrlSetCursor(-1,0) GUISetState() WinSetOnTop(@ScriptName,"",1) ; SoundPlay(@WindowsDir&"\Media\chord.wav") Opt("TrayIconHide",0) Opt("TrayAutoPause",0) TraySetToolTip("AutoIt Error Handler and Debugger") ; choose action to be taken $Timer = TimerInit() Do $TimeDiff = TimerDiff($Timer) $msg=GUIGetMsg() ; If $msg=$cont Or $msg=$con Then FileWrite("result.log.txt", " Case Fail." & @CRLF) If $msg=$send Or $msg=$sen Then MsgBox(270400,"Send Bug Report","Email successfully sent ! ") ;#include ; use email ;_INetSmtpMail ( $s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress [,$s_Subject&_ ;[,$as_Body [,$s_helo, [,$s_first [,$b_trace]]]]]) If $msg=$show Or $msg=$sho Then If @Compiled=0 Then __Debug($sErrorMsg) If @Compiled Then MsgBox(270400,"Show Bug Report",$sErrorMsg&" ") EndIf If $msg=$close Or $TimeDiff > 10000 Then Exit Until $msg=-3 Or $msg=$close Or $msg=$clos ; If $msg=$rest Or $msg=$res Then Run(@AutoItExe&' "'&@ScriptFullPath&'"',@ScriptDir,0,6) Capture($caseNo, $caseTitle, $code) ProcessClose($iPID) Exit EndFunc ;#=#Function#===============================================================# ;# Title .........: __Debug ( $txt ) # ;# Description....: Debug Function for _ErrorHandler.au3 # ;# Parameters.....: $txt = Error Message Text from StdoutRead # ;# Date ..........: 7.9.08 # ;# Authors .......: jennico (jennicoattminusonlinedotde) # ;# @MrCreatoR # ;#==========================================================================# Func __Debug($txt) WinSetState(@ScriptName,"",@SW_HIDE) $a=StringSplit($txt,@CRLF,1) $scitePath=RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\SciTE.exe","") Dim $b=StringSplit($a[1],") : ==> ",1),$number=StringMid($b[1],StringInStr($b[1],"(")+1) Dim $code="Error Code: "&@TAB&StringTrimRight($b[2],2),$line="Line: "&@TAB&$number&" => "&$a[3] Dim $file="File: "&@TAB&StringReplace($b[1]," ("&$number,""),$count=StringLen($code),$height=180 If StringLen($file)>$count Then $count=StringLen($file) If StringLen($line)>$count Then $count=StringLen($line) If StringLen($a[2])>$count Then $count=StringLen($a[2]) If $count*6>@DesktopWidth-50 Then Dim $count=(@DesktopWidth-50)/6,$height=240 $pid=Run($scitePath&' "'&@ScriptFullPath&'" /goto:'&$number&","&StringLen($a[2])-1) $x=InputBox(" Please Correct this line:",$code&@CRLF&@CRLF&$file&@CRLF&@CRLF& _ $line,StringTrimRight($a[2],1),"",$count*6,$height) WinSetState(@ScriptName,"",@SW_SHOW) If $x="" Or $x=StringTrimRight($a[2],1) Then Return $t=StringSplit(FileRead(@ScriptFullPath),@CRLF,1) $t[$number]=StringReplace($t[$number],StringTrimRight($a[2],1),$x) $open=FileOpen(@ScriptFullPath,2) For $i=1 to $t[0] FileWriteLine($open,$t[$i]) Next FileClose($open) ControlSend(@ScriptDir,"","ToolbarWindow32","^R") EndFunc Func _WinWaitActivate($title,$text,$timeout=0) WinWait($title,$text,$timeout) If Not WinActive($title,$text) Then WinActivate($title,$text) WinWaitActive($title,$text,$timeout) EndFunc Func Capture($caseNo,$caseTitle,$code) FileWrite($sLogFile, "capture case no:" & $caseNo & " Case title: " & $caseTitle & @CRLF) $caseFileDir = ("C:\Users\ico\Desktop\ims_uat\autoIt_script\IMS_testing_autoIt\screenCapture\" & @YEAR & @MON & @MDAY & "\" & $caseNo) DirCreate($caseFileDir) $errorString = "error" If StringInStr($code, $errorString) Then $errorScreenCapDir = ("\Users\ico\Desktop\ims_uat\autoIt_script\IMS_testing_autoIt\screenCapture\" & @YEAR & @MON & @MDAY & "\" & $caseNo) $errorScreenCapOriTitle = ("\" & $caseNo & "_" & $caseTitle & "_CaseFail.png") $aSplit = StringSplit($errorScreenCapOriTitle, ".") $errorScreenCapTitle = $aSplit[1] & " " & @YEAR & @MON & @MDAY & @HOUR & @MIN & "." & $aSplit[2] Local $hBmp ; Capture full screen $hBmp = _ScreenCapture_Capture("") ; Save bitmap to file _ScreenCapture_SaveImage($errorScreenCapDir & $errorScreenCapTitle, $hBmp) Else $screenCapDir = ("\Users\ico\Desktop\ims_uat\autoIt_script\IMS_testing_autoIt\screenCapture\" & @YEAR & @MON & @MDAY & "\" & $caseNo) ; $screenCapDir = ("\Users\ico\Desktop\ims_uat\autoIt_script\IMS_testing_autoIt\screenCapture\" & @YEAR & @MON & @MDAY & "\" & $caseNo) $screenCapOriTitle = ("\" & $caseNo & "_" & $caseTitle & "_Success.png") $bSplit = StringSplit($screenCapOriTitle, ".") $screenCapTitle = $bSplit[1] & " " & @YEAR & @MON & @MDAY & @HOUR & @MIN & "." & $bSplit[2] Local $hBmp ; Capture full screen $hBmp = _ScreenCapture_Capture("") ; Save bitmap to file _ScreenCapture_SaveImage($screenCapDir & $screenCapTitle, $hBmp) EndIf ;ShellExecute("\Users\ico\Desktop\ims_uat\autoIt_script\IMS_testing_autoIt\screenCapture" & "\captureImage.jpg") EndFunc