Forum Discussion

thustead's avatar
thustead
Contributor
14 years ago

Problem getting TestComplete to recognize grids

I can't get TestComplete to read the values in a few grids of the C# application that I'm testing.  I've tried numerus types of checkpoints but they don't seem to be reading the actual data in the grid.  For example if I purposely change the results of the grid, my checkpoint won't say that the results are wrong.  I attached a sample image of one of the grids.  I've only been using TestComplete for about a month, I've used other automation tools, but I've never been a developer so I'm a little green in the scripting side of these tools, everything I've done so far is with Keyword tests.  Which brings me to another question, its nice that there are so many languages to choose from in TC for scripting, but for someone like me I would like a little guidance on which language to choose.  If most people use Jscript, then there should be more support available for this language etc.  I used QTP and TestPartner so I have some experience with VB, but I think Jscript is more widely used with TestComplete.  I know the Falafel scripting class is based primarily on Jscript, so could I get some feedback as to which scripting language is more commonly used with TestComplete?



And back to the original question, any suggestions on how I could get TestComplete to recognize the data in the grids I'm looking at?  I know more info is probably needed, but any advice on what direction to go would be appreciated.



Thanks,

Tom

  • Hello Tom,





    First of all, I recommend that you review the Common Operations for Grids help topic, the "Obtaining and Setting Cell Values" section.

    The grid from the screenshot looks like the Developer Express XtraGrid control for WinForms. You can check this by the ClrFullClassName grid's property which is 

    DevExpress.XtraGrid.GridControl for XtraGrid. If this is your case, read how to work with the grid's cells in the Obtaining and Setting Cell Values in Developer Express XtraGrid help topic.

    Since you have some experience in writing scripts, I recommend that you use scripts rather than keyword tests. As for a preferred scripting language, please refer to the Selecting the Scripting Language help topic.





    If you still have a problem with reading grid cells' values correctly, please describe the problematic scenario in greater detail. What exact actions do you perform in your test? What is the expected and the actual result? If you have some errors when playing back script, please give me the exact text of the error messages.


  • Hi Allen,



    Thanks so much for the reply.  You are right, I was told by the dev team here that its a DevExpress grid, the ClrFullClassName is "WinClient.Controls.BasicGrid+ExposedGridControl".  I was told by someone at SmartBear that because this is a .Net app, that it should be exposed and I should be able to use some scripts to read the data in it.  I read through the Obtaining and Setting Cell Values in Developer Express XtraGrid help topic and am trying to use the below VBSrcipt code, but there seem to be quite a bit of places where I need to plug in values for the grid into the script, there are a lot of "WinFormsObject" referrences in both the script and the full name of the grid, so I'm not sure how to modify the script to work with my grid, the full name of the grid is:



    Sys.Process("Client").WinFormsObject("Mdi").WinFormsObject("MdiClient", "").WinFormsObject("FormStart").WinFormsObject("panelView").WinFormsObject("SearchToeView").WinFormsObject("tabControl").WinFormsObject("tabPageBasicSearch").WinFormsObject("searchViewBasic").WinFormsObject("WinClient.Panels.Search.ReqDoc.BasicReqDocQueryPanel_searchResultsGrid").WinFormsObject("gridControl")



    Any help on how to plug in these values would be greatly appreciated!



    Thanks again,

    Tom



    Sub Main

      Dim p, frmMain, Grid, nColumns, Col



      ' Obtain the application process and its main form

      Set p = Sys.Process("GridTutorials")

      Set frmMain = p.WinFormsObject("frmMain")

      ' Select the "Column Format" demo

      frmMain.WinFormsObject("gcNavigations").WinFormsObject("listBoxControl1").SelectedItem = "Column Format"

      ' Obtain the grid object

      Set Grid = frmMain.WinFormsObject("pcMain").WinFormsObject("gcContainer").WinFormsObject("Form1").WinFormsObject("gridControl1")



      nColumns = GetColumnCount (Grid, Nothing)



      ' Post grid cell values to the log

      Log.AppendFolder "Cell values in row 0:"

      For Col = 0 To nColumns-1

        Log.Message aqConvert.VarToStr(GetCellValue (Grid, Nothing, 0, Col))

      Next

      Log.PopLogFolder



      ' Post grid cell text to the log

      Log.AppendFolder "Cell text in row 0:"

      For Col = 0 To nColumns-1

        Log.Message GetCellText (Grid, Nothing, 0, Col)

      Next

      Log.PopLogFolder

    End Sub



    Function GetCellValue (Grid, View, RowIndex, ColumnId)

      Dim Column

      ' Get the grid view, if it is not specified

      If View Is Nothing Then

        Set View = Grid.MainView

      End If

      ' Get the column object

      Set Column = GetColumn (Grid, View, ColumnId)

      ' Get the cell value

      Set GetCellValue = View.GetRowCellValue(RowIndex, Column)

    End Function



    Function GetCellText (Grid, View, RowIndex, ColumnId)

      Dim Column

      ' Get the grid view, if it is not specified

      If View Is Nothing Then

        Set View = Grid.MainView

      End If

      ' Get the column object

      Set Column = GetColumn (Grid, View, ColumnId)

      ' Get the cell text

      GetCellText = View.GetRowCellDisplayText(RowIndex, Column).OleValue

    End Function



    Function GetColumnCount (Grid, View)

      If View Is Nothing Then

        GetColumnCount = Grid.MainView.Columns.Count

      Else

        GetColumnCount = View.Columns.Count

      End If

    End Function



    Function GetColumn (Grid, View, ColumnId)

      Dim Columns, Col, i



      ' Get the grid view, if it is not specified

      If View Is Nothing Then

        Set View = Grid.MainView

      End If



      Set Columns = View.Columns

      ' Check if the column is specified by caption or index

      If aqObject.GetVarType (ColumnId) = varOleStr Then

        ' Search for the column by its caption

        For i = 0 To Columns.Count-1

          Set Col = Columns.Item_2 (i)

          If Col.Caption.OleValue = ColumnId Then

            Set GetColumn = Col ' The column is found

            Exit Function

          End If

        Next

        Set GetColumn = Nothing' The column is not found

      Else

        ' The column is specified by index

        Set GetColumn = Columns.Item_2 (ColumnId)

      End If

    End Function


     


  • Hello Tom,





    Since the tested grid is a descendant of WinForms XtraGrid, you can command TestComplete to treat it as an XtraGrid control. For this purpose, you should specify the ClrFullClassName property of the tested grid on the "Tools | Current Project Properties | Object Mapping" page. Add the class name to the Developer Express Controls | XtraGrid node. Also, check whether the grid's view is overridden. For this purpose, select the grid object in the Object Browser, then select its MainView property, click the ellipsis button of the property value column to display the properties of the corresponding object and check its ClrFullClassName property. As you can see, the Developer Express Controls | XtraGrid node has some child nodes that contain the class names of native XtraGrid's views. If the ClrFullClassName property of the MainView object of the tested grid differs from these names, add its class name to the Developer Express Controls | XtraGrid | GridView node. Does this help?





    See also: Object Mapping.


  • Hi Allen,



    You're awesome!!!  Adding the ClrFullClassName to the Object Mapping XtraGrid node fixed this issue.  I can read the data in the grids with table checkpoints now. 



    I had spent a lot of time reviewing the Object Mapping article, among others, but I clearly need to improve my understanding of object mapping. 



    Thank you so much!

    Tom