Wednesday 27 November 2013

Calling multipe QTP scripts using VB file:

Well, Sometimes there comes a situation where we have to call multiple test files at a glance.
It would be cumbersome to call/open test one by one and run. Yet there are many alternative methods to achieve the same, but i love the way using array collection.
To make fully automated code/script you could even write a function to call all the tests from your test folder into the array collection dynamically and then executing the following code.Here, although, i have manually inserted every test into the array.

Function LoadNrun()
arrColl = Array(“C:\filename1″, “C:\filename2″,”C:\filename3″)
For each arrTest in arrColl
qtApp.Open arrTest
set qtTest = qtApp.Test
set objResultsOptions = CreateObject(“QuickTest.RunResultsOptions”) objResultsOptions.ResultsLocation = arrTest & “\Res1″ qtTest.Run objResultsOptions qtTest.Close
Next
End Function




*************************************************
How to close QTP Application through Code/Script/Descriptive Programming?
*************************************************

Close QTP Application:
Well,Question is simple but answer is little bit  complex. Here you need to search the desired application process on Win32_Process list.Microsoft MSDN has a good source of information on this topic. I am going to show the code without giving much explanation; Hope the code itself serves as a source of explanation
Please have a quick look on the above topic:
The Win32_Process:Win32 classes, such as Win32_NetworkAdapter or Win32_Process, monitor and manage system hardware and features. Generally, these classes are located in the root\cimv2 WMI namespace. The following table lists the Win32 class categories.WMI class represents a process on an operating system.
Source: http://msdn.microsoft.com/en-us/library/aa394084(v=VS.85).aspx

Code:
Function ClosemyApp()
Dim iCount iCount=0
Set oMyobj=GetObject(“winmgmts:\\.\root\CIMV2″)Set sCollectedProcess=oMyobj.ExecQuery(“select * from Win32_Process
where name=’QTPro.exe’ “)
For each iCount in sCollectedProcess iCount.Terminate()Next
Set sCollectedProcess=NothingSet oMyobj=Nothingmsgbox “Hurray!”
End Function


No comments:

Post a Comment