Skip to content

Infragistics Community Forum / Test Automation For Micro Focus Uft Windows Forms / Selecting a row in swftable – not by row number

Selecting a row in swftable – not by row number

New Discussion
Aswini
Aswini asked on Apr 28, 2011 10:38 AM

Hi…

My application is built on .NET and we use QTP 10.0 and 9.1CLR2.0 / TestAdvantage for Windows Forms (HP) 2009.1

 

In our application, when we give a name in ‘search form’ edit box, we get its details in the table present in the window.

 

The table by default has 800+ rows and new rows get added with every new build. Added rows get arranged alphabetically and hence row no 621 if standing for ‘PennsylvaniaA1’ in this build may stand for ‘PennsylvaniaA16’ in the next builds.

 

I need to select a row and then select some other required information and then click on ‘Add’ button.

 

As of now, I’m using ‘SelectRow’ method.

But I want to go with names of the forms. So when I give the name of form and when only that row appears, I want to select the row.

This may be with description or some other property. I tried a few from my end but could not succeed.

 

Please help me out with this.

Sign In to post a reply

Replies

  • 0
    Michael Germann
    Michael Germann answered on Apr 19, 2011 7:32 PM

    The ideal setup for UIAutomation testing is to always start with the same stable start, and the test is to make sure you always end with the expected output. If your input test data is in flux, it will likely throw off your expected testable outcome.

       That being said, ideal scenarios are not what we are always given. My first thought would be if you have filtering available, apply a filter to the desired value, such that there is only one possible outcome, and select that row.

    If filtering is not available, my next thought would be just loop through the rows until you get to the desired row. Being you are up to 800+ rows, that may not be the best scenario.

    Being there are a lot of rows, and the data is sorted, perhaps you can use a recursive searching method. There are several ways you can go about it. But one concept would be something like below.

    In a nutshell, it takes in a row to start from and the total number of rows, it finds the middle value, determines if it is the cell value it is looking for, equal, greater than or less than. If it's equal, it found it's row, in the other two cases, it calls itself, adjusting the starting row and row count accordingly. I also added an additional check, to the rowcount is below a certain number, just brute force through the rows one at a time. If it finds the row, it returns it's row number, if not it returns a -1. Note the logic will need to be changed if the sort is descending.

    Set Grid = SwfWindow("Form1").SwfTable("ultraGrid1")
    iTest = GetRowToSelect(Grid, "name", "Name for Row#86", 0, Grid.RowCount)

    If iTest <> -1 Then
        Grid.SelectRow CStr(iTest)   
    else
        msgbox "NotFound"
    End If

    Function GetRowToSelect(oGrid, sColName, oCellValue, iStartRow, iRowCount)
       dim oCrntCellVal, iNewStartRow, iNewRowCount, iMidShift, iMidRow

        If iRowCount < 6 Then
            For i = iStartRow to iStartRow + iRowCount
                    oCrntCellVal = oGrid.GetCellData(CSTR(i), sColName)
                    If oCrntCellVal = oCellValue Then
                        GetRowToSelect = i
                        Exit function
                    End If
            Next
        Else
            iMidShift = int(iRowCount / 2)
            iMidRow =  iMidShift + iStartRow
            oCrntCellVal = oGrid.GetCellData(CSTR(iMidRow), sColName)
            If oCrntCellVal = oCellValue Then
                GetRowToSelect = iMidRow
                Exit function
            elseif oCrntCellVal > oCellValue Then
                iNewStartRow = iStartRow
                iNewRowCount =     iMidShift
            elseif oCrntCellVal < oCellValue Then
                iNewStartRow = iMidRow + 1
                iNewRowCount = iRowCount – iMidShift
            End If

            GetRowToSelect  = GetRowToSelect(oGrid, sColName, oCellValue, iNewStartRow, iNewRowCount)
            If GetRowToSelect <> -1 Then
                Exit Function
            End If
        End If

        GetRowToSelect = -1
    End Function

    • 0
      Aswini
      Aswini answered on Apr 28, 2011 10:38 AM

      Hi Michael,

      Filtering option is available and when correct form name is given, I get only one row in the table and this is my desired row.

      But when I want to select thet row, I'm again supposed to give the row number as I'm using SelectRow method.

      Besides giving row number is there a way to go with the description of the outcome.

      (After filtering I get a row with four columns. This is just to let you know how my table is.)

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
Aswini
Favorites
0
Replies
2
Created On
Apr 28, 2011
Last Post
15 years, 4 months ago

Suggested Discussions

Tags

No tags

Created by

Created on

Apr 28, 2011 10:38 AM

Last activity on

Feb 25, 2026 10:24 AM