Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

AutoIt Script for automation testing is not working

$
0
0
I have written an script in autoit to automate a windows based application and it works some times properly and same script stops randomly sometimes please help me
working enviornement is windows XP and application which has to be automated is windows based application

#include "InputHeader_BMP.au3"

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

Global $strConst = '10'
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 14 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
#cs
Local $strActive = WinActive("WinApp", "Ready")
if @error == 0 Then
Winclose("WinApp")
EndIf
#ce
Func Main($strInpPath,$strImgName,$strOutPath,$iOperation)
Local $reset = 0;
Local $reset1 = 0;
Local $a = WinWaitActive("WinApp", "Ready")
if $a == 0 Then
FileWriteLine($file,"Run-WinApp.exe: Unable to Open WinApp")
FileWriteLine($file," ")
Else
FileWriteLine($file,"Run-WinApp.exe: Application is running")
FileWriteLine($file," ")
If($iOperation == 0) Then
FileWriteLine($file,":::::::::::::ARITHMETIC ADDITION:::::::::::::")
ElseIf($iOperation == 1) Then
FileWriteLine($file,":::::::::::::ARITHMETIC SUBTRACTION:::::::::::::")
Elseif($iOperation == 2) Then
FileWriteLine($file,":::::::::::::ARITHMETIC MULTIPLICATION:::::::::::::")
ElseIf($iOperation == 3) Then
FileWriteLine($file,":::::::::::::ARITHMETIC DIVISION:::::::::::::")
ElseIf($iOperation == 4) Then
FileWriteLine($file,":::::::::::::ROTATE LEFT:::::::::::::")
ElseIf($iOperation == 5) Then
FileWriteLine($file,":::::::::::::ROTATE RIGHT:::::::::::::")
ElseIf($iOperation == 6) Then
FileWriteLine($file,":::::::::::::SHIFT LEFT:::::::::::::")
ElseIf($iOperation == 7) Then
FileWriteLine($file,":::::::::::::SHIFT RIGHT:::::::::::::")
ElseIf($iOperation == 8) Then
FileWriteLine($file,":::::::::::::LESS THAN:::::::::::::")
ElseIf($iOperation == 9) Then
FileWriteLine($file,":::::::::::::LESS THAN AND EQUAL TO:::::::::::::")
ElseIf($iOperation == 10) Then
FileWriteLine($file,":::::::::::::EQUAL TO:::::::::::::")
ElseIf($iOperation == 11) Then
FileWriteLine($file,":::::::::::::NOT EQUAL TO:::::::::::::")
ElseIf($iOperation == 12) Then
FileWriteLine($file,":::::::::::::GREATER THAN:::::::::::::")
ElseIf($iOperation == 13) Then
FileWriteLine($file,":::::::::::::GREATER THAN EQUAL TO:::::::::::::")
ElseIf($iOperation == 14) Then
FileWriteLine($file,":::::::::::::COMPUTE MAXIMUM:::::::::::::")
ElseIf($iOperation == 15) Then
FileWriteLine($file,":::::::::::::COMPUTE MINIMUM:::::::::::::")
EndIf

For $i = 1 to 1 Step 1
Local $str1 = String($i)
;Local $str2 = '1K_Image'
Local $str2 = $strImgName
Local $str3 = $str2&$str1
Local $str4 = '.bmp'
Local $str5 = $str3&$str4

ControlClick("WinApp","",59398,"left",1,$iXClickFile,$iYClickFile)
sleep($iSleepTime)
ControlClick("WinApp","",59398,"left",1,$iXClickOpen,$iYClickOpen)
Local $a1 = WinWaitActive("Open","")
if $a1 == 0 Then
FileWriteLine($file, "Control-Open:   Open Image button Fail")
Else
FileWriteLine($file, "Control-Open:   Open Image button Success")
sleep($iSleepTime)
Local $str6 = $strInpPath&$str5
;$strOpenHandle = WinGetHandle("Open")
sleep($iSleepTime)
Local $strOpenIm1 = ControlSetText("Open", "","Edit1",$str6)
;FileWriteLine($file,$str6)
if($strOpenIm1 == 0) Then
FileWriteLine($file,"Error: Set Image Path Fail")
sleep($iSleepTime)
Send("{ESC}")
Elseif($strOpenIm1 == 1) Then
  FileWriteLine($file,"Set Image1 Path Success")
