How QuickTest Learns Objects While Recording

QuickTest learns objects just as you would. For example, suppose as part of an experiment, Johnny is told that he will be shown a photograph of a picnic scene for a few seconds during which someone will point out one item in the picture. Johnny is told that he will be expected to identify that item again in identical or similar pictures one week from today.

Before he is shown the photograph, Johnny begins preparing himself for the test by thinking about which characteristics he wants to learn about the item that the tester indicates. Obviously, he will automatically note whether it is a person, inanimate object, animal, or plant. Then, if it is a person, he will try to commit to memory the gender, skin color, and age. If it is an animal, he will try to remember the type of animal, its color, and so forth.

The tester shows the scene to Johnny and points out one of three children sitting on a picnic blanket. Johnny notes that it is a caucasian girl about 8 years old. In looking at the rest of the picture, however, he realizes that one of the other children in the picture could also fit that description. In addition to learning his planned list of characteristics, he also notes that the girl he is supposed to identify has long, brown hair.

Now that only one person in the picture fits the characteristics he learned, he is fairly sure that he will be able to identify the girl again, even if the scene the tester shows him next week is slightly different.

Since he still has a few moments left to look at the picture, he attempts to notice other, more subtle differences between the child he is supposed to remember and the others in the picture—just in case.

If the two similar children in the picture appeared to be identical twins, Johnny might also take note of some less permanent feature of the child, such as the child's position on the picnic blanket. That would enable him to identify the child if he were shown another picture in which the children were sitting on the blanket in the same order.

QuickTest uses a very similar method when it learns objects during the recording process.

First, it "looks" at the object on which you are recording and stores it as a test object, determining in which test object class it fits. Just as Johnny immediately checked whether the item was a person, animal, plant, or thing. QuickTest might classify the test object as a standard Windows dialog box (Dialog), a Web button (WebButton), or a Visual Basic scroll bar object (VbScrollBar), for example.

Then, for each test object class, QuickTest has a list of mandatory properties that it always learns; similar to the list of characteristics that Johnny planned to learn before seeing the picture. When you record on an object, QuickTest always learns these default property values, and then "looks" at the rest of the objects on the page, dialog box, or other parent object to check whether this description is enough to uniquely identify the object. If it is not, QuickTest adds assistive properties, one by one, to the description, until it has compiled a unique description; like when Johnny added the hair length and color characteristics to his list. If no assistive properties are available, or if those available are not sufficient to create a unique description, QuickTest adds a special ordinal identifier, such as the object's location on the page or in the source code, to create a unique description, just as Johnny would have remembered the child's position on the picnic blanket if two of the children in the picture had been identical twins.

Submitting Defects to Quality Center

When viewing the results of a run session, you can submit any defects detected to a Quality Center project directly from the Test Results window.

To manually submit a defect to Quality Center:

  1. Choose Tools > Quality Center Connection or click the Quality Center Connection button to connect to a Quality Center project. For more information on connecting to Quality Center, see Connecting to Your Quality Center Project.

Note: If you do not connect to a Quality Center project before proceeding to the next step, QuickTest prompts you to connect before continuing.

  1. Choose Tools > Add Defect or click the Add Defect button to open the Add Defect dialog box in the specified Quality Center project. The Add Defect dialog box opens.
  2. You can modify the defect information if required. Basic information about the component is included in the description
  3. Click Submit to add the defect information to the Quality Center project.
  4. Click Close to close the Add Defect dialog box.

Generating Random Strings in QTP

The following function generates random data using a format string that you can customize.

' VBScript source code

Randomize (timer)

' Declaration of all formats

' Note that a token contained within a second token (e.g. yy to yyyy) must be placed AFTER the containing token (yyyy must precede yy)

FormatArray = Array("#", "DAY", "MONTH", "dd", "mm", "yyyy", "yy", "NAME", "COLOR", "CAR")

' Definition of formats not appearing as a Case in GetRandStrForToken

Dim ValuesArray

ValuesArray = _

