Quick test professional

QTP Tips QTP codes QTP Faqs and more

Get all files within a time range or specified time

Dim From

From = TimeSerial( 11, 0, 0 ) ‘ to emphasize 24 hour clock! 11 AM

Dim Till

Till = TimeSerial( 13, 0, 0 )

 Dim oFS

Set oFS = CreateObject( “Scripting.FileSystemObject” )

Dim oFile, tFile, Range

For Each oFile In oFS.getFolder( “.\” ).Files

tmFile = TimeValue( oFile.DateCreated )

bInRange = tFile >= From And tFile <= Till

msgbox oFile.DateCreated &”–“& oFile.Name
   Next

February 15, 2008 Posted by | Files and Folders | , , , , , , , , , , | 4 Comments

Get The Latest Created File

   Const cdtFirst = #1/1/100#

   Dim sFolder  : sFolder    = “.\”
   Dim oFS      : Set oFS    = CreateObject( “Scripting.FileSystemObject” )
   Dim dtLatest : dtLatest   = cdtFirst
   Dim sExt     : sExt       = “ppt” ‘ not entirely sure about this extension
   Dim oLFile   : Set oLFile = Nothing
   Dim oFile
   For Each oFile in oFS.GetFolder( sFolder ).Files
       If sExt = LCase( oFS.GetExtensionName( oFile.Name ) ) Then
          If dtLatest < oFile.DateLastAccessed Then ‘ maybe DateCreated/DateLastModified
             dtLatest = oFile.DateLastAccessed
             Set oLFile = oFile
          End If
       End If
   Next
   If oLFile Is Nothing Then
      WScript.Echo “No file with extension”, sExt, “found.”
   Else
      WScript.Echo “found”, oLFile.Name, oLFile.DateLastAccessed
   End If

February 15, 2008 Posted by | Files and Folders | , , , , , , , , , , | Leave a comment

How to register COM with QTP?

How to register COM with QTP? 

Steps to create Intellisense in QTP:

1. Create a wsc(windows scripting component) file in the below given format:

<?xml version=”1.0″?>
<component>

<?component error=”true” debug=”true”?>
<reference object=”Scripting.Dictionary” />
<registration description=”Functions” progid=”QTP.Functions” version=”1.00″ classid=”{d7c40957-00d4-41a5-a87b-89d1db311423}”>
</registration>

<public>

<method name=”Function1″ internalName=”Functiona1″ dispid=”0″>
<PARAMETER name=”strFileName”/>
</method>
<method name=”Function2″>
</method>
<method name=”Function3″ >
</method>
</public>

</component>
2. After the file is created, register the same using regsvr32.
3. Now create the following registry entries in the path HKCU\Software\Mercury Ineteractive\QuickTest Professional\MicTest\Reserved Objects\Functions –

ProgID REG_SZ QTP.Functions
UIName REG_SZ Functions

4. Restart QTP.

  Source: Mercury Forum’s KB articles

February 14, 2008 Posted by | COM and QTP | , , , , , , , , | 3 Comments

Get Each Radio in RadioGroup And Check

Get Each Radio in RadioGroup

And Check

Set opt=Description.Create
opt(“html tag”).value=”INPUT”
opt(“type”).value = “radio”
Dim allOptions,all
Set allOptions=Browser(“a”).Page(“b”).Frame(“c”).ChildObjects(opt)
all=allOptions.count
MsgBox all

for i= 0 to all
eName=allOptions(i).getROProperty(“name”)
noofradio=allOptions(i).getElementsByName(eName).length
for j= 0 to noofradio-1
radioname=allOptions(i).object.document.getElementsByName(eName).item(j).GetAdjucentText(“afterend”)allOptions(i).object.document.getElementsByName(eName).item(j).checked=true
msgbox radioname
next
next

  Source: Mercury Forum’s KB articles

February 14, 2008 Posted by | Descriptive Programming and Child Objetcs | , , , , , , , , | 8 Comments

How To close MsgBox Runtime

 

How To close MsgBox Runtime 

