Jump to content
Sign in to follow this  
sonali

Script stops running randomly

Recommended Posts

sonali

Hi all,

We are using AutoIT V3 for testing our windows Applications.

We have been facing some issue from a few days, and are unable to solve it.

Kindly do suggest some ideas for logging or some suggestion on how to resolve this issue

We put our script on nightly runs. But unfortunately, every morning we see that the script has stopped working. The application seems to be still open.

some details of our application and our script

Application : Windows tabbed window application

Scripts: We have written multiple scripts to handle each control and windows in the application.

The scripts stops randomly with the application open.

Share this post


Link to post
Share on other sites
water

Add

AutoItSetOption("TrayIconDebug", 1)
at the top of your script. If you then move the mouse over the AutoIt icon in the system tray the currently processed statement will be displayed.

Without having seen your script I suspect a WinWait or similar statement.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
sonali

#include "InputHeader_BMP.au3"

Local $strErrorLogName = 'sa_ThresholdImageCombined_BMP.txt'
Local $strErrorLogPathName = $strErrorLogPath&$strErrorLogName

Global $strThreshConst = 50
Global $iGetBimodalText

Global $iXCord = 718
Global $iYCord = 169

Global $iSleepTime = 500

Global $file = FileOpen($strErrorLogPathName,2)
if($file == -1) Then
MsgBox(0, "Error", "Unable to open the file")
Exit
EndIf
Run($strApplicationPath)
for $iOperation = 0 to 2 Step 1
Main($strInputImgPath1k,$strName1k,$strName8bits,$iOperation)
Main($strInputImgPath2k,$strName2k,$strName8bits,$iOperation)
Main($strInputImgPath4k,$strName4k,$strName8bits,$iOperation)
Main($strInputImgPath10,$strName10,$strName8bits,$iOperation)
Main($strInputImgPath512,$strName512,$strName8bits,$iOperation)

Main($strInputColorImgPath1k,$strName1k,$strNameColor,$iOperation)
Main($strInputColorImgPath2k,$strName2k,$strNameColor,$iOperation)
Main($strInputColorImgPath4k,$strName4k,$strNameColor,$iOperation)
Main($strInputColorImgPath10,$strName10,$strNameColor,$iOperation)
Main($strInputColorImgPath512,$strName512,$strNameColor,$iOperation)
Next


Local $strActive = WinActive("ss", "Ready")
if @error == 0 Then
Winclose("ss")
EndIf


Func Main($strInpPath,$strImgName,$strOutPath,$iOperation)
Global $winsa = WinWaitActive("ss","Ready")
if ($winsa == 0) Then
FileWriteLine($file,"Error: sa Window is not Active")
Else
FileWriteLine($file,"ss.exe Application Is Running")
FileWriteLine($file," ")
if($iOperation == 0) Then
FileWriteLine($file,"::::::::::::::::BIMODAL THRESHOLD::::::::::::::")
ElseIf($iOperation == 1) Then
FileWriteLine($file,"::::::::::::::::LOWER THRESHOLD::::::::::::::")
ElseIf($iOperation == 2) Then
FileWriteLine($file,"::::::::::::::::UPPER THRESHOLD::::::::::::::")
EndIf

for $i = 1 to 4 Step 1
Local $iReset = 1
Local $str1 = String($i)
Local $str2 = $strImgName
Local $str3 = $str2&$str1
Local $str4 = '.bmp'
Local $str5 = $str3&$str4

;ControlClick($winsa,"",59398,"left",1,70,48)
;sleep($iSleepTime)
;ControlClick($winsa,"",59398,"left",1,79,85)
ControlClick("ss","",59398,"left",1,$iXClickFile,$iYClickFile)
ControlClick("ss","",59398,"left",1,$iXClickOpen,$iYClickOpen)
Local $winOpen1 = WinWaitActive("Open","")
if $winOpen1 == 0 Then
FileWriteLine($winOpen1,"Error: File->Open Window Not Active")
Else
FileWriteLine($file," ")
FileWriteLine($file,"File->Open Window is Active")
Local $str6 = $strInpPath&$str5
Local $strOpenIm1 = ControlSetText($winOpen1,"",1148,$str6)
ControlClick($winOpen1,"&Open","Button1"); Button2 for WinXP
sleep($iSleepTime)

Local $WarnImage = WinExists("ss","This Window is already open")
if ($WarnImage == 1) Then
$str61 = 'Warning: '&$str5&' Is Already Open'
FileWriteLine($WarnImage,$str61)
ControlClick("ss","","Button1")
EndIf
Local $WarnImage1 = winExists("ss","Unable to load the image.")
if ($WarnImage1 == 1) Then
$str71 = 'Warning: Unable to load iamge - '&$str5
FileWriteLine($file,$str71)
ControlClick("ss","","Button1")
$iReset = 0
EndIf

