WORKING WITH QTP

TestEveryThinG

Archive for the ‘WINDOWS’ Category

Available Android app of Testeverything Site

Posted by rajivkumarnandvani on July 26, 2016

Hi,

Now you view the TestEverything Site updates on your Android mobile.just download the android app

Please refer the below link to download the apk file of  Teverything Site.

https://drive.google.com/file/d/0B27kZ9NQHijSQnJtc1RYdGVyR2M/view?usp=sharing

Download TesteveryThing APK file
TesteveryThing APK

Posted in Automation, DATABASE, FAQ QTP, Jenkins, JMETER, Miscellaneous, QTP, QTP FAQ, SELENIUM, WEB, WEBDRIVER, WINDOWS | Tagged: , , , | Leave a Comment »

Compare bitmap file using QTP ( using Mercury.FileCompare object )

Posted by rajivkumarnandvani on June 17, 2010

Hi All,
We can use QTP in-build method for File compare with the help of Mercury.FileCompare.
Here I am going to describe how to use that.

Rem variable to store the location of the expected bitmap file
strstoreBMPfile = “D:\rajivkumarnandvani.bmp”

Rem variable to store the location of the actual bitmap file
strActBMPfile = “D:\rajiv\runtimebmpfile.bmp”

Rem Activate the window

Window(“Flight Reservation”).Activate

Rem Capture the actual bitmap image from the application during run-time
Window(“Flight Reservation”).Static(“Static”).CaptureBitmap strActBMPfile , True

Rem here True will overwrite the file
Rem here we write the function for compare the bitmap file using qtp inbuild method Mercury.FileCompare.
Rem Function FnCompareTwoBMPfiles
Rem Description: this function Compares two bitmap images
Rem input pathExpBMPfile path of Expected bmp file
Rem input pathActBMPfile path of Actual bmp file
Rem return value 1 if both file are same ; 0 if different

Function FnCompareTwoBMPfiles( byval pathExpBMPfile , byval pathActBMPfile)
rem create qtp file system object
Set objMercuryFilecompare = CreateObject(“Mercury.FileCompare”)
rem here we use binary compare
if objMercuryFilecompare.IsEqualBin( pathExpBMPfile , pathActBMPfile , 0,1) Then
rem if match then return 1
FnCompareTwoBMPfiles = 1
else
rem if does not match then return 0
FnCompareTwoBMPfiles = 0
end if
rem discard the object
Set objMercuryFilecompare = nothing
End Function

Rem now we call this function

if FnCompareTwoBMPfiles(strstoreBMPfile ,strActBMPfile) = 1 then
msgbox “ BMP file match”

else
msgbox “BMP file not match”
end IF
Rem same thing we can use for other files also.

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

Use Send Key Method QTP VB

Posted by rajivkumarnandvani on June 15, 2009

Hi All,

Some time we requre keyboard event in Automation so we can use Send key method

rem **********************************************

rem create shell object

set WshShell = CreateObject(“WScript.Shell”)

SystemUtil.Run “C:\Program Files\HP\QuickTest xcxProfessional\samples\flight\app\flight4a.exe”,”C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe”,””,””

rem first click in the text box then use send key method

Dialog(“text:=Login”).WinEdit(“attached text:=Agent Name:”).Click

rem enter rajiv in agent name text box

WshShell.SendKeys “rajiv”

rem click Password Edit box

Dialog(“text:=Login”).WinEdit(“attached text:=Password:”).Click

rem enter check in Password text box

WshShell.SendKeys “check ”

Dialog(“text:=Login”).WinButton(“text:=OK”).Click

rem press escape using send key method

WshShell.SendKeys “{ESC}”

WshShell.SendKeys “{ESC}”

rem **********************************************************

Use the SendKeys method to send keystrokes to applications that have no automation interface. Most keyboard characters are represented by a single keystroke. Some keyboard characters are made up of combinations of keystrokes (CTRL+SHIFT+HOME, for example). To send a single keyboard character, send the character itself as the string argument. For example, to send the letter x, send the string argument “x”.

Note To send a space, send the string ” “.

