Monday, April 26

Simple VB Script that interacts with QTP and excel

'HI..here in this tutorial we gone try how to create a VB script which
' launches qtp and open the test which you have specified in the excel


'First we shall create a constant that points to the excel where it is located
' in local drive





Const Data_file = "C\O2C\QTPTrial\Imp Scripts\ScriptsforDemo.xlsx"
'Next define the columns and sheets

' Our sheet name is Scripts and 1st and second column hold the name
'and path of the script



Const Sheet_name = "Scripts"
Const Starting_row = 1
Const Name_column = 1

Const Path_column = 2

'After this we need to create objects using create object method
'for excel and qtp. Create object method is one of scripting runtime
'objects from VB scripting components



Dim appQTP
Dim appExcel






Set appQTP = CreateObject("QuickTest.Application")' here creating QTP
Set appExcel = CreateObject("Excel.Application")'excel application



'Next we will have few lines of code which will check if whether qtp is
'open if not, then open it
if appQTP.launched <> True then
      appQTP.launch
      if err.number <> 0 then
      wscript.echo " QTP did not launch"
end if

end if

' Next Open the data excel file
Dim ObjDataSheet
set ObjDataSheet = appExcel.workbooks.open(Data_file,,False)
ObjDatasheet.worksheets(Sheet_name).activate 'Activating the sheet"Scripts"

'We next after this shall read the excel for path and scriptname

scriptname = appexcel.cells(Starting_row,Name_column).value
scriptpath = appexcel.cells(Starting_row,path_colums).value

' Till now we have done 90% of the job. next is the final step where
'you a will call step to open the test.

appQTP.open scriptpath & scriptname, true 'true to open in readonly mode, false for write mode
wscript.echo "QTP Script has been opened"

' Thats my friends. here was the simple tutorial showing how to script
'to open QTP file

No comments:

Post a Comment

---------------------------------------------

Related Posts Plugin for WordPress, Blogger...