Saturday, August 23, 2008

How to find out the number of links in a web page

Here i am writing the link names in a text file

Set fileSysObject=createobject("Scripting.FileSystemObject")
Set linksFileName=fileSysObject.opentextfile("D:\samplelinkfile.txt",2,true)

Set linkDescObj=description.Create
linkDescObj("micclass").value="Link"
Set noOfLinks=browser("Browser").Page("Yahoo! India").ChildObjects(linkDescObj)

For i=0 to noOfLinks.count-1
linkName=noOfLinks(i).getROProperty("name")
linksFileName.writeline(linkName)
Next
linksFileName.close
Set fileSysObject=nothing

Wednesday, August 20, 2008

what is the difference between Automation object model(AOM) and test object model(TOM)?

By using QTP automation object model, we can automate QTP operations.

By using object, methods and properties provided by QTP, we can write programs that can configure QTP operations and settings.

For example, you can create and run an automation program from Microsoft Visual Basic that loads the required add-ins for a test or component, starts QuickTest in visible mode, opens the test, configures settings that correspond to those in the Options, Test Settings, and Record and Run Settings dialog boxes, runs the test, and saves the test.

Test Object Model, is nothing but how QTP identifies the objects in the application.

How to get the class of an object, what mandatory and assistive properties are used during recording the application, how it identifies the objects during run session etc...

What is the vb script when the url enter into the browser

Browser Object.navigate "URL"

Ex: Browser("browser").navigate "www.yahoomail.com"

How to capture screen shots when an error occurs?

In QTP8.2, we can choose the run setting:
Test -> settings -> Run tab -> set ON save image of desktop when error occurs checkbox

In QTP 9.2, follow the below navigation:
Tools -> Options -> Run tab -> In the drop down list box "On Error"(default) is selected for "Save step screen capture to results"

And even we can also configure, whether we have to proceed to next step or stop the test execution by following below navigation:
File Menu -> Settings -> Run Tab -> Choose the required action from the "Whenever an error occurs during run session" drop down list box.

Where the text version of script file located in file system?

Path of your testname\ActionName\Script.mts

Ex: D:\QTPSample\SampleTest\Action1\Script.mts

How to call action into a script

We can call an action as per our needs.

If you want to call a new action, follow below navigation
Insert Menu ->Call to New Action -> Give an action name description etc...

If you wish to call a read only copy of an action, use "Call to copy of action" and follow the below navigation for it:
Insert Menu ->Call to copy of action ->Choose the test name and action name

If you wish to call a reusable action, then use "Call to existing action"
Insert Menu ->Call to existing of action ->Choose the test name and action name

If you wish to call a reusable action within your programatically during run-time use
RunAction "ActionName",NoOfIterations,Parameters

If you wish to call a reusable action in another test your programatically during run-time use
RunAction "ActionName[ScriptName]",NoOfIterations,Parameters

How to get line numbers in your editor in expert view?

Follow below navigation:
Tools -> Editor Options -> General tab -> set show line numbers check box

How to Parameterize Object repository in QTP?

In QTP 8.2, we can parameterize both the per-action OR and shared OR.

For Per-Action OR, we can parameterize in both the global sheet and local action sheets.

To do this, we can select the object in OR, and choose parameter radio button in configure value dialog, and choose global or current action sheet in parameter options.

If the OR is shared OR, here only global sheet option is visible and current action sheet is disabled.

To parameterize the OR follow below navigation:
Open the OR by Tools -> OR or OR button -> Select the object in OR or parent object -> Click parameter radio button -> click on the parameter options button beside the textbox ->select data table in parameter type list box -> choose the data sheet type and choose column name in the sheet

What are the product enhancements in QTP 9.2

Enhanced Object Spy Functionality: You can now use the Object Spy to spy on multiple objects during a single spying session. When you click the pointing hand, QuickTest is hidden, but the Object Spy remains visible. You can hover over different objects in your application and view the methods and properties of each one. When you want to return the focus to QuickTest to view methods and properties of a particular object, you click the object with the pointing hand.

Web Drag and Drop Support: You can now test drag and drop operations in your Web-based application using the new Drag and Drop methods, available for all Web test objects (except the container objects Browser, Page, and Frame).

You can use these methods to drag one Web object onto another Web object, to drag a Web object from one location in a frame to another, or to drag an item within a Web object to another location within that object (drag and pan).

Text Recognition Support for Windows-Based Environments: In recent versions of QuickTest Professional, text-capturing test object methods, reserved object methods, text/text area checkpoints, and text/text area output value steps were not available for objects in Windows-based environments (Standard Windows, Visual Basic, ActiveX, .NET Windows Forms, ActiveX, and Terminal Emulators).

In QuickTest Professional 9.2, you can use the text and text area checkpoint or output value commands to verify or retrieve text in your Windows-based objects. Alternatively, you can use the testobject.GetText (for Terminal Emulator objects), testobject.GetVisibleText, or testobject.GetTextLocation test object methods, or the TextUtil.GetText or TextUtil.GetTextLocation reserved object methods to capture the text you need.