You can use SendKeys to send more than one keystroke at a time. To do this, create a compound string argument that represents a sequence of keystrokes by appending each keystroke in the sequence to the one before it. For example, to send the keystrokes a, b, and c, you would send the string argument “abc”. The SendKeys method uses some characters as modifiers of characters (instead of using their face-values). This set of special characters consists of parentheses, brackets, braces, and the:

  • plus sign       “+”,
  • caret             “^”,
  • percent sign “%”,
  • and tilde       “~”

Send these characters by enclosing them within braces “{}”. For example, to send the plus sign, send the string argument “{+}”. Brackets “[ ]” have no special meaning when used with SendKeys, but you must enclose them within braces to accommodate applications that do give them a special meaning (for dynamic data exchange (DDE) for example).

  • To send bracket characters, send the string argument “{[}” for the left bracket and “{]}” for the right one.
  • To send brace characters, send the string argument “{{}” for the left brace and “{}}” for the right one.

Some keystrokes do not generate characters (such as ENTER and TAB). Some keystrokes represent actions (such as BACKSPACE and BREAK). To send these kinds of keystrokes, send the arguments shown in the following table:

Key Argument
BACKSPACE {BACKSPACE}, {BS}, or {BKSP}
BREAK {BREAK}
CAPS LOCK {CAPSLOCK}
DEL or DELETE {DELETE} or {DEL}
DOWN ARROW {DOWN}
END {END}
ENTER {ENTER} or ~
ESC {ESC}
HELP {HELP}
HOME {HOME}
INS or INSERT {INSERT} or {INS}
LEFT ARROW {LEFT}
NUM LOCK {NUMLOCK}
PAGE DOWN {PGDN}
PAGE UP {PGUP}
PRINT SCREEN {PRTSC}
RIGHT ARROW {RIGHT}
SCROLL LOCK {SCROLLLOCK}
TAB {TAB}
UP ARROW {UP}
F1 {F1}
F2 {F2}
F3 {F3}
F4 {F4}
F5 {F5}
F6 {F6}
F7 {F7}
F8 {F8}
F9 {F9}
F10 {F10}
F11 {F11}
F12 {F12}
F13 {F13}
F14 {F14}
F15 {F15}
F16 {F16}

To send keyboard characters that are comprised of a regular keystroke in combination with a SHIFT, CTRL, or ALT, create a compound string argument that represents the keystroke combination. You do this by preceding the regular keystroke with one or more of the following special characters:

Key Special Character
SHIFT +
CTRL ^
ALT %

Note When used this way, these special characters are not enclosed within a set of braces.

To specify that a combination of SHIFT, CTRL, and ALT should be held down while several other keys are pressed, create a compound string argument with the modified keystrokes enclosed in parentheses. For example, to send the keystroke combination that specifies that the SHIFT key is held down while:

  • e and c are pressed, send the string argument “+(ec)”.
  • e is pressed, followed by a lone c (with no SHIFT), send the string argument “+ec”.

You can use the SendKeys method to send a pattern of keystrokes that consists of a single keystroke pressed several times in a row. To do this, create a compound string argument that specifies the keystroke you want to repeat, followed by the number of times you want it repeated. You do this using a compound string argument of the form {keystroke number}. For example, to send the letter “x” ten times, you would send the string argument “{x 10}”. Be sure to include a space between keystroke and number.

Note The only keystroke pattern you can send is the kind that is comprised of a single keystroke pressed several times. For example, you can send “x” ten times, but you cannot do the same for “Ctrl+x”.

Note You cannot send the PRINT SCREEN key {PRTSC} to an application.

Mobile

Posted in WINDOWS | Tagged: , , | 105 Comments »

Work With List Box QTP

Posted by rajivkumarnandvani on May 3, 2009

When we use list box Object in QTP. QTP perform following operation on listbox . like

Browser(“Browser”).Page(“Page”)..WebList(“ListBox”).Select “ListBoxValue”

It select the value from List Box that value must be present in list box otherwise QTP give an error like that

“Cannot identify the specified item of the ListBox object. Confirm that the specified item is included in the object’s item collection.”

So before selection any value in list box Always insure the value you are going to select in list box must be present by use this method/Function

