TESTEVERYTHING

Tuesday 31 May 2011

QTP does not record the application

  1. Make sure your application must be open after opening the QTP tool; otherwise QTP does not record the application. So always open the QTP first then open the Application.
  2.  
  3. 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


Monday 23 May 2011

Close All Browsers Except OLD One QTP VB

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


Public function fn_CloseAllBrowsersExceptOLD
      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

call  fn_CloseAllBrowsersExceptOLD( )

Handle Popup Dialog window in Browser QTP

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

Sunday 22 May 2011

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

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.

Execute() and Eval() statements in QTP

Eval()
Evaluates an expression and returns the result.

Eval always take the "=" as comparision
while the execute take the "=" as assignment

In VBScript, x = y can be interpreted two ways. The first is as an assignment statement, where the value of y is assigned to x. The second interpretation is as an expression that tests if x and y have the same value. If they do, result is True; if they are not, result is False. The Execute statement always uses the first interpretation, whereas the Eval method always uses the second.

call evalexecute()
Sub evalexecute
   Dim z
   z = "4"
   print eval("z=5")   & "---  Eval Print  - should return False "
   print eval("z=4")   & "---  Eval Print  - should return True "
   print z    & "---  Eval Print  - value of z should be unchanged"
   print execute ("z=8")   & "- should be blank as execute will not return anything"
   print z     & "---  Eexcute Print - should print 8" 
End Sub
 

Saturday 21 May 2011

Dictionary Object in QTP

Dictionary object is similar to a typical array. The difference between a dictionary object and an array is that there is a unique key associated with every item of dictionary object. This unique key can help you in calling that item as and whenever required.

In arrays we store the values based upon the index i.e. 0,1,2 but here we can store the values based upon the names i.e. keys. Each value is stored corresponding to the unique keys. Dictionary object that stores data in key, item pairs.

Dictionary objects are very useful when dealing with the large no of data. On an average they are 3 times faster then the collection objects

Every key should be unique. Duplicate keys are not allowed. Dictionary object belong to "Scripting.Dictionary" class. To create a dictionary object we can use the following statement:

REM Create a variable.
Dim objDict
REM Create dictionary object
Set objDict=CreateObject("Scripting.Dictionary")

Following are the methods available with the Dictionary Objects:
Add Method,Exists Method, Items Method, Keys Method, Remove Method, RemoveAll Method

REM  Adding keys and corresponding items. 

objDict.Add “Company”, “TEST”
objDict.Add “Name”, “Rajiv”
objDict.Add “Blog”, “QTP” 




Using Exists Method to check whether the key 'Company' exists?

If  objDict.Exists(“Company”) Then
   msgbox “Specified key exists.”
Else
   msgbox “Specified key doesn’t exist.”

End If"

Retrieve ALL items and keys respectively from inside dictionary object.

REM Get the items.
allItems = objDict.Items
REM  Get the keys.
allkeys= objDict.Keys

REM Iterate the array.
For x = 0 To objDict.Count-1
    msgbox  allItems(x) & ” :” & allkeys(x)
Next

Using Remove method

objDict.Remove("Company")

 Now it will return false because we have deleted the key.

  msgbox objDict.Exists(“Company”)

Using Remove all method to clear the dictionary

REM Clear the dictionary.
objDict.RemoveAll

Launch QTP by VB Script

Hi All,
Some times we required to launch QTP via Script . Here i am showing how to launch QTP via VB script. We can use this for load Library file/ Object repository / Recovery  at qtp Startup. Just copy the script and save the file with .vbs extension
open the vbs file with microsoft based script host OR wsh

REM This function closes all previous instances/processes of QTP one by one

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
rem  call  function fn_CloseApplication  for closing the already(if any) opened instances/processes of QTP

call fn_CloseApplication( “QTPro.exe”)
call fn_CloseApplication( “QTAutomationAgent.exe”)

rem  launch QTP
Set objQtpApp = CreateObject(“QuickTest.Application”)
objQtpApp.Launch
objQtpApp.Visible = True
‘ check the QTP settings
objQtpApp.Test.Settings.Launchers(“Web”).Active = False
objQtpApp.Test.Settings.Launchers(“Web”).Browser = “IE”
objQtpApp.Test.Settings.Launchers(“Web”).Address = “http://newtours.mercury.com “
objQtpApp.Test.Settings.Launchers(“Web”).CloseOnExit = True
objQtpApp.Test.Settings.Launchers(“Windows Applications”).Active = False
objQtpApp.Test.Settings.Launchers(“Windows Applications”).Applications.RemoveAll
objQtpApp.Test.Settings.Launchers(“Windows Applications”).RecordOnQTDescendants = True
objQtpApp.Test.Settings.Launchers(“Windows Applications”).RecordOnExplorerDescendants = False
objQtpApp.Test.Settings.Launchers(“Windows Applications”).RecordOnSpecifiedApplications = True
objQtpApp.Test.Settings.Run.IterationMode = “rngAll”
objQtpApp.Test.Settings.Run.StartIteration = 1
objQtpApp.Test.Settings.Run.EndIteration = 1
objQtpApp.Test.Settings.Run.ObjectSyncTimeOut = 20000
objQtpApp.Test.Settings.Run.DisableSmartIdentification = False
objQtpApp.Test.Settings.Run.OnError = “Dialog”
objQtpApp.Test.Settings.Resources.DataTablePath = “<Default>”
objQtpApp.Test.Settings.Resources.Libraries.RemoveAll
objQtpApp.Test.Settings.Resources.Libraries.SetAsDefault
objQtpApp.Test.Settings.Web.BrowserNavigationTimeout = 60000
objQtpApp.Test.Settings.Web.ActiveScreenAccess.UserName = “”
objQtpApp.Test.Settings.Web.ActiveScreenAccess.Password = “”

