Friday, November 20, 2009

Extending Test Complete Trial License

Delete the "regkey.dat" file on your machine. The file should be located in the following folder:

"C:\ProgramData\AutomatedQA\TestComplete\7.0" (for Windows Vista, Windows Server 2008)

"C:\Documents and Settings\All Users\Application Data\AutomatedQA\TestComplete\7.0" (for any other version of Windows


9876EDDA-9DE430BF-5BA4BEE1-6B84F60B-7BC395CD-D04A8A89-9509

TestComplete: Random Function

function Random(min,max)

Randomize()
Random =Int ((max-min+1)*rnd+min)

end Function

Accessing Grid Cell value

Property used to access grid cell value :

grid.wValue(rowindex,colindex)

Wednesday, November 18, 2009

VB Script and excel playing aroubd...

// Following code will read and write in an excel file.


Set objXL = CreateObject("Excel.Application")
Set objWB = objXL.WorkBooks.Open("C:\Documents and Settings\nsharma\Desktop\VB scripts\test1.xls")
Set objWS = objXL.ActiveWorkBook.WorkSheets("Sheet1")
Dim CellArray()
ACount = 0
For i = 1 To 10
If objXL.Cells(i, 8).Value = "" Then
CellValue = "Empty"
objXL.Cells(i, 9).Value="Pass"
Else
CellValue = objXL.Cells(i, 8).Value
End If
ReDim preserve CellArray(ACount)
CellArray(ACount) = CellValue
msgbox(cellvalue)
ACount = ACount + 1
Next
objWB.Close
objXL.Quit

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

counter=1

While Not blnDone

Wait (2)

blnDone=Window("FlightReservation").Dialog("FlightsTable").Exist counter=counter+1

If counter=10 then

blnDone=True

End if

Wend

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."

or

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 India"

val2="India"

val=InStr(1,val1,val2)

val will have value 12 . This means that the position of the word India in val1 is 12.

Split: Returns a zero-based, one-dimensional

array containing a specified number of substrings with respect to delimiter.

Usage:

Val=”appleXballXcatXdog”

Sval=Split(val,”X”,-1)

Now Sval(0) will have apple

Sval(1)=ball

Sval(2)=cat.

That is Split command will split the string based upon the delimiter specified.

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.