dim objListBox, sValuematch ,bTrue
set objListBox = Browser(“Browser”).Page(“Page”)..WebList(“ListBox”)
sValuematch =”Type Value that need to be check”
bTrue = fn_Valuematch_for_weblistbx(objListBox ,sValuematch )
if bTrue =True then
Browser(“Browser”).Page(“Page”)..WebList(“ListBox”).Select “ListBoxValue”
end if

REM*************************************************************************************************************
REM ” this function Check the value u define match With in WEBListbox or Not if match return true otherwise False
Public Function fn_Valuematch_for_weblistbx(byval m_listboxobject, byval m_valuematch)
”check is m_listboxobject object or not
If IsObject(m_listboxobject ) = true and IsNull(m_valuematch) = false Then
Dim m_Getallfield,m_arAllfield,m_val,m_actual
m_arAllfield = m_listboxobject.GetROProperty(“all items”)
m_arAllfield =Split (m_arAllfield,”;”)
For each element in m_arAllfield
If m_valuematch = element then ‘ compare the text
fn_Valuematch_for_weblistbx=true ” if value match then return true & exit thr loop
exit for
else
fn_Valuematch_for_weblistbx = false
end if
Next
else
print “Error wrong Parameter for function fn_Valuematch_for_listbx”,”Check paramenter value”
End If
End Function
REM*************************************************************************************************************

Posted in QTP, WEB, WINDOWS | Tagged: , , | 21 Comments »

Work With text box( Windows WinEdit box) QTP

Posted by rajivkumarnandvani on May 3, 2009

In most cases, double-clicking on a data input field is the preferable method of selection; furthermore, it is usually necessary versus a single mouse click on the object. Double –clicking selects the all of the data in that field so that it can be replaced with the new data. A single- click operation, may only place the cursor in the input control , selecting none of the existing data and normally activates the insert mode . Not good. The existing data is not replaced with the new value. In some applications where multiple words or value separated by spaces can lives in a single edit box. We have found the even double-clicking may not get all of the text selected and ready for replacement. In this case, the method that consistently ensures that all of the data is selected is this: navigate to control via keyboard control, such as tabbing, right arrow or mouse click. Once the cursor is placed into the control, record these keystrokes:

Ctrl + Home
Ctrl + Shift + End
Delete

Like
Dialog(“Login”).WinEdit(“Agent Name:”).Type micCtrlDwn + micHome + micCtrlUp
Dialog(“Login”).WinEdit(“Agent Name:”).Type micCtrlDwn + micShiftDwn + micEnd + micShiftUp + micCtrlUp

Posted in Miscellaneous, QTP, WINDOWS | Tagged: , | Leave a Comment »

Get current DATETIME through VB QTP/Create unique file or folder

Posted by rajivkumarnandvani on April 17, 2009

Some Time we want create a folder Or File with unique name then we current date time value for creating the file or folder that we can use this method for create the file OR folder as decribed here

REM this function return the current date time in text format

REM  Function  fn_GetDateTimeText() This function return currentdatetime in Text format
REM  this will remove the specail charactor from currentdatetime & replace with _ underscore
REM  Input              := None
REM  Output(ReturnType) := return currentdatetime in Text format

Public Function fn_GetDateTimeText