When capturing text for a text/text area checkpoint or output value step, or using one of the above mentioned methods, QuickTest tries to retrieve the text directly from the object. If QuickTest cannot capture the text this way (for example, because the text is part of a picture), it tries to capture the text using a new OCR (optical character recognition) mechanism.

Whenever possible, it is highly recommended to check text from your application window by inserting a standard checkpoint, output value, or GetROProperty method for the object containing the desired text to retrieve the value of it's text (or similar) property.

New Supported Operating Systems and Environments

QuickTest Professional 9.2 has added support for the following operating systems, browsers, and development environments.

Ø Microsoft Windows Vista

Ø Citrix support

Ø VMWare desktop support (QuickTest and the tested application must both be installed on the virtual machine).

Ø Microsoft Internet Explorer 7

Ø Mozilla Firefox 2.0

Ø Netscape Browser 8.1.2

Ø Microsoft Windows Presentation Foundation (supported with the .NET Add-in 9.2)

What are the new features in QTP 9.2

Mercury Screen Recorder: You can instruct QuickTest to save a movie of your entire run session or to capture only the segments surrounding errors or warnings that occur. This can be useful to help you see how your application behaved under test conditions or to debug your test or component.

When you select a step in the test results tree and click the Screen Recorder tab, the right pane of the Test Results window displays the frame in the movie corresponding to the highlighted step in the test results tree.

Once you have a movie stored with your test results, you can export the movie file or attach the movie file to the defects you report to Quality Center. You can also use the Mercury Micro Player if you want to watch a captured movie without opening QuickTest.

You can customize the criteria QuickTest uses to save movies in the Run tab of the Options dialog box.

You can customize the criteria QuickTest uses to save movies by selecting Always, For errors, or For errors and warnings in the Save movies to results list in the Run tab of the Options dialog box.

To configure screen recorder options, follow below navigation:

Tools -> Options -> Run Tab

Dynamic Management of Object Repositories: QuickTest now has a new RepositoriesCollection reserved object that you can use to programmatically manage the set of object repositories that are associated with an action during a run session.

At the beginning of a run session, the RepositoriesCollection object contains the same set of object repository files as the Associated Repository Files tab of the Action Properties dialog box. The operations you perform on the RepositoriesCollection object affect only the run-time copy of the collection.

You can use the RepositoriesCollection object to associate or disassociate shared object repositories with an action during a run session or change the priority order of the objects in the list.

We can associate the object repositories to an action by following below navigation:

Edit Menu -> Action -> Action Properties -> Associate Repositories tab.

Monday, August 11, 2008

Can the class of an object be retrieved using the logical name

QTP does not have a method or function to retrieve the class of an object based on the logical name. This is a limitation of the QTP product.
However, you may use a unique property of an object to determine the class of the object. Include the unique property in a description object then use the ChildObjects method to capture a collection of the objects which have that description. The GetROProperty method can be used on each object in the collection to get the "micclass" property.
Set oDesc = Description.Create()oDesc( "text").Value = "Cancel"Set child = Dialog("Login").ChildObjects (oDesc)msgbox child(0).GetROProperty("micclass")

Why QTP iterates for rows removed from the Data Table

If the user deletes a row from the data table using CTRL-X or the Delete key, QTP still runs an iteration for that row.
The DataTable contains four rows with data. The user uses the Delete key to delete the third and fourth rows. On replay, QTP still replays four iterations, even though he expects it to replay only two iterations. Why does this happen? The row was not deleted from the Data Table; only its contents were removed.
Each row in the table represents an iteration of the test script. You can see this in the Data Table. Any rows that are used for iterations have a black bottom grid line (instead of a gray grid line).
The CTRL-X and Delete keys remove the values from the cells in the row, but do not remove the rows (the grid line for the is still black).
If you want to prevent QTP from running an iteration on a row, you need to delete the entire row from the Data Table using the Edit -> Delete option (Ctrl+K). (This restores the bottom grid line from black to gray.)

When are optional steps used?

When recording a test or component, the application you are testing may prompt you to enter a user name and password in a login window. When you run the test or component, however, the application does not prompt you to enter your user name and password, because it has retained the information that was previously entered. In this case, the steps that were recorded for entering the login information are not required and should, therefore, be marked optional.
When running a test or component, if a step in an optional dialog box does not open, QuickTest bypasses this step and continues to run the test. When the run session ends, a message is displayed for the step that failed to open the dialog box, but the step does not cause the test or component to fail.
To set an optional step in the Keyword View, right-click a step and choose Optional Step.You can also add an optional step in the Expert View by adding OptionalStep to the beginning of the VBScript statement. For example:OptionalStep.Browser("Browser").Page("Yahoo! Mail - The best").WebEdit("login").Set "uday"

What are environmental variables in QTP? How to use environmental variables?

