WORKING WITH QTP

TestEveryThinG

Archive for May, 2009

Create ZiP file VB QTP / UnZip file VB QTP

Posted by rajivkumarnandvani on May 13, 2009

Function WindowsUnZip(sUnzipFileName, sUnzipDestination)
Set oUnzipFSO = CreateObject(“Scripting.FileSystemObject”)
If Not oUnzipFSO.FolderExists(sUnzipDestination) Then
oUnzipFSO.CreateFolder(sUnzipDestination)
End If
With CreateObject(“Shell.Application”)
.NameSpace(sUnzipDestination).Copyhere .NameSpace(sUnzipFileName).Items
End With

Set oUnzipFSO = Nothing
End Function
Function WindowsZip(sFile, sZipFile)

Set oZipShell = CreateObject(“WScript.Shell”)
Set oZipFSO = CreateObject(“Scripting.FileSystemObject”)

If Not oZipFSO.FileExists(sZipFile) Then
NewZip(sZipFile)
End If

Set oZipApp = CreateObject(“Shell.Application”)

sZipFileCount = oZipApp.NameSpace(sZipFile).items.Count

aFileName = Split(sFile, “\”)
sFileName = (aFileName(Ubound(aFileName)))

‘listfiles
sDupe = False
For Each sFileNameInZip In oZipApp.NameSpace(sZipFile).items
If LCase(sFileName) = LCase(sFileNameInZip) Then
sDupe = True
Exit For
End If
Next

If Not sDupe Then
oZipApp.NameSpace(sZipFile).Copyhere sFile

‘Keep script waiting until Compressing is done
On Error Resume Next
sLoop = 0
Do Until sZipFileCount < oZipApp.NameSpace(sZipFile).Items.Count
Wscript.Sleep(100)
sLoop = sLoop + 1
Loop
On Error GoTo 0
End If
End Function

Sub NewZip(sNewZip)
Set oNewZipFSO = CreateObject(“Scripting.FileSystemObject”)
Set oNewZipFile = oNewZipFSO.CreateTextFile(sNewZip)

oNewZipFile.Write Chr(80) & Chr(75) & Chr(5) & Chr(6) & String(18, 0)

oNewZipFile.Close
Set oNewZipFSO = Nothing

Wscript.Sleep(500)
End Sub

WindowsZip “c:\rajiv.htm”, “c:\rajiv.zip”

Posted in Miscellaneous | Tagged: , , | 15 Comments »

Get Web Page label Error Message QTP

Posted by rajivkumarnandvani on May 13, 2009

REM This function get the label message text from Web page whose class ErrorMessage OR InformationMessage
REM  Input objParent := Object  Name of from which rquired the Message  like Page or Frame
REM  Output(ReturnType) := Label text  message
REM  Created:    22/Nov/2008    Rajiv Kumar Nandvani ## Changed:MM/DD/YYYY
REM  Example to call    fn_GetLabelMessageText(“objPageRMS”)

Public Function fn_GetLabelMessageText( byval objParent)

Dim objdesc , objCollection , objStyle ,nObjectCount  , sMessageText , sAllText ,i
REM create label WEB element object
set objdesc= Description.Create()
objdesc(“micclass”).value =”WebElement”
objdesc(“class”).value  =”ErrorMessage|Information|labelinfo|labelerroer”
objdesc(“innertext”).value =”.*[a-z].*”
REM create array of  web element object found in WEB page
Set objCollection = objParent.ChildObjects(objdesc)
REM count number of object
nObjectCount = objCollection.Count
For i =0 to nObjectCount -1
set objStyle  = objCollection(i).Object.CurrentStyle
If  objStyle.Color =”red” or objStyle.Color =”green” or objStyle.Color = “#367602” or objStyle.Color = “#000000”  Then
sMessageText = objCollection(i).GetROProperty(“innerText”)
End If
If sMessageText <>””  Then
sAllText = sAllText & ”  ” & sMessageText
End If
sMessageText =””
next
fn_GetLabelMessageText = sAllText
REM remove the object
Set objStyle =nothing
Set objCollection =nothing
Set objdesc =nothing

End Function
Rem **********************************************************************************************************

Posted in QTP | Tagged: , , | 9 Comments »

Close All Browser Except OLD One QTP VB

Posted by rajivkumarnandvani on May 13, 2009

Hi All,

Some time we required that Only OLD open Browser Window( Only for IE) will remain Open and rest of all shall be closed during QTP scripting. Here is the Function which will close the all open Browser except OLD Open browser (Work only for Internet Explorer using QTP)

Public function fn_CloseAllBrowserRemainingOLD

rem create Browser description object
Set brwsr=Description.Create
brwsr(“micclass”).value=”Browser”
Set obj=Desktop.ChildObjects(brwsr)
browserCount= obj.count
Set obj=nothing
If  browserCount >1  Then
do
Browser(“CreationTime:=1”).Close
Set obj=Desktop.ChildObjects(brwsr)
browserCount= obj.count
Set obj=nothing
loop  until  browserCount =1
End If

End Function

Posted in QTP, WEB | Tagged: , , | 6 Comments »

Close All Browser Except Latest One QTP VB