send("{Enter}")
sleep($iSleepTime)
Local $str7 = 'Warning:  '&$str5&' is already open'
Local $str8 = $str5&' is ready for the process'
Local $a2 = WinExists("WinApp","This Window is already open")
if $a2 == 1 Then
FileWriteLine($file,$str7)
send("{Enter}")
$reset = 0
ElseIf $a2 == 0 Then
;FileWriteLine($file,$str8)
$reset = 1
EndIf
Local $a11 = WinExists("WinApp","Unable to load the image.")
if $a11 == 1 Then
FileWriteLine($file,"Error: Unable to Load Image")
send("{ENTER}")
$reset1 = 0
Else
$reset1 = 1
EndIf
if(($reset == 1) AND($reset1 == 1)) Then
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
ControlHide("[Active]","","[ID:65280]")
ArithmeticOperation($str3,$strOutPath,$iOperation)
EndIf
EndIf
FileWriteLine($file,"")
EndIf
EndIf
Winclose($iHandle1)
;MouseClick("Left",731,168,1)
Next
EndIf
EndFunc

Func ArithmeticOperation($str3,$strOutPath,$iType)
Local $strOut =  $strOutputImgPath&$strOutPath&$str3
Local $reset = 1
ControlClick("WinApp","",59398,"left",1,$iXClickOperation,$iYClickOperation)
ControlClick("WinApp","",59398,"left",1,$iXClickArithmetic,$iYClickArithmetic)
sleep(500)
Local $winArithmetic = WinGetHandle("WinApp","Arithmetic Operations")
If @error Then
FileWriteLine($file, "Arithmetic Operations Menu Not Available")
Else
$strCombo3 = $str3&'.bmp'
ControlCommand($winArithmetic, "", "ComboBox2", "SetCurrentSelection", $iType)
if @error == 1 Then
FileWriteLine($file,'Error: ComboBox2 Fail')
Else
FileWriteLine($file,'ComboBox2: Select Add Success')
EndIf

Sleep($iSleepTime)
ControlCommand($winArithmetic,"", "ComboBox3", "ShowDropDown", "")
sleep($iSleepTime)
;ControlCommand($winArithmetic,"", "ComboBox3",  "SetCurrentSelection", 0)
ControlCommand($winArithmetic, "", "ComboBox3", "SelectString", $strCombo3)
If @error == 1 Then
FileWriteLine($file, 'Error: ComboBox3 Fail')
Else
FileWriteLine($file, 'ComboBox3: Select Image1 Success')
ControlClick($winArithmetic,"","ComboBox3")
;sleep($iSleepTime)
EndIf


Local $strbuttoncheck =  ControlCommand($winArithmetic,"","Button11","IsChecked", "")
if ($strbuttoncheck == 1) Then
FileWriteLine($file, "Check Box is already checked")
Local $setText = ControlSetText($winArithmetic,"","Edit1",$strConst)
if ($setText == 0) Then
FileWriteLine($file,"Error: Set Constant value Fail")
Else
FileWriteLine($file,"Set Constant Value Success")
EndIf
Else
ControlCommand($winArithmetic,"", "Button11", "Check", "")
sleep($iSleepTime)
if (@error == 1)Then
FileWriteLine($file,"Error: Check Button Fail")
Else
FileWriteLine($file,"Check Buttton Pass")
Local $setText = ControlSetText($winArithmetic,"","Edit1",$strConst)
if ($setText == 0) Then
FileWriteLine($file,"Error: Set Constant value Fail")
Else
FileWriteLine($file,"Set Constant Value Success")
EndIf
EndIf
EndIf

ControlCommand($winArithmetic,"", "ComboBox5", "ShowDropDown", "")
sleep($iSleepTime)
ControlCommand($winArithmetic,"", "ComboBox5","SelectString", 'NewImage')
If @error == 1 Then
FileWriteLine($file, 'Error: ComboBox5 Fail')
Else
FileWriteLine($file, 'ComboBox5: Select OutputImage Success')
ControlClick($winArithmetic,"","ComboBox5")
sleep($iSleepTime)
EndIf


Local $strOk = ControlClick($winArithmetic,"","Button7")
If $strOk == 0 Then
FileWriteLine($file, 'Error: Click Button7 Fail')
Else
FileWriteLine($file, 'Button7: Click OK Success')
sleep($iSleepTime)
Local $strWarnOut = WinExists("WinApp","Please select input image.")
if ($strWarnOut == 1) Then
FileWriteLine($file,"Warning: Select Input Image")
;send("{ENTER}")
ControlClick("WinApp","","Button1")
sleep($iSleepTime)
ControlClick($winArithmetic,"","Button6")
sleep($iSleepTime)
WinClose($iHandle1)
;MouseClick("Left",731,168,1)
;sleep($iSleepTime)
$reset = 0
EndIf