Write the below line as the first-line in your script. Set sh = CreateObject(“Scripting.Shell”) …This will create a shell object at run-time and will be available until the test ends.

If you are getting problem like ,Activex Component can’t create object Then use  Set sh =CreateObject(“WScript.Shell”)

 Now… where ever you are having “msgbox” replace it with..

sh.Popup “message content”, 5, “msg header”, (0+4)

 the above line will show the message content for 5 seconds(and vanishes after that).

The alert-box’s header will have “header info”. Last parameter(0+4) is actually two things. 0 -> show OK button in the alertBox 48 -> “!” icon… if you use 64 u will see X icon instead BTW… since u need the message to be displayed

 

 

February 14, 2008 Posted by | QTP Tips and Faqs | , , , , , , , , | 13 Comments

How to do the backward compatability in QTP

 How to run the scripts in 8.2

those are recorded in 9.0 or higher

Sol:

Step 1: Delete the object repository of 9.0

Step 2: open a Blank test in 8.2

Step 3: Create the shared object repository in 8.2 that should contain all the objects in 9.0 and save.

Step 4: create the action structure in 8.2 should contain the same num of actions, same names and structure as the script of 9.0.

Step 5: save the test. (From now we call this as 8.2 scripts)

Step 6: from 8.2 script copy Test.tsp file to the 9.0 script.

Step 7: copy all Resource.MTR file found in Action0, Action 1, etc to 9.0 scripts

Step 8: now u can run the scripts with little modifications if require

Author: Mohan Kakarla

February 14, 2008 Posted by | Backward compatability in QTP | , , , , , , , | 1 Comment

GET NAMES OF ALL OPEN BROWSERS

Set bDesc = Description.Create()

bDesc(“application version”).Value = “internet explorer 6”

Set bColl = DeskTop.ChildObjects(bDesc)

Cnt = bColl.Count

MsgBox “There are total: “&Cnt&”browsers opened”

 For i = 0 To (Cnt -1)

MsgBox “Browser : “&i&” has title: “& bColl(i).GetROProperty(“title”)

Next ‘ i

 Set bColl = Nothing

Set bDesc = Nothing

Author: Mohan Kakarla

February 14, 2008 Posted by | Browser Scripts | , , , , , , , , | 3 Comments

What’s New in Quick Test Pro 9.0,9.1

What’s New in Quick Test Pro 9.0

Object Repository Manager

You can use the Object Repository Manager to manage all of the shared object repositories in your organization from one, central location. This includes adding and defining objects, modifying objects and their descriptions, parameterizing test object property values, maintaining and organizing repositories, and importing and exporting repositories in XML format. You can open multiple object repositories at the same time. Each object repository opens in its own resizable document window. This enables you to compare the content of the repositories, to copy or move objects from one object repository to another, and so forth

Object Repository Merge Tool

You can use the Object Repository Merge Tool to merge the objects from two shared object repositories into a single shared object repository. You can also use the Object Repository Merge Tool to merge objects from the local object repository of one or more actions or components into a shared object repository. When you merge objects from two source object repositories, the content is copied to a new, target object repository, ensuring that the information in the source repositories remains unchanged. If any conflicts occur during the merge, for example, if two objects have the same name and test object class, but different test object descriptions, the relevant objects are highlighted in the source repositories, and the Resolution Options pane details the conflict and possible resolutions.

Multiple Object Repositories per Action or Component

QuickTest provides several options for storing and accessing test objects. You can store the test objects for each action or component in its corresponding local object repository, which is unique for each action and component. You can also store test objects in one or more shared object repositories that can be used in multiple actions and components. Alternatively, you can use a combination of objects from the local object repository and one or more shared object repositories. You choose the combination that matches your testing needs.

XML Object Repository Format

QuickTest now enables you to import and export object repositories from and to XML format. This enables you to modify object repositories using the XML editor of your choice and then import them back into QuickTest. You can import and export files either from and to the file system or a Quality Center project (if QuickTest is connected to Quality Center).

Function Library Editor