Posted by rajivkumarnandvani on May 13, 2009

Hi All,

Some time we required that Only Latest open Browser Window( Only for IE) will remain Open and rest of all shall be closed during QTP scripting. Here is the Function which will close the all open Browser except Latest Open browser (Work only for Internet Explorer using QTP)

Public function fn_CloseAllBrowserExceptLatest

rem create Browser description object

Set brwsr=Description.Create
brwsr(“micclass”).value=”Browser”

rem get  all open Browser collection in Object
Set obj=Desktop.ChildObjects(brwsr)
browserCount= obj.count
Set obj=nothing

rem check if open browser count greater then one or Not
If  browserCount >1Then

rem If greater than one then close all open browser except latest using Creation Time property in QTP
For a =0 to browserCount -2
Browser(“CreationTime:=”&a).Close
Next

End If

End function

Posted in QTP | Leave a Comment »

Execute the qtp scripts when the system is locked

Posted by rajivkumarnandvani on May 9, 2009

Change the following registry settings..
HKEY_LOCAL_MACHINE\SOFTWARE\Mercury Interactive\QuickTest Professional\MicTest
Locate the key “SkipEnvironmentChecks”

By Default the value will be “0”
Change the value to “1” and restart the QTP.
Now QTP can run even if the system is lock.

Posted in QTP | Tagged: , | 3 Comments »

Use Regular Expressions QTP

Posted by rajivkumarnandvani on May 5, 2009

Some Times QTP does not recognize the application object during second run  Or it run first time successfully then QTP gives an error cannot identified the application Window object properties does not match with the test object. There might be a case of window name /object name is getting changed each time. Here we required the use of regular expression. See the below example for more clarification

Regular Expression

Regular Expression

During Recording of  Flight application QTP record the flight application it identified the Fax order window name property like this

It Text Property is Fax order 11

If you run this script Again it will give an error because Fax order Window name will be

Fax order 12

Regular

Regular

Cannot identify the object “Fax Order No. 11” (of class Dialog). Verify that this object’s properties match an object currently displayed in your application.

Line (1): “Window(“Flight Reservation”).Dialog(“Fax Order No. 11″).Activate”.

Now we change text property to regular expression open Object properties from object repository  .Click on text property value cell

objectproperty

objectproperty

Check regular expression check box A message will appear click NO. Now change Text box value according to Regular expreesion.

Fax Order No. 11 to Fax Order No.*

Here each time only last part getting changed here we use .* as regular expression means it will check only Fax order No text not whole string

Same case we can  apply for different object properties if they are getting changed

A regular expression is a string that describes or matches a set of strings. It is often called a pattern as it describes set of strings.

Given underneath is one of the most widely used and ever confused BackLash character. The remaining expressions are serialized below that.

Using the Backslash Character
A backslash (\) instructs QuickTest to treat the next character as a literal character, if it is otherwise a special character. The backslash (\) can also instruct QuickTest to recognize certain ordinary characters as special characters. For example, QuickTest recognizes \n as the special newline character.
For example:
w matches the character w
\w is a special character that matches any word character including underscore
For example, in QTP, while entering the URL of a website,
http://mercurytours.mercuryinteractive.com
The period would be mistaken as an indication of a regular expression. To indicate that the period is not part of a regular expression, you would enter it as follows:
mercurytours\.mercuryinteractive\.com Note: If a backslash character is used before a character that has no special meaning, the backslash is ignored. For example, \z matches z.

