Friday, November 20, 2009
Extending Test Complete Trial License
TestComplete: Random Function
Randomize()
Random =Int ((max-min+1)*rnd+min)
end Function
Wednesday, November 18, 2009
VB Script and excel playing aroubd...
QTP’S test Object Functions:
Exist: You can enter Exist and/or Wait statements to instruct QuickTest to wait for a window to open or an object to appear. Exist statements return a boolean value indicating whether or not an object currently exists. Wait statements instruct QuickTest to wait a specified amount of time before proceeding to the next step. You can combine these statements within a loop to instruct QuickTest to wait until the object exists before continuing with the test.
Example:
blnDone=Window("Flight Reservation").Dialog("Flights Table").Exist
blnDone=Window("FlightReservation").Dialog("FlightsTable").Exist counter=counter+1
Check Property: Checks whether the specified object property achieves the specified value within the specified timeout.
Syntax: object.CheckProperty (PropertyName, PropertyValue, [TimeOut])
Example:
var_CheckProperty = Browser("HP QuickTest Professional").Page("HP QuickTest Professional").Link("1.2 License Models").CheckProperty("text", "Licence Models")
Return Value
A Boolean value. Returns TRUE if the property achieves the value, and FALSE if the timeout is reached before the property achieves the value.
A TRUE return value reports a Passed step to the test results; a FALSE return value reports a Failed step to the test results.
GetTOProperty: Returns the value of the specified property from the test object description.
Syntax: object.GetTOProperty (Property)
Example : var_GetTOProperty = Browser("HP QuickTest Professional").Page("HP QuickTest Professional").Link("1.2 License Models").GetTOProperty("Innertext")
Return Value: A variant value which will have the inner text of the link “1.2 License Models”
GetROProperty: Returns the current value of the test object property from the object in the application.
Syntax: object.GetROProperty (Property)
Example : var_GetTOProperty = Browser("HP QuickTest Professional").Page("HP QuickTest Professional").Link("1.2 License Models").GetROProperty("Innertext")
Return Value: A variant value which will have the current inner text value of the link “1.2 License Models”
ReportEvent : Reports an event to the test results
Syntax: Reporter.ReportEvent EventStatus, ReportStepName, Details [, Reporter]
Example:
Reporter.ReportEvent 1, "Custom Step", "The user-defined step failed."
Reporter.ReportEvent micFail, "Custom Step", "The user-defined step failed."
SystemUtil.Run : You can run any application from a specified location using a SystemUtil.Run statement
Example:SystemUtil.Run"C:\ProgramFiles\InternetExplorer\IEXPLORE.EXE","","C:\Documents and Settings\Administrator","open"
The statement opens the Internet Explorer.
ExecuteFile: This can be used to execute an external VB Script File
Syntax: ExecuteFile FileName
Example : ExecuteFile “C:\sample.vbs”
The above discussed functions can be easily Accessed by step Generator:
VB Script File handling
File handling:
Writing Values From a File:
Const ForReading = 1, ForWriting = 2
Dim fso, MyFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.OpenTextFile("c:\testfile.txt", ForWriting, True)
MyFile.WriteLine "Hello world!"
MyFile.WriteLine "The quick brown fox"
MyFile.Close
Reading Values from a File:
Const ForReading = 1, ForWriting = 2
Dim fso, MyFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.OpenTextFile("c:\testfile.txt", ForReading)
Val= MyFile.ReadLine
Val1=MyFile.ReadLine
MyFile.Close
Fetching Values from a Database using VBScript.
Set MyConn = CreateObject("ADODB.Connection")
MyConn.Open"Provider=Microsoft.Jet.OLEDB.4.0;DataSource=C:\Program”+_ "Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight32.mdb"
Set RS = MyConn.Execute("SELECT * FROM Orders")
While Not RS.EOF
msgbox RS("Order_Number").Value
Rs.MoveNext
Wend
VB Script In built Functions
Command: InputBox.
Displays a prompt in a dialog box, waits for the user to input text or click a button, and returns the contents of the text box.
Syntax: InputBox(“Enter your name”)
Command: MsgBox.
Displays a message in a dialog box, waits for the user to click a button, and returns a value indicating which button the user clicked.
Syntax: MsgBox(“Hello World”)
String Functions:
StrComp: Returns a value indicating the result of a string comparison.
Usage: A=Strcmp(“Hello”,”Hello”)
A will have value 0 which means true.
InStr: Returns the position of the first occurrence of one string within another
Usage: val1="welcome to
val2="
val=InStr(1,val1,val2)
val will have value 12 . This means that the position of the word
array containing a specified number of substrings with respect to delimiter.
Usage:
Val=”appleXballXcatXdog”
Sval=
Now Sval(0) will have apple
Sval(1)=ball
Sval(2)=cat.
That is
Date and Time Functions:
Now: Returns the current date and time according to the setting of your computer's system date and time.
Usage:
Dim MyVar
MyVar = Now ' MyVar contains the current date and time.
DateAddf: Returns the number of intervals between two dates
Usage:
DiffADate = "Days from today: " & DateDiff("d", Now,"2/7/2008" )
MsgBox DiffADate
DiffADate will have the no of days between today and "2/7/2008"
DateAdd: Returns a date to which a specified time interval has been added.
Usage:
NewDate = DateAdd("m", 1, "31-Jan-95")
The NewDate will be “28-Feb-95”. One month latter than “31-Jan-95”
Day(now): This will return todays day alone. Like 21, 15 or 12
Hour(now): This will retun the current hour alone.