Local $strWarnOut1 = WinExists("WinApp", "Please select output.")
if ($strWarnOut1 == 1) Then
FileWriteLine($file,"Warning: Select Output Image")
ControlClick("WinApp","","Button1")
;send("{ENTER}")
sleep($iSleepTime)
ControlClick($winArithmetic,"","Button6")
sleep($iSleepTime)
WinClose($iHandle1)
;MouseClick("Left",731,168,1)
;sleep($iSleepTime)
$reset = 0
EndIf

Local $strWarnOut2 = Winexists("WinApp","Operation failed")
if($strWarnOut2 == 1) Then
FileWriteLine($file,"Error: Operation Failed")
ControlClick("WinApp","","Button1")
;send("{ENTER}")
sleep($iSleepTime)
ControlClick($winArithmetic,"","Button6")
sleep($iSleepTime)
WinClose($iHandle1)
;MouseClick("Left",731,168,1)
;sleep($iSleepTime)
$reset = 0
EndIf

Local $strWarnOut3 = WinExists("WinApp","Provide a valid Constant Value. Valid Range is 0-65536.")
if($strWarnOut3 == 1) Then
FileWriteLine($file,"Warning: Enter a Valid Constant")
;send("{ENTER}")
ControlClick("WinApp","","Button1")
sleep($iSleepTime)
ControlClick($winArithmetic,"","Button6")
sleep($iSleepTime)
WinClose($iHandle1)
$reset = 0
EndIf
Local $strWarnOut4 = WinExists("WinApp","Provide a valid Constant Value. Valid Range is 0.0 - 255.0")
if($strWarnOut4 == 1) Then
FileWriteLine($file,"Warning: Enter a Valid Constant")
;send("{ENTER}")
ControlClick("WinApp","","Button1")
sleep($iSleepTime)
ControlClick($winArithmetic,"","Button6")
sleep($iSleepTime)
WinClose($iHandle1)
$reset = 0
EndIf

ControlClick($winArithmetic,"","Button6")
sleep($iSleepTime)
If $reset == 1 Then
Sleep($iSleepTime)
ControlClick("WinApp","",59398,"left",1,$iXClickFile,$iYClickFile)
sleep($iSleepTime)
ControlClick("WinApp","",59398,"left",1,$iXClickSaveAs,$iYClickSaveAs)
sleep($iSleepTime)
Local $winSaveAs = WinWaitActive("Save As","")
if $winSaveAs == 0 Then
FileWriteLine($file, "Control-SaveAs: Cannot Open Save Window")
Else
FileWriteLine($file, "Control-SaveAs: Open Save Window ")
if($iType == 0) Then
$strType = '_Add.bmp'
Elseif ($iType == 1) Then
$strType = '_Sub.bmp'
Elseif ($iType == 2) Then
$strType = '_Mul.bmp'
Elseif ($iType == 3) Then
$strType = '_Div.bmp'
Elseif ($iType == 4) Then
$strType = '_RotateLeft.bmp'
Elseif ($iType == 5) Then
$strType = '_RotateRight.bmp'
Elseif ($iType == 6) Then
$strType = '_ShiftLeft.bmp'
Elseif ($iType == 7) Then
$strType = '_ShiftRight.bmp'
Elseif ($iType == 8) Then
$strType = '_LessThan.bmp'
Elseif ($iType == 9) Then
$strType = '_LessThanEqualTo.bmp'
Elseif ($iType == 10) Then
$strType = '_EqualTo.bmp'
Elseif ($iType == 11) Then
$strType = '_NotEqualTo.bmp'
Elseif ($iType == 12) Then
$strType = '_GreaterThan.bmp'
Elseif ($iType == 13) Then
$strType = '_GreaterThanEqualto.bmp'
Elseif ($iType == 14) Then
$strType = '_ComputeMaximum.bmp'
Elseif ($iType == 15) Then
$strType = '_ComputeMinimum.bmp'
EndIf
;$strSave = $str3&'_const_'&$strConst&$strType
$strSave = $strOut&'_const_'&$strConst&$strType
;$strSavePath = $strOutPath&$strSave
$strSavePath = $strSave
Local $strSave = ControlSetText("Save As", "","Edit1",$strSavePath)
if ($strSave == 0) Then
FileWriteLine($file, 'Error:SaveAs Fail-Cannot Save Image')
Else
FileWriteLine($file, 'Save Image success')

sleep($iSleepTime)
ControlClick($winSaveAs,"","Button2")
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($winArithmetic,"","Button8")
Sleep($iSleepTime)
WinClose($iHandle1)
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndFunc

Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>