Monday 16 May 2011

Date Time Functions In Visual Basic / QTP

The following functions isolate the date portion and time portion, respectively, of a Date/Time value:

Function

Description

DateValue Returns the date portion of a Date/Time value, with the time portion “zeroed out”. (Note: When the time portion of a date/time variable is “zeroed out”, the time would be interpreted as 12:00 AM.) Example:
Dim dtmTest As Date
dtmTest = DateValue(Now)
At this point, the date portion of dtmTest is 8/31/2001, with a time portion of 0 (12:00 AM midnight).
TimeValue Returns the time portion of a Date/Time value, with the date portion “zeroed out”. (Note: When a date/time variable is “zeroed out”, the date will actually be interpreted as December 30, 1899.) Example:
Dim dtmTest As Date
dtmTest = TimeValue(Now)
At this point, the time portion of dtmTest is 9:15:20 PM, with a date portion of 0 (12/30/1899).
The following functions are used to isolate a particular part of a date:

Function

Description

Weekday Returns a number from 1 to 7 indicating the day of the week for a given date, where 1 is Sunday and 7 is Saturday. Example:
intDOW = Weekday(Now) ‘ intDOW = 6
Note:
When necessary to refer to a day of the week in code, VB has a set of built-in constants that can be used instead of the hard-coded values 1 thru 7:
Constant Value
vbSunday 1
vbMonday 2
vbTuesday 3
vbWednesday 4
vbThursday 5
vbFriday 6
vbSaturday 7

Function

Description

WeekdayName Returns a string containing the weekday name (“Sunday” thru “Saturday”), given a numeric argument with the value 1 through 7. Example:
strDOW = WeekdayName(6) ‘ strDOW = “Friday”
The WeekdayName function takes an optional, second argument (Boolean) indicating whether or not to abbreviate the weekday name. By default, the second argument is False, meaning do not abbreviate and return the full name. If True, the first three letters of the weekday name will be returned:
Example:
strDOW = WeekdayName(6, True) ‘ strDOW = “Fri”
You can nest the Weekday function within the WeekdayName function to get the weekday name for a given date:
Example:
strDOW = WeekdayName(Weekday(Now)) ‘ strDOW = “Friday”
Month Returns a number from 1 to 12 indicating the month portion of a given date. Example:
intMonth = Month(Now) ‘ intMonth = 8
MonthName Returns a string containing the month name (“January” thru “December”), given a numeric argument with the value 1 through 12. Example:
strMoName = MonthName(8) ‘ strMoName = “August”
The MonthName function takes an optional, second argument (Boolean) indicating whether or not to abbreviate the month name. By default, the second argument is False, meaning do not abbreviate and return the full name. If True, the first three letters of the month name will be returned:
Example:
strMoName = MonthName(8, True) ‘ strMoName = “Aug”
You can nest the Month function within the MonthName function to get the month name for a given date:
Example:
strMoName = MonthName(Month(Now)) ‘ strMoName = “August”
Day Returns a number from 1 to 31 indicating the day portion of a given date. Example:
intDay = Day(Now) ‘ intDay = 31
Year Returns a number from 100 to 9999 indicating the year portion of a given date. Example:
intYear = Year(Now) ‘ intYear = 2001
The following functions are used to isolate a particular part of a time:

Function

Description

Hour Returns an integer specifying a whole number between 0 and 23 representing the hour of the day. Example:
intHour = Hour(Now) ‘ intHour = 21 (for 9 PM)
Minute Returns an integer specifying a whole number between 0 and 59 representing the minute of the hour. Example:
intMinute = Minute(Now) ‘ intMinute = 15
Second Returns an integer specifying a whole number between 0 and 59 representing the second of the minute. Example:
intSecond = Second(Now) ‘ intSecond = 20

Sunday 15 May 2011

Create ZiP file VB QTP / UnZip file VB QTP

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)))
    REM  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
     REM  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”

Scroll the page using QTP / Scroll bar handling

Hi All,

Sometimes in application we need to scroll the page or object grid list item. Like in search result of Google page next link comes at the end of the page. For click the next page link we have to scroll the page. In that case QTP does not record scroll down event. Usually it’s seen that QTP identifies the object in the page irrespective of scroll down.

But some times it does not work for items list in grid. OR it will take time. For this we can use scrollintoview method. It will automatically scroll the page up to object view.


Like:

Browser(“Google”).Page(“testeverything – Google”).Link(“Next”).Object.scrollIntoView

Scroll bar QTP


Which one is right ?

Translate







Tweet