QuickTest now has a built-in function library editor, which enables you to create and edit function libraries containing VBScript functions, subroutines, modules, and so forth, and then call their functions from your test or component. You can create, open, and work on multiple function libraries simultaneously. Each function library opens in its own document window. When working with a function library, another testing document, such as a test, application area, or component, is always open, enabling you to add calls to your functions as you create or modify them. By creating and working with function libraries directly in QuickTest, you can take advantage of QuickTest’s Expert View-like editing features, syntax checker, debug features, and so forth. For example, you can step directly into the function code in a function library while debugging a test or component. You can also use the Function Definition Generator to generate definitions for new user-defined functions, add header information to them, and register these functions to a test object, if needed. You can then complete the function by adding its content (code). You can associate a function library directly with a test or application area, to make its functions available to all of a test’s actions, or to all of an application area’s associated components. By implementing user-defined functions in function libraries and associating them with your test, you and other users can choose functions that perform complex operations, such as adding if/then statements and loops to test steps, or working with utility objects—without adding the code directly to the test. In addition, you save time and resources by implementing and using reusable functions.

Handling Missing Actions and Resources

Whenever a testing document (test, component, or application area) contains a resource that cannot be found, QuickTest opens the Missing Resources pane and lists the missing resource(s). For example, a test may contain an action or a call to an action that cannot be found; a testing document may use a shared object repository that cannot be found; or a testing document may use an object repository parameter that does not have a default value. In all of these cases, QuickTest indicates this in the Missing Resources pane, enabling you to map a missing resource to an existing one, or remove it from the testing document, as required.

New Look and Functionality for Application Areas

An application area serves as a single entity in which you store all of the resources and settings required for a component. It also provides a single point of maintenance for all elements associated with the testing of a specific part of an application. With this release, application areas have a new look and enhanced functionality. The application area document now contains a sidebar that lets you navigate directly to the resources or settings you want to modify. Application areas now include a list of keywords that you can make available to associated components. To help you decide which keywords to make available for use in a particular application area, QuickTest enables you to sort and filter the keyword list, and displays the properties for any keyword you highlight. The resources and settings you define for an application area are now linked to all associated components, ensuring that any changes you make in the resource files are immediately applied to these components. For example, if you modify the properties of an object in an associated object repository, the changes immediately affect any associated components using that test object.

New Supported Operating System Versions

QuickTest now supports the following operating system:

  • Windows 2000—Service Pack 4
  • Update Rollup 1 for Windows 2000 Service Pack 4
  • Windows XP 32-Bit Edition—Service Pack 2
  • Windows XP 64-Bit Edition—Service Pack 1
  • Windows Server 2003 32-Bit Edition—Service Pack 1
  • Windows Server 2003 R2 (32-Bit x86)

New Supported Browsers and Browser Versions

In addition to support for recording tests and components on Microsoft Internet Explorer, QuickTest now supports running tests and components on the following new Web browser versions:

  • Microsoft Internet Explorer 7.0
  • Netscape Browser 8
  • Mozilla Firefox 1.5

New Look and Feel for the QuickTest Window

The QuickTest window now contains movable and dockable tabbed panes that you can position anywhere on your screen, as required. When customizing the QuickTest window, you can move and resize panes, select to show or auto-hide panes, create tabbed panes, select which toolbars to display, and so forth. For example, you can move the Data Table to be a floating pane at the top right of the window, or you can display the Active Screen, Data Table and Missing Resources pane all as tabbed panes at the bottom left of the window. You can also apply any of the available Windows themes to the QuickTest window to change the look and feel of the main QuickTest window to suit your needs.

Improved Menus and Toolbars

The QuickTest menus and toolbars contain more intuitive categories and new commands to help you better manage your QuickTest sessions. For example, the Automation menu contains all of the commands that are related to recording and running your tests and components, as well as viewing the run results. The Resources menu contains all of the commands that are relevant for managing your object repositories, and for viewing associated function libraries. The File menu enables you to set document-specific settings, manage your testing documents, connect to your Quality Center project, associate function libraries with your testing document, and so forth.

