Archive

Showing posts with label QTP. Show all posts
Showing posts with label QTP. Show all posts

Tuesday, August 2, 2011

Get count of file with matching extension in a Folder

In automation testing, you might come across with situation where in you need to find out number of files with a particular extension. Below is the code to get the count of file matches with the extension.

Function GetFileCount(ByVal sFolderPath, ByVal sExt)

 

            Dim iCount

            Dim oFile, pFolder

            Dim fso

            On Error Resume Next

           

            Set fso=CreateObject("Scripting.FileSystemObject")

            set pFolder=fso.GetFolder(sFolderPath)

            set oFile=pFolder.Files

 

            For each sFile in oFile

                        If instr(1,lcase(sFile.Path),sExt,1)>0 Then     'It's a text comparison

                                    iCount=iCount+1

                        End IF

            Next

 

                        'Count all files in each subfolder – recursion point

            For Each SubFld In pFolder.SubFolders

                        iCount = iCount + GetFilecount(SubFld.Path, sExt)

            Next

 

            GetFilecount=iCount  'Return the count to the calling statement

            Set fso=Nothing

End Function

 

sPath="E:\Debajit Hazarika\EDI Files"

sCount=GetFileCount(sPath, ".mbi")

Msgbox "Total Count  ="&sCount


Saturday, June 4, 2011

How to import all working sheets of an excel file to QTP DataTable: Excel Automation

Hello, friends
This post is meant for QTP learner and who are novice at it. You know that DataTable plays a big role in parameterizing our automation test. We pass arguments to our test script using this dataTable provided by QTP. However, in automation testing of a complex and large scale project we become less dependent on DataTable. Most of our test data is stored in Excel sheet because it gives us a flexibility to modify when needed. We know that to import and excel sheet, we use following commands: 
                               i)DataTable.Import(FilePath)
                               ii) DataTable.ImportSheet "FilePath", "SourceSheet", "DestinationSheet"

If your excel file contains more than one sheet, then none of the above command gives you the ability to import all the sheets at a time. In this case, you have to meet the requirement pragmatically. Sometimes, there is a requirement of using different local sheets at a time during execution. To get ride of such situation or to ease the process, I would like to share the following code snippet with you to achieve that goal. Code is given in Function format for reusability.

   Function ImportAllSheetsToDataTable(FileName)
       Dim objExl, objWBook

       If  Not IsNull(FileName) Then        'Check if the File name has been passed.
    Set objExl=CreateObject("Excel.Application")
    Set objWBook=objExl.Workbooks.Open(FileName,,True) 'Open the excel file

For each oWSheet in objWBook.WorkSheets  'Read all the worksheets
DataTable.AddSheet oWSheet.Name
DataTable.ImportSheet FileName, oWSheet.Name,oWSheet.Name
Next
        Set objWBook = Nothing
    objExl.Quit      'Quit the Application
    Set objExl = Nothing
Else
msgbox "No File name has been passed"
End IF
   End Function

   'To call the Function
   sPath="C:\TestData\TestData_QA.xls"
   ImportAllSheetsToDataTable(sPath)

Hope this code will also help

Thursday, June 2, 2011

How to identify a WebButton under a WebTable on a page

We, the automation tester frequently encounter web table on web page. WebTable is a way by which developers use to display information or data to user in tabular form on web page. Handling webtable is not a big deal in automation testing. But handling objects inside the table needs care. You must have faced such situation where you need to identify the button or link to perform "click" operation on it to open the respective page. It is simple if there is only one object of that type.
What will you do if there is more than one object of that type with same sets of property? Probably, you remember how to use index property and that will solve the issue at hand. If you are asked to identify a button and click on it based on some arguments, what you are going to do. Then we will be going into a bit complex thing. First you need to determine which button to identify and then click. To find the button, we need to know the row and column number of the cell of the table.
Let me proceed with an assignment. Assignment is- You need to delete the account with the name "Acc Nick Name". Look at the image below. This is a list containing different account nos. From here you need to search for "Acc Nick Name" and hit the "Delete" button to delete the account. Since you never know how many accounts this list may contain. So the behavior of this list is dynamic and each "Delete" button is of same nature.



Let's get into action. I pull up the spy button and get to see below mentioned hierarchy.






As you can see that the Delete button is located inside the webtable. Now, we are going use the Object Repository to store the object. To achieve that, I started recording the script. While recording I click on any of the Delete button. As a result, QTP automatically saved all the objects it has interacted with. Then I change the Title of the browser to broWCP and Page to pgWCP in the OR. Below is the code.

  Browser("broWCP").Page("pgWCP").WebButton("Delete")

You noticed that web table is missing from the recorded script. This is because QTP conceals the complete hierarchy. Now, remove the WebButton part and type WebTable, it will automatically display the name of the table. So, the code will look like this:

  Browser("broWCP").Page("pgWCP").WebTable("HSA Custodian")

Now, we need to find out how many rows and column the table has. Then we need to locate the Delete button based on the Account NickName. Here is the complete code:

Dim iRow, iCol, sRow, sButton
Dim bStatus:bStatus=False
sAccount="Acc Nick Name" 'Account Name to delete

iRow= Browser("broWCP").Page("pgWCP").WebTable("HSA Custodian").RowCount 'Find out the total row
iCol= Browser("broWCP").Page("pgWCP").WebTable("HSA Custodian").ColumnCount(iRow) 'Find the total Column

For i=1 to iRow 'get the row no where the target item exists
  If Browser("broWCP").Page("pgWCP").WebTable("HSA Custodian").GetCellData(i,3)= sAccount Then
      sRow=i
      bStatus=True
      Exit for
  Else
      bStatus=False
  End If
Next

  If bStatus Then
      Set sButton=Browser("broWCP").Page("pgWCP").WebTable("HSA Custodian").ChildItem(sRow, iCol, "WebButton", sRow-2)
      sButton.Highlight
      sButton.click
  Else
      Msgbox "Could not find the item"
  End IF


We know that the field "Account Nickname" exits on the 3rd column of the table. We have also identified that all the "Delete" buttons located in the last column of the table, hence we used whatever value is assigned to iCol. Later part "sRow -2" is due to the fact that index starts with "0" and our first row of the table contains the column heading. Hence, we need to subtract 2 from sRow. Last argument of childitem method is the index no.

This is how we can handle dynamic button inside a WebTable. Hope you enjoyed learning this fact.

Tuesday, September 21, 2010

What is the difference between QTP 9.2 and QTP 9.5?

Following are the points that make QTP 9.5 different from QTP 9.2:

1. QTP 9.5 supports MS Vista 64 bit edition also, in comparison to QTP 9.2's support for 32 bit edition only.
2. Support for omnipresent tabbed browsing is also introduced with this version.
3. All the addins come itegrated with QTP. But, still we need to buy add ins seperately to get them activated.
4. QTP 9.5 has introduce support for Bitmap torenace. You can change the tolerance level directly from GUI and define it in terms of RGB and pixel.
5. Checkpoints & Output values are getting recorded in OR.
6. You can create your own QTP add-in. When your add-in is loaded, Quicktest will recognize objects as you defined.
7. Maintenance Run mode.