Array(_

Array("DAY", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"),_

Array("MONTH", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"),_

Array("COLOR", "Red", "Yellow", "Blue", "Green"),_

Array("NAME", "Hilik", "Oren", "Shoshi", "Ilan"),_

Array("CAR", "Ford", "Toyota", "Lexus", "Mazda")_

)

' Generate a random value for a specific token

Function GetRandStrForToken(sToken)

Select Case sToken

Case "#"' Single digit

GetRandStrForToken = CStr(Int(Rnd*10))

Case "dd"' May (numaric)

GetRandStrForToken = CStr (Int(Rnd*31 + 1))

Case "mm"' Month (numeric)

GetRandStrForToken = CStr (Int(Rnd*12 + 1))

Case "yy"' Two digit Year

GetRandStrForToken = CStr(Int(Rnd*10)) + CStr(Int(Rnd*10))

Case "yyyy"' Four digit Year

GetRandStrForToken = CStr (1950 + Int(Rnd * 100))

Case Else ' Pick from the Values Array for other formats

'LookUpArray

For i = 0 to UBound(ValuesArray)

If sToken = ValuesArray(i)(0) Then

GetRandStrForToken = ValuesArray(i)( 1 + Int( rnd*(UBound(ValuesArray(i))) ) )

Exit For

End If

Next

End Select

End Function

' Parse the current token (if any)

Function GetNextToken (ByRef sFormat)

For each sToken in FormatArray

sTemp = Mid(sFormat, 1, Len(sToken))

If sTemp = sToken Then

GetNextToken = sToken

sFormat = Mid(sFormat, Len(sToken) + 1)

Exit Function

End If

Next

End Function

' Generate random data given a format

Function GenerateRandData(ByVal Format)

Dim nPos

Dim nLength

nLength = Len(Format)

While nLength > 0

' Anything inside a [] brackets is copied as is

If Mid(Format, 1, 1) = "[" Then ' Find the closing brackets

nPos = InStr(1, Format, "]", vbTextCompare)

If nPos = 0 Then Exit Function

GenerateRandData = GenerateRandData + Mid(Format, 2, nPos - 2)

Format = Mid(Format, nPos + 1)

nLength = Len(Format)

Else

' Search for a valid token

sToken = GetNextToken(Format)

If Not sToken = "" Then

GenerateRandData = GenerateRandData + GetRandStrForToken(sToken)

nLength = Len(Format)

Else ' No token - just copy the current character

GenerateRandData = GenerateRandData + Mid(Format,1, 1)

If nLength = 1 Then

Exit Function

End If

Format = Mid(Format, 2)

nLength = Len(Format)

End If

End If

Wend

End Function

' Usage

msgbox GenerateRandData ("Today Is the first DAY in MONTH")

msgbox GenerateRandData ("A Date in the format [dd/mm/yyyy] dd/mm/yyyy")
msgbox GenerateRandData ("My name is NAME, I drive a COLOR CAR. you can reach me on +972-54-###-####")

Close Message Boxes Automatically in QTP

The function below shows a message box that disappears after the specified timeout (in seconds). The script execution then continues.

Public Sub MsgBoxTimeout (Text, Title, TimeOut)

Set WshShell = CreateObject("WScript.Shell")

WshShell.Popup Text, TimeOut, Title

End Sub

If TimeOut is 0, it behaves just like a normal message box. If TimeOut is greater than 0, the dialog box disappears after the specified number of seconds.

Debugging using File Operations

The following are some file operations which are useful for debugging. The following examples can be found in the FileOperationForDebugging.vbs file located in the <QuickTest installation folder>\CodeSamplesPlus folder.

' Creates a specified file and returns a TextStream object that can be used to read from or write to the file.

' Example of usage:

' Set f = CreateFile("d:\emp\beenhere.txt", True)

' f.WriteLine Now

' f.Close

Function CreateFile(sFilename, bOverwrite)

Set fso = CreateObject("Scripting.FileSystemObject")

Set CreateFile = fso.CreateTextFile(sFilename, bOverwrite)

End Function

' Opens a specified file and returns a TextStream object that can be used to read from, write to, or append to the file.

' iomode: 1 - ForReading, 2 - ForWriting, 8 - ForAppending

' Example of usage

' Set f = OpenFile("d:\emp\beenhere.txt", 2, True)

' f.WriteLine Now

' f.Close

Function OpenFile(sFilename, iomode, create)

Set fso = CreateObject("Scripting.FileSystemObject")

Set OpenFile = fso.OpenTextFile(sFilename, iomode, create)

End Function

' Appends a line to a file.

' Example of usage:

' AppendToFile "d:\emp\beenhere.txt", Now

Function AppendToFile(sFilename, sLine)

Const ForAppending = 8

If sFilename = "" Then

sFilename = Environment("SystemTempDir") & "\QTDebug.txt"

End If

Set f = OpenFile(sFilename, ForAppending, True)

f.WriteLine sLine

f.Close

End Function

' Writes a line to a file.

' Destroys the current content of the file .

' Example of usage:

' WriteToFile "d:\emp\beenhere.txt", Now

Function WriteToFile(sFilename, sLine)

Const ForWriting = 2

If sFilename = "" Then

sFilename = Environment("SystemTempDir") & "\QTDebug.txt"

End If

Set f = OpenFile(sFilename, ForWriting, True)

f.WriteLine sLine

f.Close

End Function

Normalizing Strings in QTP

The NormalizeString function receives a string and returns the equivalent string in a regular expression.

Function NormalizeString(OrgStr)

Dim TempStr

TempStr = Replace(OrgStr, "\", "\\")

TempStr = Replace(TempStr, "*", "\*")

TempStr = Replace(TempStr, "+", "\+")

TempStr = Replace(TempStr, ".", "\.")

NormalizeString = Replace(TempStr, "?", "\?")

End function

msgbox NormalizeString ("a+b*c.d?e")

Additional Online Resources for QTP

QuickTest Professional includes the following additional online resources:

Mercury Tours sample Web site (available from the QuickTest Professional Start menu program folder and also available from the QuickTest Professional Record and Run Settings dialog box) and the Mercury Tours Windows sample flight application (available from the QuickTest Professional Start menu program folder) are the basis for many examples in this book. The URL for the Web site is http://newtours.mercury.com.

Knowledge Base (available from Help > Knowledge Base) uses your default Web browser to open the Mercury Customer Support knowledge base, which enables you to browse the Mercury and user-contributed knowledge base articles, and add your own articles. The URL for this Web site is http://support.mercury.com/cgi-bin/portal/CSO/kbBrowse.jsp.

Customer Support Web Site (available from Help > Customer Support Web Site) uses your default Web browser to open the Mercury Customer Support Web site. This site enables you to browse the knowledge base and add your own articles, post to and search user discussion forums, submit support requests, download patches and updated documentation, and more. The URL for this Web site is http://support.mercury.com.

Send Feedback (available from Help > Send Feedback) enables you to send online feedback about QuickTest Professional to the product team.

Mercury Home Page (available from Help > Mercury Home Page) uses your default Web browser to open the Mercury home page. This site provides you with the most up-to-date information on Mercury and its products. This includes new software releases, seminars and trade shows, customer support, educational services, and more. The URL for this Web site is http://www.mercury.com.

Mercury Best Practices contain guidelines for planning, creating, deploying, and managing a world-class IT environment. Mercury provides three types of best practices: Process Best Practices, Product Best Practices, and People Best Practices. Licensed customers of Mercury software can read and use the Mercury Best Practices available from the Customer Support site, http://support.mercury.com.

Modifying License Information for QTP

Working with QuickTest requires a license. When you install QuickTest, you select one of the following license types:

  • a 14-day demo license
  • a permanent seat license that is specific to the computer on which it is installed
  • a network-based concurrent license that can be used by multiple QuickTest users

You can change your license type at any time (as long as you are logged in with administrator permissions on your computer). For example, if you are currently working with a demo license, you can install a seat license, or you can choose to connect to a concurrent license server, if one is available on your network.

If needed, you can request a new seat license on the Mercury Customer Support Web site. The URL for the License Request Web site is http://support.mercury.com/license.

If you purchase external add-ins, you need to install the relevant add-in licenses.

Deleting Results Using the Windows Command Line

You can use the Windows command line to instruct the Test Results Deletion Tool to delete test results according to criteria you specify. For example, you may want to always delete test results older than a certain date or over a minimum file size.

To run the Test Results Deletion Tool from the command line:

Open a Windows command prompt and type <QuickTest installation path>\bin\TestResultsDeletionTool.exe, then type a space and type the command line options you want to use.

Note: If you use the -Silent command line option to run the Test Results Deletion Tool, all test results that meet the specified criteria are deleted. Otherwise, the Delete Test Results window opens.

Command Line Options

You can use command line options to specify the criteria for the test results that you want to delete. Following is a description of each command line option.

Note: If you add command line options that contain spaces, you must specify the option within quotes, for example:
TestResultsDeletionTool.exe -Test "F:\Tests\Keep\web objects"

-Domain Quality_Center_domain_name

Specifies the name of the Quality Center domain to which you want to connect. This option should be used in conjunction with the -Server, -Project, -User, and -Password options.

-FromDate results_creation_date

Deletes test results created after the specified date. Results created on or before this date are not deleted. The format of the date is MM/DD/YYYY.

The following example deletes all results created after November 1, 2005.

TestResultsDeletionTool.exe -Silent -Test "C:\tests\test1" -FromDate "11/1/2005"

-Log log_file_path

Creates a log file containing an entry for each test results file in the folder or test you specified. The log file indicates which results were deleted and the reasons why other results were not. For example, results may not be deleted if they are smaller than the minimum file size you specified.

You can specify a file path and name or use the default path and name. If you do not specify a file name, the default log file name is TestResultsDeletionTool.log in the folder where the Test Results Deletion Tool is located.

The following example creates a log file in C:\temp\Log.txt.

TestResultsDeletionTool.exe -Silent -Log "C:\temp\Log.txt" -Test "C:\tests\test1"

The following example creates a log file named TestResultsDeletionTool.log in the folder where the Test Results Deletion Tool is located.

TestResultsDeletionTool.exe -Silent -Log -Test "C:\tests\test1"

-MinSize minimum_file_size

Deletes test results larger than or equal to the specified minimum file size. Specify the size in bytes.

Note: The -MinSize option is available only for test results in the file system. It is not supported when working with tests in Quality Center.

The following example deletes all results larger than or equal to 10000 bytes. Results that are smaller than 10000 bytes are not deleted.

TestResultsDeletionTool.exe -Silent -Test "C:\tests\test1" -MinSize "10000"

-Name result_file_name

Specifies the name(s) of the result file(s) to be deleted. Only results with the specified name(s) are deleted.

You can use regular expressions to specify criteria for the result file(s) you want to delete. For more information about regular expressions and regular expression syntax, refer to the QuickTest Professional Basic Features User's Guide.

The following example deletes results with the name Res1.

TestResultsDeletionTool.exe -Silent -Test "C:\tests\test1" -Name "Res1"

The following example deletes all results whose name starts with Res plus one additional character. (For example, Res1 and ResD would be deleted. ResDD would not be deleted.)

TestResultsDeletionTool.exe -Silent -Test "C:\tests\test1" -Name "Res."

-Password Quality_Center_password

Specifies the password for the Quality Center user name. This option should be used in conjunction with the -Domain, -Server, -Project, and -User options.

The following example connects to the Default Quality Center domain, using the server located at http://QCServer/qcbin, with the project named Quality Center_Demo, using the user name Admin and the password PassAdmin.

TestResultsDeletionTool.exe -Domain "Default" -Server "http://QCServer/qcbin" -Project "Quality Center_Demo" -User "Admin" -Password "PassAdmin"

-Project Quality_Center_project_name

Specifies the name of the Quality Center project to which you want to connect. This option should be used in conjunction with the -Domain, -Server, -User, and -Password options.

-Recursive

Deletes test results from all tests in a specified folder and its subfolders. When using the -Recursive option, the -Test option should contain the path of the folder that contains the tests results you want to delete (and not the path of a specific test).

The following example deletes all results in the F:\Tests folder and all of its subfolders.

TestResultsDeletionTool.exe -Test "F:\Tests" -Recursive

Note: The -Recursive option is available only for folders in the file system. It is not supported when working with tests in Quality Center.

-Server Quality_Center_server_path

Specifies the full path of the Quality Center server to which you want to connect. This option should be used in conjunction with the -Domain, -Project, -User, and -Password options.

-Silent

Instructs the Test Results Deletion Tool to run in the background (silently), without the user interface.

The following example instructs the Test Results Deletion Tool to run silently and delete all results located in C:\tests\test1.

TestResultsDeletionTool.exe -Silent -Test "C:\tests\test1"

-Test test_or_folder_path

Sets the test or test path from which the Test Results Deletion Tool deletes test results. You can specify a test name and path, file system path, or full Quality Center path.

This option is available only when used in conjunction with the -Silent option.

Note: The -Domain, -Server, -Project, -User, and -Password options must be used to connect to Quality Center.

The following example opens the Test Results Deletion Tool with a list of the results in the F:\Tests\Keep\webobjects folder.

TestResultsDeletionTool.exe -Test "F:\Tests\Keep\webobjects"

The following example deletes all results in the Quality Center Tests\webobjects test:

TestResultsDeletionTool.exe -Domain "Default" -Server "http://QCServer/qcbin" -Project "Quality Center_Demo592" -User "Admin" -Password "PassAdmin" -Test "Subject\Tests\webobjects"

Note: The -Test option can be combined with the -Recursive option to delete all test results in the specified folder and all its subfolders.

-UntilDate results_creation_date

Deletes test results created before the specified date. Results created on or after this date are not deleted. The format of the date is MM/DD/YYYY.

This option is available only when used in conjunction with the -Silent option.

The following example deletes all results created before November 1, 2005.

TestResultsDeletionTool.exe -Silent -Test "C:\tests\test1" -UntilDate "11/1/2005"

-User Quality_Center_user_name

Specifies the user name for the Quality Center project to which you want to connect. This option should be used in conjunction with the -Domain, -Server, -Project, and -Password options.

This option is available only when used in conjunction with the -Silent option.