We can schedule the script execution during night time also.
Scheduling can be done easily using window task scheduler for starting the execution of QTP script automatically at a predefined time.
For doing scheduling, we need to create .vbs file.
The Important steps required for scheduling are,
- Create a Driver script which calls all the scripts one by one.
- Complete Dry run to make sure script will continue execution without any interruption. Add Recovery scenario for handling any unexpected pop-up window or any other inconsistent behavior of the application under test.
- Create a .vbs file which will be used for starting the QTP using Automation Object Model. Remember to add the code for keeping settings/options of the QTP so that the scheduler will open QTP with same settings.
you can refer the below sample vbscript code for creating the .vbs file to be called from the scheduler.
Dim qtApp 'As QuickTest.Application ' Declare the Application object variable
Dim qtTest 'As QuickTest.Test ' Declare a Test object variable
Dim qtResultsOpt 'As QuickTest.RunResultsOptions ' Declare a Run Results Options object variable
Set qtApp = CreateObject("QuickTest.Application") ' Create the Application object
qtApp.Launch ' Start QuickTest
qtApp.Visible = True
qtApp.Open "C:\Tests\Test1", True ' Open the test in read-only mode. Include your driver script here.
Set qtResultsOpt = CreateObject("QuickTest.RunResultsOptions") ' Create the Run Results Options object
qtResultsOpt.ResultsLocation = "C:\Tests\Test1\Res1" ' Set the results location
qtTest.Run qtResultsOpt ' Run the test
The complete code and details can be found in the QTP help file for Automation Object Model.
The next step is we should merge the code for QTP options/settings within this code.
The options/settings code can be easily generated automatically.
Click Tools->Options from QTP IDE to open the below screen.
Click "generate" in the above screen to automatically generate the code.
- Then add a task in windows scheduler for calling the .vbs file.
You can do it by using Schedule Task wizard from settings->control panel->Scheduled Tasks->Add Scheduled Task
Click "Browse" in the below screen of the wizard to set specify your .vbs file.
- Locking the system while running the script will affect the script running.So don't lock your machine while running the script. Anyway, you can add the below code at end of your .vbs file to lock the system automatically once after completing execution of the script.
eBook for learning Software Testing and QTP Automation.
Set obj = CreateObject("WScript.Shell")
sCmnd = "%windir%\SYSTEM32\rundll32.exe user32.dll,LockWorkStation"
obj.Run sCmnd, 0, False