Selecting a row from a FlexListBase control that matches a text pattern

Selecting a row from a FlexListBase control that matches a text pattern

The controls that derive from the FlexListBase control contain no methods for selecting a row that matches a specified text/string pattern. The following code snippets demonstrate how this functionality can be achieved via a SilkTest Classic 4Test function, a Silk4J method and a VB.NET method:


SilkTest Classic:

[-] FindAndSelectIndex_ContainingTextPattern(window wFlexListBase, String sTextPattern)
     [ ]
     [ ] List of List of STRING llsValues = wFlexListBase.GetValues(0,wFlexListBase.numRows)
     [ ]
     [ ] List of STRING lsRow
     [ ] String sItem = ""
     [ ] String sValue
     [ ] int i=0
     [ ]
     [-] for each lsRow in llsValues
          [-] for each sValue in lsRow
               [ ] sItem = sItem + sValue + " "
          [ ]
          [-] if(MatchStr(sTextPattern,Trim(sItem)))
               [ ] wFlexListBase.SelectIndex(i)
               [ ] return
          [ ]
          [ ] sItem = ""
          [ ] i++
     [ ]
     [ ] //If we get to here we did not find the item:
     [ ] LogWarning("Unable to find an item matching the text pattern: {sTextPattern}")




Silk4J:

public void selectItemContainingTextPattern(FlexListBase fList, String sPattern){
     List<List<String>> values = fList.getValues(0,fList.getNumRows());
     String sItem = "";
     int iRowIndex = 0;
     
     for(List<String> row:values){
          for(String item:row){
               sItem = sItem.concat(item+" ");
          }

          if(sItem.trim().matches(sPattern)){
               fList.selectIndex(iRowIndex);
               break;
          }else{
               iRowIndex++;
          }
     }

}


VB.NET

Public Sub SelectIndex_withTextPattern(list As FlexListBase, pattern As String)
     Dim llsRows As List(Of List(Of String)) = list.GetValues(0, list.NumRows)
     Dim iRowIndex As Integer = 0
     Dim sItem As String = ""
     Dim sTemp As String
     Dim lsRow As List(Of String)
     
     For Each lsRow In llsRows
          For Each sTemp In lsRow
               sItem = sItem + sTemp +" "
          Next

          If sItem.Trim() Like pattern
               list.SelectIndex(iRowIndex)
               Exit For
          Else
               iRowIndex = iRowIndex+1
          End If

     Next
End Sub


The following code highlights how the said helper function/method can be called from their respective environments:

SilkTest Classic:

[-] testcase exampleSelectListItem() appstate none
     [ ] FindBrowserApplication("/BrowserApplication").SetActive()
     [ ] FindAndSelectIndex_ContainingTextPattern(FindFlexDataGrid("//FlexDataGrid[@caption='dg']"), "*mjones*")



Silk4J:

FlexDataGrid grid = desktop.<FlexDataGrid>find("//FlexDataGrid[@caption='dg']");
selectItemContainingTextPattern(grid, ".*Jones.*mjones.*");


VB.NET

SelectIndex_withTextPattern(_desktop.FlexDataGrid("//FlexDataGrid[@caption='dg']"), "*Jones*mjones*")

 

Attachments:

SilkTest Classic example script:

3007.flexListSelect.zip

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2013-03-13 08:19
Updated by:
 
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.