Expressions & Explanation
Special characters and sequences are used in writing patterns for regular expressions. The following describes the characters and sequences that can be used\
Marks the next character as either a special character or a literal. For example, “n” matches the character “n”. “\n” matches a newline character. The sequence “\\” matches “\” and “\(” matches “(“.

^
Matches the beginning of input.

$
Matches the end of input.

*
Matches the preceding character zero or more times. For example, “zo*” matches either “z” or “zoo”.

+
Matches the preceding character one or more times. For example, “zo+” matches “zoo” but not “z”.

?
Matches the preceding character zero or one time. For example, “a?ve?” matches the “ve” in “never”.

.
Matches any single character except a newline character.

(pattern)
Matches pattern and remembers the match. The matched substring can be retrieved from the resulting Matches collection, using Item [0]…[n]. To match parentheses characters ( ), use “\(” or “\)”.

xy
Matches either x or y. For example, “zwood” matches “z” or “wood”. “(zw)oo” matches “zoo” or “wood”.

{n}
n is a nonnegative integer. Matches exactly n times. For example, “o{2}” does not match the “o” in “Bob,” but matches the first two o’s in “foooood”.

{n,}
n is a nonnegative integer. Matches at least n times. For example, “o{2,}” does not match the “o” in “Bob” and matches all the o’s in “foooood.” “o{1,}” is equivalent to “o+”. “o{0,}” is equivalent to “o*”.

{n,m}
m and n are nonnegative integers. Matches at least n and at most m times. For example, “o{1,3}” matches the first three o’s in “fooooood.” “o{0,1}” is equivalent to “o?”.

[xyz]
A character set. Matches any one of the enclosed characters. For example, “[abc]” matches the “a” in “plain”.

[^xyz]
A negative character set. Matches any character not enclosed. For example, “[^abc]” matches the “p” in “plain”.

[a-z]
A range of characters. Matches any character in the specified range. For example, “[a-z]” matches any lowercase alphabetic character in the range “a” through “z”.

[^m-z]
A negative range characters. Matches any character not in the specified range. For example, “[m-z]” matches any character not in the range “m” through “z”.

\b
Matches a word boundary, that is, the position between a word and a space. For example, “er\b” matches the “er” in “never” but not the “er” in “verb”.

\B
Matches a non-word boundary. “ea*r\B” matches the “ear” in “never early”.

\d
Matches a digit character. Equivalent to [0-9].

\D
Matches a non-digit character. Equivalent to [^0-9].

\f
Matches a form-feed character.

\n
Matches a newline character.

\r
Matches a carriage return character.

\s
Matches any white space including space, tab, form-feed, etc. Equivalent to “[ \f\n\r\t\v]”.

\S
Matches any nonwhite space character. Equivalent to “[^ \f\n\r\t\v]”.

\t
Matches a tab character.

\v
Matches a vertical tab character.

\w
Matches any word character including underscore. Equivalent to “[A-Za-z0-9_]”.

\W
Matches any non-word character. Equivalent to “[^A-Za-z0-9_]”.

\num
Matches num, where num is a positive integer. A reference back to remembered matches. For example, “(.)\1” matches two consecutive identical characters.

\n
Matches n, where n is an octal escape value. Octal escape values must be 1, 2, or 3 digits long. For example, “\11” and “11” both match a tab character. “011” is the equivalent of “01” & “1”. Octal escape values must not exceed 256. If they do, only the first two digits comprise the expression. Allows ASCII codes to be used in regular expressions.

\xn
Matches n, where n is a hexadecimal escape value. Hexadecimal escape values must be exactly two digits long. For example, “\x41” matches “A”. “\x041” is equivalent to “\x04” & “1”. Allows ASCII codes to be used in regular expressions

Posted in QTP | 22 Comments »

General Run Error QTP How to get details about it?

Posted by rajivkumarnandvani on May 5, 2009

If you have worked on QTP for some time you might have encountered errors like “General Run Error” which does not give any details regarding the error and testers often resort to using hit-and-try method to get the problem solved.
Instead, you can write a simple command to get the error number using err object. Just include this piece of code after the line where error occurred.

Msgbox Err.Number

This will throw the number code of the error. Now in all probability this error would not be documented in QTP’s help VB Script Run time Error Reference. (Otherwise QTP would not have thrown it “General”) Simply Google this error code and you can get the details and possibly how to resolve it.

Posted in QTP | Leave a Comment »

Addin Window not Appear When QTP Start

Posted by rajivkumarnandvani on May 5, 2009

1. Go to menu Tools->options following Window will appear

If check box not checked then it will shown in Display Add-in Manager on startup checkbox

addin

addin

Close the QTP and again open the QTP Application. Now on startup of QTP Addin window will Appear like this select requred Addinf as per need your application

addin Manager

addin Manager

Posted in QTP | 1 Comment »

QTP does not record the application

Posted by rajivkumarnandvani on May 5, 2009

  1. Make sure your application must be open after opening the QTP tool; otherwise QTP does not record the application. So always open QTP first and after this open the Application.
  2. Check Record and Run Options setting in QTP Tool setting

You can reach on this setting by Menu selecting Automation > Record and Run Settings.

Make sure your setting should be like this if not change according to it

QTP

QTP

Radio button selection should be Record and run test on any open Windows-based application.

1. Check Addis is loaded or not for your Application

First you should know which application you are going to record its WEB application or windows application

For Web Application following Addin should be loaded( In RMS)

Web

.Net

.WPF

Active X

Java

For Windows Application following Addin should be loaded (In RMS)

.WPF (GIS)

.Net   (GIS)

Visual Basic

Active X

Check addin is loaded or not by menu option select File->Setting

Addin

Addin

Check addin is checked or not If not then do the following steps

1. Go to menu Tools->options following Window will appear

If check box not checked then it will shown in Display Add-in Manager on startup checkbox

addin

addin

Close the QTP and again open the QTP Application. Now on startup of QTP Addin window will Appear like this select requred Addinf as per need your application

addin Manager

addin Manager

Posted in FAQ QTP, QTP | Tagged: | 59 Comments »

Close Application Process QTP

Posted by rajivkumarnandvani on May 3, 2009

REM This function kill the given process exe  through task manager
rem example call  fn_CloseApplication(“EXCEL.EXE”)

Public Function  fn_CloseApplication( byval sApplicationExe)
Dim strComputer
Dim objWMIService
Dim colProcesses
Dim objProcess
strComputer = “.”
Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\cimv2”)

Set colProcesses = objWMIService.ExecQuery (“Select * from Win32_Process Where Name = ‘”&sApplicationExe&”‘”)
For Each objProcess in colProcesses
objProcess.Terminate()
Next
Set objWMIService = Nothing
Set colProcesses=Nothing
End Function

Posted in QTP | Tagged: , | 5 Comments »