July 15, 2010

Running Automated Testing Scripts On Your Schedule

Helix ALM
QA Wizard Pro scripts can be run unattended by saving them as batch script files and using the Windows Task Scheduler to launch them at a scheduled time. The Scheduled Task Wizard gives you the option of running the script once at a specified time, or on a daily, weekly or monthly basis. But what do you do if that doesn’t fit your schedule? Perhaps you would like to monitor a web site and ensure it is up and running by logging in once every hour. To set this up for a twenty-four hour period, you would need to schedule 24 separate tasks to run at a specified time – a time-consuming task in itself. If the launch time changes, you would need to go back and modify each of those tasks individually. A better idea is to create another QA Wizard Pro script that allows you to launch the batch script file at a time interval you choose, as well as capture additional information such as total number of times the batch script was run or the number of times the login test failed. Your “Main” script can use the Run Command statement to launch a QA Wizard Pro batch script file from the DOS command line. Since Run Command returns a ‘0’ if successful and a ‘1’ for anything else, you can use it in a conditional statement to track the number of times the login fails: if RunCommand(“C:\Monitor\Login.qawbatch", “C:\Monitor, "") > 0 then Println("Fail") ErrCount=ErrCount + 1 End if If your login script fails for any reason, that failure will be captured and counted. If you are using a checkpoint to verify success, for example making sure the correct welcome greeting appears, make sure to set the failure behavior to generate an error and stop the script. Since the batch script has been launched independently of the “Main” script, the error will not affect the “Main” script. To ensure that each launch of the login script will run cleanly, use the Run Command statement prior to the call to kill any hanging application processes (Internet Explorer browser in this case): RunCommand("C:\WINDOWS\system32\cmd.exe", "C:\WINDOWS\system32\", "/C"taskkill /F /IM iexplore.exe"") Since you will be running the script repeatedly, create a loop that will exit after a certain condition is met. The condition may be the script must run a certain number of times, or stop if the number of login failures is above an acceptable number. A While loop will allow you to keep checking a flag that will be set, and an If statement will perform the check: DONE=False ‘set initial value to False While DONE=False If ErrCount >= 3 then ‘Finished if three or more errors found DONE=True End if WEnd Finally, you can create an Interval variable to allow you to control how long between script executions. One way to do this is to translate the time into milliseconds (1 sec = 1000msec, 1 minute=60000 ms, etc) and use a Delay statement wait the specified amount of time. The Delay step should be right before the WEnd of the While loop: Delay(Interval) ‘Wait the specified amount of time Once you have your “Main” script set up, save it as a batch script file and use the Windows Task Scheduler to do the initial kickoff – QA Wizard Pro will take care of the rest!