New and Enhanced Expert View and Function Library Editor Options

You can use the following new options and enhancements when working in the Expert View or Function Library editor:

Syntax Errors

You can check for syntax errors at any time by using the new Check Syntax command. If syntax errors are identified, they are displayed in the Information Pane in the bottom left corner of your screen (configurable). You can jump directly to the statement line for each error so that you can correct it. As in the previous release, when you select to switch to the Keyword View from the Expert View, QuickTest checks whether there are syntax errors in your statements. QuickTest displays the Keyword View only after all syntax errors have been corrected.

Comment/Uncomment

You can now comment and uncomment individual statements or entire sections in your action using the new Comment Block and Uncomment Block commands. This enables you to comment out sections while debugging your actions, for example, as well as providing an additional way to implement comments.

Indent/Outdent

You can now indent and individual statements or blocks of statements using the new Indent and Outdent commands. This helps make your test actions more readable and easier to maintain.

Action Parameter Enhancement

In addition to specifying test or action parameters to pass values to and from your test, and between actions in your test, you can now use action parameters to pass values between sibling actions (actions at the same hierarchical level).

Debugging Enhancements

You can use the following new options and enhancements when debugging your tests, components, and function libraries:

New Step Commands

In addition to the Step Into, Step Over, and Step Out options, you can now instruct QuickTest to start a debug session from a particular step using the Start from Step command, or to run the debug session from the current step until it reaches a particular step using the Run to Step commands.

Run Current Action

You can also use the Run Current Action option to run a single action in your test.

Enhanced Breakpoint Support

You can now insert and remove breakpoints in the Keyword View by clicking in the margin to the left of a statement in your testing document. You can also enable and disable breakpoints as you debug different parts of your action, component, or function library. This enables you to temporarily ignore breakpoints without removing them as you debug the various parts of your test, component, or function library.

Added Control of the Object Repository from Run Session and QuickTest Automation Scripts

QuickTest provides a new Repository reserved object that enables you to set or retrieve the value of object repository parameters for the current run session. The QuickTest Professional automation object model provides a new ObjectRepositories collection object that enables you to control the object repositories associated with actions. For example, when you create a new object repository for a new product module, you can use an automation script to associate the new object repository with the actions of all relevant tests.

Checkpoint and Output Value Renaming Capabilities

When you create a checkpoint or output value, by default, its name is the name of the test object on which the checkpoint or output value step is performed. QuickTest now enables you to rename checkpoints and output values in your test. This can make it easier, for example, to see the purpose of the checkpoint or output value step without opening the checkpoint or output value dialog box.

Test Results Enhancements

You can now export run results to an HTML file to save them in HTML format. This is useful, for example, if you want to send the HTML file containing the run session results in an e-mail to a third-party who does not have QuickTest installed. You can choose to export the entire report to an HTML file, or just a part of it. You can also modify the theme of the Test Results window, just like you can for the main QuickTest window. What’s New in Quick Test Pro 9.1

Navigate and Learn

The new Navigate and Learn feature is accessible from the Object Repository Manager. Each time you select a window to learn using this feature, the selected window and its descendant objects are added to the active shared object repository according to the settings in the object filter.

Object Repository Comparison Tool

The new Object Repository Comparison Tool is accessible from the Object Repository Manager. You can use this tool to identify the differences between objects in two specified shared object repository files. It also enables you to track changes in different versions of the same shared object repository file. After the compare process, the Comparison Tool provides a graphic representation of the objects in the object repositories, indicating objects that have differences, as well as objects that are unique to one repository. You can also view the properties and values of each object in the repositories. During the comparison process, the original object repository files remain unchanged

Object Repository Automation

You can use the objects and methods of the QuickTest Object Repository automation object model to write scripts that automatically manipulate object repositories, instead of performing these operations manually using the Object Repository Manager. For example, you can add, remove, and rename test objects, import from and export to XML, and retrieve and copy test objects. The QuickTest Professional Object Repository Automation Reference is a Help file that provides detailed descriptions, syntax information, and examples for the objects and methods in the QuickTest object repository automation object model. You can write your automation scripts in any language and development environment that supports automation.

