Sign in to follow this  
Followers 0
Guest BigMike

On Error Goto:?

4 posts in this topic

I just downloaded and installed the AutoIT3 on Tuesday and I am having some problems I am hoping some of you can help me with.

I am writing a script to automate testing of applications. here is what I have so far.

$file="c:\test.txt"
FileDelete ( $file)

$DebugText=("Script Start      " & @HOUR &":"& @MIN & ":" & @SEC & "  Day  " & @MON & "/" & @MDAY & "/" & @YEAR)
RecLog($DebugText)

;  BEGIN TESTING MS-WORD
$errMSWORD = ("Error with MS-Word")
run ("C:\Program Files\Microsoft Office\Office10\winword.exe")
if WinWaitActive ("Document1", "", 10)=0 Then FileWriteLine($file, $errMSWORD)
Send ("Testing Script for Microsoft Word XP...^s")
WinMenuSelectItem("Document1","", "&File", "Save &As...")
if WinWaitActive ("Save As", "", 10)=0 Then FileWriteLine($file, $errMSWORD)
send ("{DELETE}")
send ("c:\Testing.doc!S")
if winwaitactive ("Testing.doc", "", 10)=0 Then FileWriteLine($file, $errMSWORD)
WinClose ("Testing.doc")
send ("{Lwin}R")
if winwaitactive ("Run", "", 10)=0 Then FileWriteLine($file, $errMSWORD)
send ("{DELETE}c:\Testing.doc{ENTER}")
if winwaitactive ("Testing.doc", "", 10)=0 Then FileWriteLine($file, $errMSWORD)
WinClose ("Testing.doc")
FileRecycle ("c:\Testing.doc")
$DebugText=("MS-WORD Test Passed:    " & @HOUR &":"& @MIN & ":" & @SEC & "  Day  " & @MON & "/" & @MDAY & "/" & @YEAR)
RecLog($DebugText)


;  BEGIN TESTING MS-EXCEL
$errMSEXCEL = ("Error with MS-Excel")
run ("C:\Program Files\Microsoft Office\Office10\excel.exe")
if winwaitactive ("Microsoft Excel - Book1", "", 10)=0 Then FileWriteLine($file, $errMSEXCEL)
Send ("Testing Excel^s")
if winwaitactive ("Save As", "", 10)=0 Then FileWriteLine($file, $errMSEXCEL)
send ("{DELETE}")
send ("c:\Testing.xls!S")
if winwaitactive ("Microsoft Excel - Testing.xls", "", 10)=0 Then FileWriteLine($file, $errMSEXCEL)
WinClose ("Microsoft Excel - Testing.xls")
send ("{Lwin}R")
if winwaitactive ("Run", "", 10)=0 Then FileWriteLine($file, $errMSEXCEL)
send ("{DELETE}c:\Testing.xls{ENTER}")
if winwaitactive ("Microsoft Excel - Testing.xls", "", 10)=0 Then FileWriteLine($file, $errMSEXCEL)
WinClose ("Microsoft Excel - Testing.xls")
FileRecycle ("c:\testing.xls")
$DebugText=("MS-EXCEL Test Passed:    " & @HOUR &":"& @MIN & ":" & @SEC & "  Day  " & @MON & "/" & @MDAY & "/" & @YEAR)
RecLog($DebugText)

;Write End of Script time stamp
$DebugText=("Script End        " & @HOUR &":"& @MIN & ":" & @SEC & "  Day  " & @MON & "/" & @MDAY & "/" & @YEAR)
RecLog($DebugText)

Func RecLog($DebugText)
    FileWriteLine($file, $DebugText)

EXIT

I still have about 30 more programs to put in there for testing and what I need help with is that if any of the areas of a program fails, I want to write the error message to the txt file and then skip right to the next program on the list. I can't figure out how to Skip, I would use the GoTo if I was writing a batch file.

also if anyone has a better idea on how I have the error messaging I would appreciate that.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

this could be one option .. just took the WORD portion and coded with some IF so it only continues to the next test when the current test went ok :

$FILE="c:\test.txt"
FileDelete( $FILE)

$DebugText=("Script Start      " & @HOUR &":"& @MIN & ":" & @SEC & "  Day  " & @MON & "/" & @MDAY & "/" & @YEAR)
RecLog($DEBUGTEXT)

;  BEGIN TESTING MS-WORD
$MSG =("Error with MS-Word")
Run("C:\Program Files\Microsoft Office\Office10\winword.exe")
If WinWaitActive("Document1", "", 10)Then 
   Send("Testing Script for Microsoft Word XP...^s")
   WinMenuSelectItem("Document1","", "&File", "Save &As...")
   If WinWaitActive("Save As", "", 10) Then 
      Send("{DELETE}")
      Send("c:\Testing.doc!S")
      If WinWaitActive("Testing.doc", "", 10) Then 
         WinClose("Testing.doc")
         Send("{Lwin}R")
         If WinWaitActive("Run", "", 10) Then 
            Send("{DELETE}c:\Testing.doc{ENTER}")
            If WinWaitActive("Testing.doc", "", 10) Then 
               WinClose("Testing.doc")
               FileRecycle("c:\Testing.doc")
               $msg=("MS-WORD Test Passed:    " & @HOUR &":"& @MIN & ":" & @SEC & "  Day  " & @MON & "/" & @MDAY & "/" & @YEAR)
            EndIf
         EndIf
      EndIf
   EndIf
EndIf
RecLog($MSG)

Func RecLog($DEBUGTEXT)
   FileWriteLine($FILE, $DEBUGTEXT)
EndFunc  ;==>RecLog
Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Basically just set up some while type loops use exitloop to go to the next part.

Terminate a While/Do/For loop.

ExitLoop [level]Parameters

level [optional] The number of levels of loop to break out of. The default is 1 (meaning the current loop).

You might also consider making a function to write the log file and then set a variable to show it was done:

if @error=1 then logme("this part failed")
;......

func logme($_line)
FileWriteLine("logfile.txt", @YDay&" "&$_line)
$log="yes"
endfunc

AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

i don't think WORD uses a standard Menu... so

WinMenuSelectItem("Document1","", "&File", "Save &As...")

will fail

Run AU3_Spy and hover over the Menu and you will see that it has a control name. Try controlsend of "fa" to that control name.

Lar.

None of Microsoft's "big-name" products use standard controls. Visual Studio doesn't, all of Office has its own set of controls defined. Basically the general rule is: If Microsoft made it, it probably doesn't use standard Microsoft controls.

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