Following VB script can be used to launch QTP.
1: Dim QTPObj
2: Dim QTPTest
3: Set QTPObj=CreateObject("QuickTest.Application")
4: If Not QTPObj.Launched then
5: QTPObj.Launch
6: End if
7: QTPObj.Visible=True
8: QTPObj.Open "Path of QTP script"
9: Set QTPTest=QTPObj.Test
10: QTPTest.Run
11: QTPTest.Close
12: QTPObj.Quit
Line by line Explanation:-
Line 1: Declare object for QTP
Line 2: Declare object for QTP test
Line 3: Create QTP object
Line 4: If condition to verify if QTP is running or not
Line 5: If QTP is not running, launch QTP session
Line 6: End of if statement
Line 7: Make QTp Visible. If thi sproperty is set to False, QTP qould be launched (at backend), but would not be visible to user.
Line 8: Open the QTP test to run by specifying the path
Line 9: Map the QTP test with object
Line 10: Run the QTP test
Line 11: Afterthe test is completed. close QTP
Line: Quitting the obect created.
Showing posts with label VBScript. Show all posts
Showing posts with label VBScript. Show all posts
Tuesday, April 26, 2011
Thursday, April 21, 2011
VBScript Code | Appending text to File
Write the below written QTP code inside a notepad and save it as a .vbs file. You can either run it from command prompt or run it by double-clicking on it.
VBScript Code - The following code appends a text to a file. If the file does not exist, it creates the file.
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set FSO = CreateObject("Scripting.FilesystemObject")
Set QTPfile = FSO.OpenTextFile("c:\myfile.txt", ForAppending, True)
QTPfile.WriteLine("Myfirst line of text.")
QTPfile.Close
VBScript Code - The following code appends a text to a file. If the file does not exist, it creates the file.
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set FSO = CreateObject("Scripting.FilesystemObject")
Set QTPfile = FSO.OpenTextFile("c:\myfile.txt", ForAppending, True)
QTPfile.WriteLine("Myfirst line of text.")
QTPfile.Close
VBScript Code | Reading all lines from File
Write the below written QTP code inside a notepad and save it as a .vbs file. You can either run it from command prompt or run it by double-clicking on it.
VBScript Code - The following code reads first line from a text file.
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set FSO = CreateObject("Scripting.FilesystemObject")
Set QTPfile = FSO.OpenTextFile("c:\myfile.txt", ForReading , False)
While not QTPfile.AtEndOfStream
a=QTPfile.ReadLine
Print a
Wend
VBScript Code | Reading text from File
Write the below written QTP code inside a notepad and save it as a .vbs file. You can either run it from command prompt or run it by double-clicking on it.
VBScript Code - The following code reads first line from a text file.
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set FSO = CreateObject("Scripting.FilesystemObject")
Set QTPfile = FSO.OpenTextFile("c:\myfile.txt", ForReading , False)
a=QTPfile.ReadLine
QTPfile.Close
Print a
VBScript Code | Writing text to File
Write the below written QTP code inside a notepad and save it as a .vbs file. You can either run it from command prompt or run it by double-clicking on it.
VBScript Code - The following code reads first line from a text file.
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set FSO = CreateObject("Scripting.FilesystemObject")
Set QTPfile = FSO.OpenTextFile("c:\myfile.txt", ForWriting, False)
QTPfile.WriteLine(" This is my demo text")
QTPfile.Close
Subscribe to:
Posts (Atom)