New Environment Support

QuickTest Professional 9.1 supports the following new infrastructure software, operating system, and Web browser versions:

  • QuickTest now runs under Microsoft .NET Framework 2.0. If it is not currently installed on the computer on which you are installing QuickTest, Setup prompts you to install it before continuing the installation. On-screen instructions are provided.
  • QuickTest now provides Beta-level support for Microsoft Windows Vista Beta 2—build 5384.
  • QuickTest now provides Beta-level support for Microsoft Internet Explorer 7.0 Beta 3. For more information about working with the Web add-in, see Testing Web Objects.
  • QuickTest now provides Alpha-level support for Bon Echo version 2.0a3 (Mozilla Firefox 2.0 Alpha).

Newly Integrated Tools

The QuickTest Script Editor and Business Component Upgrade Tool are now installed automatically when you install QuickTest Professional 9.1.   

February 14, 2008 Posted by | What’s New in Quick Test Pro 9.0 | , , , , , , , , , | 7 Comments

QTP Additional Faqs

QTP Additional Faqs

1) How to Stop  the execution of the test.

    Syntax

   Services.Abort 2)How to add folders

Sub AddNewFolder(path, folderName)     Dim fso, f, fc, nf   
  Set fso = CreateObject("Scripting.FileSystemObject")    
 Set f = fso.GetFolder(path)

     Set fc = f.SubFolders    
 If folderName <> "" Then

        Set nf = 
fc.Add(folderName)

    Else        
Set nf = fc.Add("New Folder")

 
    End If End Sub

An error occurs if the folderName already exists.

3 )How to get the ASCII valuse for a character

Remarks

In the following example, Asc returns the ANSI character code of the first letter of each string:

Dim MyNumber  MyNumber = Asc("A")    

   ' Returns 65.

 MyNumber = Asc("a")

       ' Returns 97.

 MyNumber = Asc("Apple")   ' Returns 65.

Note   The AscB function is used with byte data contained in a string. Instead of returning the character code for the first character, AscB returns the first byte. AscW is provided for 32-bit platforms that use Unicode characters. It returns the Unicode (wide) character code, thereby avoiding the conversion from Unicode to ANSI.

4) How to get Character fron ASCII value

Remarks

Numbers from 0 to 31 are the same as standard, nonprintable ASCII codes. For example, Chr(10) returns a linefeed character.

The following example uses the Chr function to return the character associated with the specified character code:

Dim MyChar
 MyChar = Chr(65)   ' Returns A.
 MyChar = Chr(97)   ' Returns a.
MyChar = Chr(62)   ' Returns >.  MyChar = Chr(37)   ' Returns %.

Note   The ChrB function is used with byte data contained in a string. Instead of returning a character, which may be one or two bytes, ChrB always returns a single byte. ChrW is provided for 32-bit platforms that use Unicode characters. Its argument is a Unicode (wide) character code, thereby avoiding the conversion from ANSI to Unicode.

5)Accessing User-Defined Properties of Web Objects

You can use the attribute/<property name> notation to access native properties of Web objects and use these properties to identify such objects with programmatic descriptions. For example, suppose a Web page has the same company logo image in two places on the page: <IMG src=”logo.gif” mce_src=”logo.gif” LogoID=”122″> <IMG src=”logo.gif” mce_src=”logo.gif” LogoID=”123″> You could identify the image that you want to click using a programmatic description by including the user-defined property LogoID in the description as follows: Browser(“Mercury Tours”).Page(“Find Flights”).Image(“src:=logo.gif”,”attribute/LogoID:=123″).Click 68, 12 Note: The attribute/<property name> notation is not supported in Netscape 4.x.

6)How to Run Your Automation Program

There are several applications available for running automation programs. You can also run automation programs from command line using Microsoft’s Windows Script Host. For example, you could use the following command line to run your automation program: WScript.exe /E:VBSCRIPT myScript.vbs 7) What is the other way of making coments instead of astrik(‘)

