Sign in to follow this  
Followers 0
sonali

AutoIt Script for automation testing is not working

11 posts in this topic

#1 ·  Posted (edited)

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
Edited by Melba23
Added tags

Share this post


Link to post
Share on other sites



Add

AutoItSetOption("TrayIconDebug", 1)
at the top of your script. If you hover of the tray icon you see the currently executed statement.

BTW: If posting code, please wrap it in [autoit][/autoit] tags. Makes reading much easier.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - 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

Thanks and sorry for that posting method i am very new to autoit

Share this post


Link to post
Share on other sites

Hi,

i tried with AutoItSetOption("TrayIconDebug", 1)

Nothing really working its again halting and its because of winwaitactive in script any suggestion to replace that.

Share this post


Link to post
Share on other sites

Do you know which of the WinWaitActive statements halts the script?

If yes, write the title to the Console or use MsgBox to display the title of the window. Maybe there is a mismatch.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - 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

I tried that also.its the exact match of title the problem is it stops only for 1 or 2 images rest it works fine.so can u please suggest some other thing which i can replace "winwaitactive" and i cant make it "winsetontop" as i have to wait til the image is being loaded and it takes different time for different images

the image which it has run properly might have stopped next time.

Its not for same image which it is stopping.

in same script it runs some time n sometime it doesn't.

please suggest me something to make it work

Share this post


Link to post
Share on other sites

For WinWaitActive to return True the window has to exist and be active (has the focus).

You could try to replace

Local $a = WinWaitActive("WinApp", "Ready")
Local $hWindow = WinWait("WinApp", "Ready")
WiNActivate($hWindow)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - 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

Hi,

It was stopping randomly when i used Local $a = WinWaitActive("WinApp", "Ready")

After using this code below its stopping everytime please suggest something

Local $hWindow = WinWait("WinApp", "Ready")

WiNActivate($hWindow)

Share this post


Link to post
Share on other sites

Does it stop at the WinWait or WinActivate statement?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - 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

winwait it stops

Share this post


Link to post
Share on other sites

Then there is no window with the specified title and text.

Maybe the title doesn't start with the specified text ("WinAPpp").

Set

AutoItSetOption("WinTitleMatchMode", 2)
at the top of your script so the the text matches any substring in the title.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - 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  
Followers 0