Local $WarnImage2 = WinExists("ss","Error opening image file")
If($WarnImage2 == 1) Then
FileWriteLine($file,"Error Opening image file")
ControlClick("ss","","Button1")
sleep($iSleepTime)
ControlClick("ss","","Button1")
sleep($iSleepTime)
ControlClick("ss","","Button1")
$iReset = 0
EndIf

Local $var = ControlGetText( "[Active]", "", "[ID:65280]" )
$process = 'Processing Image: '&$var
FileWriteLine($file,$process)

Global $iHandle1 = ControlGetHandle("[Active]","","[ID:65280]")
if(@error == 1) Then
FileWriteLine($file,"Cannot Get Handle")
Else
;FileWriteLine($file,$iHandle1)
ControlHide("[Active]","","[ID:65280]")
if($iReset == 1) Then
ThresholdOperations($str3,$strOutPath,$iOperation)
EndIf
EndIf
EndIf
FileWriteLine($file," ")
Next
EndIf
EndFunc

Func ThresholdOperations($str3,$strOutPath,$iType)
Local $iReset = 1
Local $strOut =  $strOutputImgPath&$strOutPath&$str3
;ControlClick($winsa,"",59398,"left",1,140,50)
;sleep($iSleepTime)
;ControlClick($winsa,"",59398,"left",1,253,85)
ControlClick("ss","",59398,"left",1,$iXClickOperation,$iYClickOperation)
ControlClick("ss","",59398,"left",1,$iXClickThreshold,$iYClickThreshold)
Local $winThresh = WinWaitActive($Winsa,"Thresold Operation");
if $winThresh == 0 Then
FileWriteLine($file,"Error: Operations-> Threshold Window Not Available")
Else
FileWriteLine($file,"Operations-> Threshold Window Available")
ControlCommand($winThresh,"","ComboBox2", "SetCurrentSelection", $iType)
if @error == 1 Then
FileWriteLine($file,"Error: Thrshold->ComboBox2 Selection Failure")
Else
FileWriteLine($file,"Threshold->ComboBox2 Selection Pass")
EndIf
sleep($iSleepTime)

$strCombo3 = $str3&'.bmp'
ControlCommand($winThresh,"","ComboBox3","ShowDropDown", "")
if @error == 1 Then
FileWriteLine($file,"Error: Input Image ComboBox ShowDropDown Fail")
Else
FileWriteLine($file,"Input Image ComboBox ShowDropDown Pass")
EndIf
ControlCommand($winThresh, "", "ComboBox3", "SelectString", $strCombo3)
If @error == 1 Then
FileWriteLine($file,"Error: Input Image ComboBox Set String Fail")
Else
FileWriteLine($file,"Input Image ComboBox Set String Pass")
EndIf
ControlClick($winThresh,"","ComboBox3")
sleep($iSleepTime)

ControlCommand($winThresh,"","ComboBox4","ShowDropDown", "")
if @error == 1 Then
FileWriteLine($file,"Error: Output Image ComboBox ShowDropDown Fail")
Else
FileWriteLine($file,"Output Image ComboBox ShowDropDown Pass")
EndIf
ControlCommand($winThresh, "", "ComboBox4", "SelectString", 'NewImage')
If @error == 1 Then
FileWriteLine($file,"Error: Output Image ComboBox Set String Fail")
Else
FileWriteLine($file,"Output Image ComboBox Set String Pass")
EndIf
if($iType == 1 Or $iType == 2) Then
Local $setText = ControlSetText($winThresh,"","Edit3",$strThreshConst)
if ($setText == 0) Then
FileWriteLine($file,"Error: Set Threshold value Fail")
Else
FileWriteLine($file,"Set Threshold value Success")
EndIf
EndIf

sleep($iSleepTime)
ControlClick($winThresh,"","ComboBox4")
sleep($iSleepTime)

Local $strClickOk = ControlClick($winThresh,"","Button7")
if($strClickOk == 1) Then
FileWriteLine($file,"Click OK Sucesss")
Local $iGetBimodalText = ControlGetText($winThresh,"","Edit4")
if @error == 1 Then
FileWriteLine($file,"Error: Edit4 Control get text for bimodal threshold Fail")
Else
FileWriteLine($file,"Edit4: ControlGetText Pass")
EndIf
Else
FileWriteLine($file,"Error: Click Ok Fail")
EndIf
sleep($iSleepTime)