In QTP, the variables defined in one action cannot be accessed in another action. By using environmental variables, we can access these variables.
QTP supports 3 types of environmental variables:
1. Built-in environmental variables: Variables that represent information about the test and the computer on which the test is run, such as Test path and Operating system. These variables are accessible from all tests, and are designated as read-only.
2. User defined internal environmental variables: variables that you define within the test. These variables are saved with the test and are accessible only within the test in which they were defined. You can create or modify internal, user-defined environment variables for your test.To create User defined internal variables follow below navigation:Test -> settings -> Environmental tab -> Choose “User-defined” in variable type -> click on new button and give name and value.

3. User defined external environmental variables: variables that you predefine in the active external environment variables file. External environment variable values are designated as read-only within the test.To create User defined external variables follow below navigation:Test -> settings -> Environmental tab -> Choose “User-defined” in variable type -> and choose Load variables and values from external file(reloaded each run session) check box ->Enter .xml file which contains the environmental variables.

All the internal user defined environmental variables are displayed with black color, and external environmental variables are displayed in blue color.
The access the value of the environmental variables:temp=Environment.Value("Name")

Deleted a reusable external action from test, but the Action Filter and Local Datasheet still does not reflect the removal from the test.

We have discovered that when a Re-usable external action is called into the main test and then is deleted, the main test will delete the call to the action; however, the test flow filter still contains the external action in the list of external actions in the main test, as well as the Local Datasheet remaining part of the test.

What property we use to get the tooltip of a link or an Image?

We use “alt” Run-time property of an object
Ex : var1=browser("MSN.com").Page("MSN.com").Image("NFL Sunday: Week 10 //LaDainia").GetROProperty("alt")

How to programmatically load a Shared Object Repository

Use the Automation Object Model to specify the path to a Shared Object Repository:
Dim App 'As Application
Set App = CreateObject("QuickTest.Application")
App.Test.Settings.Resources.ObjectRepositoryPath = ""

How can you load External Library files in QTP 8.2?

We can load the external Library files by using 2 ways:
Choose Test > Settings > Choose Resources tab > Choose + button so select the library file > browse and select the library file > click Ok.
We can load the library files using Scripting:
Use executefile function to load library files.
Example:
executefile "C:\Documents and Settings\ukumar\Desktop\Sample.vbs"
x=10
y=5
result=SumOfTwoNumbers(x,y)
msgbox(result)

'Code in External Library file.
'Public function SumOfTwoNumbers(a,b)
'Dim sum
'sum=a+b
'SumOfTwoNumbers=sum
'End Function

How to check number of items in a WebList at run time.

Browser("browser name").Page("page name").WebList("list1").GetROProperty("items count")

How to "Turn Off" QTP results after running a Script?

Choose Tools > Options > Run Tab > Deselect View results when run session ends check box. But this suppresses only the result window, but log will be created and can viewed manually which cannot be restricted from getting created.

How to supress warnings from the "Test results page"?

From the Test results Viewer choose Tools > Filters > Uncheck the Warnings check box.

How to open any application using scripting?

SystemUtil , object used to open and close applications and processes during a run session.
A SystemUtil.Run statement is automatically added to your test when you run an application from the Start menu or the Run dialog box while recording a test
E.g : SystemUtil.Run "Notepad.exe"

How will you customize the Active Screen settings in QTP?

The Active Screen tab enables you to specify which information QTP saves and displays in the Active Screen while recording and running tests.
The more information saved in the Active Screen, the easier it is to edit the test or component after it is recorded. However, more information saved in the Active Screen adds to the recording time and disk space required. This is especially critical in Visual Basic, ActiveX, and .NET Windows Forms environments.
We can customize the Active Screen setting, by using “Custom Active Screen Capture Settings”.
To do this follow below navigation:
Tools > Options > Active Screen Tab > Click on custom level button > configure as per your needs and click Ok.

Friday, August 8, 2008

What is Smart Identification?

Configuring Smart Identification properties enables you to help QuickTest identify objects in your application, even if some of the properties in the object’s learned description have changed.

If QuickTest is unable to find any object that matches the learned object description, or if it finds more than one object that fits the description, then QuickTest ignores the learned description, and uses the Smart Identification mechanism to try to identify the object.

The Smart Identification mechanism uses two types of properties:

Ø Base Filter Properties.

Ø Optional Filter Properties.

Selecting the Enable Smart Identification check box for a particular test object class instructs QuickTest to learn the property values of all properties specified as the object’s base and/or optional filter properties in the Smart Identification Properties dialog box.

Thursday, August 7, 2008

How to create a folder and delete a folder

folderPath="d:\Sample Folder"

Set fileSysObj=createobject("Scripting.FileSystemObject")

On Error resume next

fileSysObj.createfolder(folderPath)

If Err.number<> 0 Then
reporter.ReportEvent micFail,"createfolder","Unable to create the specified folder"
End If

If fileSysObj.folderexists(folderPath) Then
fileSysObj.deletefolder(folderPath)
else
reporter.ReportEvent micFail,"folder delete","The specified folder does not exist"
End If