Dim sDateTime
sDateTime = now
sDateTime =replace(sDateTime,”:”,”_”)
sDateTime =replace(sDateTime,”>”,”_”)
sDateTime =replace(sDateTime,”<“,”_”)
sDateTime =replace(sDateTime,”/”,”_”)
sDateTime =replace(sDateTime,”|”,”_”)
sDateTime =replace(sDateTime,”\”,”_”)
sDateTime =replace(sDateTime,”*”,”_”)
sDateTime =replace(sDateTime,””””,”_”)
sDateTime =replace(sDateTime,”#”,””)
fn_GetDateTimeText =sDateTime
End Function

dim sGetCurrentDateTime

sGetCurrentDateTime = fn_GetDateTimeText()

Set objFSO =CreateObject(“Scripting.FileSystemObject”)

rem create text file

objFSO.CreateTextFile(“c:/” & sGetCurrentDateTime & “.txt” , True)

rem create folder

objFSO.CreateFolder(“c:/” & sGetCurrentDateTime & “.txt” , True)

Posted in QTP, WINDOWS | Tagged: , , , , , , | 1 Comment »

Handle popup window QTP VB

Posted by rajivkumarnandvani on April 11, 2009

REM *************************************************************************
REM  Function  fn_GetPopupMessageText() This function Get the lable textmessage from Popup Dialog window  in Browser page
REM  and enter the label text in Result Excel Sheet
REM Note Dialog Window Must be child of  Parent object

REM  Input              := None
REM  Output(ReturnType) := None
REM  Created:    11/April/2009    Rajiv Kumar Nandvani ## Changed:MM/DD/YYYY

REM *************************************************************************

Call fn_GetPopupMessageText()
Public function fn_GetPopupMessageText()
Set objStaticText =Description.Create()
objStaticText(“nativeclass”).value =”Static”
objStaticText(“text”).value =”.*[a-z].*”
Set objWinbutton =Description.Create()
objWinbutton(“micclass”).value =”WinButton”
If Window(“regexpwndtitle:=Windows Internet Explorer”,”regexpwndclass:=IEFrame”).Dialog(“regexpwndtitle:=Windows Internet Explorer”,”regexpwndclass:=#32770″).Exist(2) then
Window(“regexpwndtitle:=Windows Internet Explorer”,”regexpwndclass:=IEFrame”).Dialog(“regexpwndtitle:=Windows Internet Explorer”,”regexpwndclass:=#32770″).Activate
set objStaticText = Window(“regexpwndtitle:=Windows Internet Explorer”,”regexpwndclass:=IEFrame”).Dialog(“regexpwndtitle:=Windows Internet Explorer”,”regexpwndclass:=#32770″).ChildObjects(objStaticText)
For i=0 to objStaticText.count-1
sDescription =objStaticText(i).GetVisibleText(-1,-1,-1,-1)
Next
set objWinbutton = Window(“regexpwndtitle:=Windows Internet Explorer”,”regexpwndclass:=IEFrame”).Dialog(“regexpwndtitle:=Windows Internet Explorer”,”regexpwndclass:=#32770″).ChildObjects(objWinbutton)
For i=0 to objWinbutton.count-1
objWinbutton(i).click
Exit for
Next
fn_GetPopupMessageText = sDescription
End if
End Function

Public function fn_GetPopupMessageText()
Set objStaticText =Description.Create()
objStaticText(“nativeclass”).value =”Static”
objStaticText(“text”).value =”.*[a-z].*”
Set objWinbutton =Description.Create()
objWinbutton(“micclass”).value =”WinButton”
If Browser(“title:=.*(Page).*”).Dialog(“text:=Windows Internet Explorer”,”nativeclass:=#32770″).Exist(2) then
Browser(“title:=.*(Page).*”).Dialog(“text:=Windows Internet Explorer”,”nativeclass:=#32770″).Activate
set objStaticText = Browser(“title:=.*(Page).*”).Dialog(“text:=Windows Internet Explorer”,”nativeclass:=#32770″).ChildObjects(objStaticText)
For i=0 to objStaticText.count-1
sDescription =objStaticText(i).GetVisibleText(-1,-1,-1,-1)
Next
set objWinbutton = Browser(“title:=.*(Page).*”).Dialog(“text:=Windows Internet Explorer”,”nativeclass:=#32770″).ChildObjects(objWinbutton)
For i=0 to objWinbutton.count-1
objWinbutton(i).click
Exit for
Next

fn_GetPopupMessageText = sDescription
End if

End Function

Posted in QTP, WEB, WINDOWS | Tagged: , | 1 Comment »

Read Value from Registory

Posted by rajivkumarnandvani on February 6, 2009

Here we can get the loaction where QTP installed

Set objFSO =CreateObject(“Scripting.FileSystemObject”)

Set WshShell = CreateObject(“WScript.Shell”)
sKey =”HKLM\SOFTWARE\Mercury Interactive\QuickTest Professional\Configuration_UI\Packages\WebFormsPackage\Settings\ConfigurationFile”
sQTPpath= WshShell.RegRead(sKey)

msgbox sQTPpath

set WshShell =nothing

set objFSO=nothing

Posted in QTP, WINDOWS | Tagged: , , | Leave a Comment »

Working with files(FileSystemObject)

Posted by rajivkumarnandvani on February 6, 2009


There are two major categories of file manipulation:

  • Creating, adding, or removing data, and reading files
  • Moving, copying, and deleting files

Creating Files

There are three ways to create an empty text file (sometimes referred to as a “text stream”).

The first way is to use the CreateTextFile method. The following example demonstrates how to create a text file using the CreateTextFileMethod method.

[VBScript]
Dim fso, f1
Set fso = CreateObject("Scripting.FileSystemObject")
Set f1 = fso.CreateTextFile("c:\testfile.txt", True)
[JScript]
var fso, f1;
fso = new ActiveXObject("Scripting.FileSystemObject");
f1 = fso.CreateTextFile("c:\\testfile.txt", trThe second way to create a text file is to use the OpenTextFile method of the FileSystemObject object with the ForWriting flag set.
[VBScript
Dim fso, ts
Const ForWriting = 2
Set fso = CreateObject("Scripting. FileSystemObject")
Set ts = fso.OpenTextFile("c:\test.txt", ForWriting, True)
[JScript]var fso, ts;var ForWriting= 2;fso = new ActiveXObject("Scripting.FileSystemObject")ts = fso.OpenTextFile("c:\\test.txt", ForWriting, true);

A third way to create a text file is to use the OpenAsTextStream method with the ForWriting flag set.

[VBScript]
Dim fso, f1, ts
Const ForWriting = 2
Set fso = CreateObject("Scripting.FileSystemObject")
fso.CreateTextFile ("c:\test1.txt")
Set f1 = fso.GetFile("c:\test1.txt")
Set ts = f1.OpenAsTextStream(ForWriting, True[JScript]var fso, f1, ts;var ForWriting = 2fso = new ActiveXObject("Scripting.FileSystemObject")fso.CreateTextFile ("c:\\test1.txt");f1 = fso.GetFile("c:\\test1.txt");ts = f1.OpenAsTextStream(ForWriting, true);

Adding Data to the File

Once the text file is created, add data to the file using the following three steps:

Open the text file.

Write the data.

Close the file.

To open an existing file, use either the OpenTextFile method of the FileSystemObject object or the OpenAsTextStream method of the File object.

To write data to the open text file, use the Write, WriteLine, or WriteBlankLines methods of the TextStream object, according to the tasks outlined in the following table.

Task

Method

Write data to an open text file without a trailing newline character.

Write

Write data to an open text file with a trailing newline character.

WriteLine

Write one or more blank lines to an open text file.

WriteBlankLines

To close an open file, use the Close method of the TextStream object.

Note The newline character contains a character or characters (depending on the operating system) to advance the cursor to the beginning of the next line (carriage return/line feed). Be aware that the end of some strings may already have such nonprinting characters.

The following example demonstrates how to open a file, use all three write methods to add data to the file, and then close the file:

[VBScript]
Sub CreateFile()
   Dim fso, tf
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set tf = fso.CreateTextFile("c:\testfile.txt", True)
   ' Write a line with a newline character.
   tf.WriteLine("Testing 1, 2, 3.") 
   ' Write three newline characters to the file.        
   tf.WriteBlankLines(3) 
   ' Write a line.
   tf.Write ("This is a test.") 
   tf.Close
End Sub
[JScript]function CreateFile(){   var fso, t   fso = new ActiveXObject("Scripting.FileSystemObject");   tf = fso.CreateTextFile("c:\\testfile.txt",    // Write a line with a newline character.   tf.WriteLine("Testing 1, 2, 3.") ;   // Write three newline characters to the file.   tf.WriteBlankLines(3) ;   // Write a line   tf.Write ("This is a test.");   tf.Close()}

Reading Files

To read data from a text file, use the Read, ReadLine, or ReadAll method of the TextStream object. The following table describes which method to use for various tasks.

Task

Method

Read a specified number of characters from a file.

Read

Read an entire line (up to, but not including, the newline character).

ReadLine

Read the entire contents of a text file.

ReadAll

If you use the Read or ReadLine method and want to skip to a particular portion of data, use the Skip or SkipLine method. The resulting text of the read methods is stored in a string which can be displayed in a control, parsed by string functions (such as Left, Right, and Mid), concatenated, and so forth.

The following example demonstrates how to open a file, write to it, and then read from it:

[VBScript]
Sub ReadFiles
   Dim fso, f1, ts, s
   Const ForReading = 1
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set f1 = fso.CreateTextFile("c:\testfile.txt", True)
   ' Write a line.
   Response.Write "Writing file <br>"
   f1.WriteLine "Hello World"
   f1.WriteBlankLines(1)
   f1.Close
   ' Read the contents of the file.
   Response.Write "Reading file <br>"
   Set ts = fso.OpenTextFile("c:\testfile.txt", ForReading)
   s = ts.ReadLine
   Response.Write "File contents = '" & s & "'"
   ts.Close
End Sub
[JScript]function ReadFiles(){   var fso, f1, ts, s;   var ForReading = 1;   fso = new ActiveXObject("Scripting.FileSystemObject");   f1 = fso.CreateTextFile("c:\\testfile.txt", true);   // Write a line.   Response.Write("Writing file <br>");   f1.WriteLine("Hello World");   f1.WriteBlankLines(1);   f1.Close();   // Read the contents of the file.   Response.Write("Reading file <br>");   ts = fso.OpenTextFile("c:\\testfile.txt", ForReading);   s = ts.ReadLine()   Response.Write("File contents = '" + s + "'")   ts.Close();}

Moving, Copying, and Deleting Files

The FSO object model has two methods each for moving, copying, and deleting files, as described in the following table.

Task

Method

Move a file

File.Move or FileSystemObject.MoveFile

Copy a file

File.Copy or FileSystemObject.CopyFile

Delete a file

File.Delete or FileSystemObject.DeleteFile

The following example creates a text file in the root directory of drive C, writes some information to it, moves it to a directory called \tmp, makes a copy of it in a directory called \temp, then deletes the copies from both directories.

To run the following example, create directories named \tmp and \temp in the root directory of drive C:

[VBScript]
Sub ManipFiles
   Dim fso, f1, f2, s
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set f1 = fso.CreateTextFile("c:\testfile.txt", True)
   Response.Write "Writing file <br>"
   ' Write a line.
   f1.Write ("This is a test.")
   ' Close the file to writing.
   f1.Close
   Response.Write "Moving file to c:\tmp <br>"
   ' Get a handle to the file in root of C:\.
   Set f2 = fso.GetFile("c:\testfile.txt")
   ' Move the file to \tmp directory.
   f2.Move ("c:\tmp\testfile.txt")
   Response.Write "Copying file to c:\temp <br>"
   ' Copy the file to \temp.
   f2.Copy ("c:\temp\testfile.txt")
   Response.Write "Deleting files <br>"
   ' Get handles to files' current location.
   Set f2 = fso.GetFile("c:\tmp\testfile.txt")
   Set f3 = fso.GetFile("c:\temp\testfile.txt")
   ' Delete the files.
   f2.Delete
   f3.Delete
   Response.Write "All done!"
End Sub

Posted in QTP, WINDOWS | Tagged: , , , , , | Leave a Comment »

Folder Count method

Posted by rajivkumarnandvani on February 5, 2009

Dim fs ‘ variable declared outside a procedure (this is a global variable)
‘ this is hold a reference to the file system object
‘ create an instance
Set fs = CreateObject(“scripting.filesystemobject”)
‘ count files in windows directory
MsgBox CountFiles (“C:\Program Files\ESL India Ltd\BillingSaaClient\SAA\output”)
‘ takes a string argument containing the name of the directory

‘ returns an integer contiang the nubmer of files in that direcrectory

‘ and all sub directories

Function CountFiles (ByVal StrFolder)
Dim ParentFld
Dim SubFld
Dim IntCount
‘ note the use of the fs global variable

Set ParentFld = fs.GetFolder (StrFolder)
‘ count the number of files in the current directory

IntCount = ParentFld.subfolders.Count

For Each SubFld In ParentFld.SubFolders

‘ count all files in each subfolder – recursion point

IntCount = IntCount + CountFiles(SubFld.Path)

Next

‘ return counted files

CountFiles = IntCount

End Function

Posted in QTP, WINDOWS | Tagged: , , , , , | Leave a Comment »