Local $warnOut = WinExists("ss","Please select an input image.")
if $warnOut == 1 Then
FileWriteLine($file,"Warning: Select An Input Image")
Local $warnOK = ControlClick("ss","Please select an input image.","Button1")
if $warnOK == 1 Then
FileWriteLine($file,"Click Ok: Success")
Sleep($iSleepTime)
ControlClick($winThresh,"","Button8")
Sleep($iSleepTime)
;MouseClick("Left",$iXCord,$iYCord,1)
WinClose($iHandle1)
Else
FileWriteLine($file,"Warning: Click OK Fail")
EndIf
$iReset = 0
EndIf

Local $warnOut = WinExists("ss","Please select an output image window.")
if $warnOut == 1 Then
FileWriteLine($file,"Warning: Select An Output Image")
Local $warnOK = ControlClick("ss","Please select an output image window.","Button1")
if $warnOK == 1 Then
FileWriteLine($file,"Click Ok: Success")
Sleep($iSleepTime)
ControlClick($winThresh,"","Button8")
Sleep($iSleepTime)
;MouseClick("Left",$iXCord,$iYCord,1)
WinClose($iHandle1)
Else
FileWriteLine($file,"Warning: Click OK Fail")
EndIf
$iReset = 0
EndIf

ControlClick($winThresh,"","Button8")

if($iReset == 1) Then
;ControlClick($winsa,"",59398,"left",1,73,47)
;sleep($iSleepTime)
;ControlClick($winsa,"",59398,"left",1,162,86)
ControlClick("ss","",59398,"left",1,$iXClickFile,$iYClickFile)
ControlClick("ss","",59398,"left",1,$iXClickSaveAs,$iYClickSaveAs)
sleep($iSleepTime)
Local $winSaveAs = WinWaitActive("Save As","")
if($WinSaveAs == 0) Then
FileWriteLine($file,"Error: File->SaveAs Window Not Active")
Else
if($iType == 0) Then
$strType = '_'&$iGetBimodalText&'_Bimodal.bmp'
Elseif($iType == 1) Then
$strType = '_'&$strThreshConst&'_Lower.bmp'
Elseif($iType == 2) Then
$strType = '_'&$strThreshConst&'_Upper.bmp'
EndIf

FileWriteLine($file,"File->SaveAs Window is Active")
$str31 = $strOut&$strType
$strSaveFile = $str31
Local $strSave = ControlSetText($winSaveAs,"","Edit1",$strSaveFile)
if($strSave == 0) Then
FileWriteLine($file,"Error: SaveAs->ImagePath Set Text Fail")
Else
FileWriteLine($file,"SaveAs->ImagePath Set Text Pass")
ControlClick($winSaveAs,"","Button1") ;Button2 for WinXP
if @error == 1 Then
FileWriteLine($file,"Error: Click On Save Fail")
Else
FileWriteLine($file,"Click On Save Pass")
FileWriteLine($file,"Save Image Success")

sleep($iSleepTime)
Local $var3 = ControlGetText( "[ACTIVE]","", "[ID:65280]" )
$process2 = 'Output Image: '&$var3
FileWriteLine($file,$process2)

Global $iHandle3 = ControlGetHandle("[ACTIVE]","","[ID:65280]")
if(@error == 1) Then
FileWriteLine($file,"Cannot Get Handle")
Else
WinClose($iHandle3)
Sleep($iSleepTime)
ControlClick($winThresh,"","Button8")
Sleep($iSleepTime)
WinClose($iHandle1)
EndIf
EndIf
EndIf
EndIf
EndIf
;Sleep($iSleepTime*2)s
;MouseClick("Left",$iXCord,$iYCord,1)
;Sleep($iSleepTime)
;ControlClick($winThresh,"","Button8")
;Sleep($iSleepTime)
;MouseClick("Left",$iXCord,$iYCord,1)
EndIf
EndFunc

Edited by Melba23
Added [autoit] tags

Share this post


Link to post
Share on other sites
water

You need to do more error checking. After you called an AutoIt function check if the return value, @error and @extended or OK or denote an error.

Example:

$iPID = Run("..:")
If $iPID = 0 or @error <> 0 Then Exit MsgBox(16, "Error", "Run returned error " & @error)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
sonali

Its not particular that where it stops. It stops randomly.but application will be active.

Share this post


Link to post
Share on other sites
water

The above code is just an example ;)

AutoItSetOption("TrayIconDebug", 1)
will show you where the Autoit script stopped. Then you need to add code to let your script handle the error condition. Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
careca

The above code is just an example ;)

AutoItSetOption("TrayIconDebug", 1)
will show you where the Autoit script stopped. Then you need to add code to let your script handle the error condition.

If im not wrong, i think with the use of it you are able to hover the mouse over the tray icon and it'll show the line it is sitting in and it's code.

Spoiler

Paster - Main function is to paste text, but has more functions. (No longer mantained, switched to String Trigger)

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites
water

You are not wrong ;)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×