Ans: “Hello” : Rem Comment after a statement separated by a colon.

8)How to run commands in command prompt from qtpAns:You can run standard DOS commands in your QuickTest test using the VBScript Windows Scripting Host Shell object (WSCript.shell). For example, you can open a DOS command window, change the path to C:\, and execute the DIR command using the following statements: Dim oShell Set oShell = CreateObject (“WSCript.shell”) oShell.run “cmd /K CD C:\ & Dir” Set oShell = Nothing 9) what is optional stepAns:

Description

Causes a step to be bypassed if an object in that step is not found.

Syntax

OptionalStep.StatementToMakeOptional

Example

The following example uses the OptionalStep object to make the Paris selection from the Depart WebList an optional step. OptionalStep.Browser(“Mercury Tours”).Page(“Find Flights”).WebList(“depart”).Select “Paris” 10)What is the alternative way to getROpropertyAns) object.QueryValue(property to get)11)How to get the number of childs in a tree a) Object.children.lengthex: Browser(“xxx”).Page(“xxx”).Image(“xxx”).Object.children.length11)How to know that the table has no recordsa) rs.RecordCount 12)What are the types of parameters available in QTPa) 3 types   1)  Action Parameters(Input ,output)These parameters are restricted to that action only.i.e we can not use them for another action.Note:Don’t think that the output action parameter can pass values between action.The only purpouse with output action parameter is to assign the values at run time rather than design time from the external source(application)Advantage: These parameters are bound to the action even this action is called from another test.How to Declare: Using Action property tabSyntax: Input parameter —variable= parameter(“name”)              Output parameter—Parameter(“name”)=value              2)  Test Parameters(Input ,output)These parameters are not restricted to that action i.e we can use them for any nother action.Note These parameters are not found and unable to use them in any action  is called from another test.Advantage: test  parameters can pass values between action.How to Declare: Using  Test Setting-à parameters tabSyntax: Input parameters—   variable= TestArgs (“name”)Output parameters–   TestArgs (“name”)=value3)Local ParametersThese are also same as test parameters but we need to Declare and use them from code not from IDE.Advantage:These parameters still can used even the actions are called from any testSyntax:Declarationà LocalParameter(“name”)=valueUse: variable= LocalParameter(“name”)13)what are the different ways to delay the execution steps in QTPAns)3 ways1) object.waitProperty ”propertyName”,”value”,”time in milli sec”This is called conditional wait  This will pauses the execution as long as the specified value of the property exist in the AUT or specified time out which ever is earlier2) Wait(seconds)This is called unconditional wait.i.e it will wait for the specified time3) Services.ThinkTime 10Same as wait14) How to minimize QTP while runninga) Set qtApp = CreateObject(“QuickTest.Application”)
    qtApp.WindowState = “Minimized”
     Set qtApp = Nothing

  Source: Mercury Forum’s KB articles

Author : Tarun Lalvani

February 14, 2008 Posted by | QTP Additional Faqs | , , , , , , , , | 5 Comments

DELETE ROWS FROM XL SHEET

DELETE ROWS FROM

 XL SHEET

 Public Function BIP_xlsDeleteRowRange (sSrcPath, sDestPath, sStartRow, sEndRow) ‘Create Excel object
Set oExcel = CreateObject(“Excel.Application”)
‘Sets the application to raise no app alerts
‘In this case it will allow a file overwrite w/o raising a ‘yes/no’ dialog
oExcel.DisplayAlerts = False

‘Open Book in Excel
Set oBook = oExcel.Workbooks.Open(sSrcPath)
‘Set Activesheet
Set oSheet = oExcel.Activesheet

‘Delete row range
oSheet.Rows(sStartRow +”:”+ sEndRow).Delete

‘Save new book to Excel file
oBook.SaveAs (sDestPath)

‘Close the xls file
oExcel.Workbooks.Close()

End Function 

February 14, 2008 Posted by | Excel Automation | , , , , , , , | 14 Comments