Created On:  14-05-2010
 
Much like the Classic Agent, a user can extend the Open Agent winclasses with their own custom methods and properties. A user can simply follow the same practices that they previously employed when extending Classic Agent winclasses. Below we can see that these functions could easily be incorporated into a custom winclass:

//Extended SWTTable winclass
[-] winclass ExtSWTTable:SWTTable
 [ ]
 [ ] //Get the value of the cell at row # and column #
 [+] String GetCellValue(int iRow, int iCol)
  [ ] list of window lwRows = this.FindAll("//SWTTableRow")
  [ ]
  [ ]
  [+] if(iRow > this.RowCount || iRow < 1)
   [ ] raise E_ROW_INDEX_INVALID, "***ERROR: Specified row value is invalid"
  [+] if(iCol > this.ColumnCount || iCol < 1)
   [ ] raise E_COLUMN_INDEX_INVALID, "***ERROR: Specified column value is invalid"
  [ ]
  [ ] return lwRows[iRow].Items[iCol]
 [ ]
 [ ] //Return the TABLECELL that contains the specified value
 [+] TABLECELL FindCell(string sCellVal)
  [ ]
  [ ] TABLECELL tReturn
  [ ]
  [ ] boolean bBreak = false
  [ ]
  [ ] int i,k
  [ ] window wRow
  [ ] list of STRING lsCellValues
  [ ]
  [-] for(i=1; i<= this.RowCount; i++)
   [ ] wRow = this.Find("//SWTTableRow[{i}]")
   [ ] lsCellValues = wRow.Items
   [ ]
   [-] for(k=1; k<=ListCount(lsCellValues); k++)
    [+] if(lsCellValues == sCellVal)
     [ ] tReturn = {i,k}
     [ ] bBreak = true
     [ ] break
   [+] if(bBreak)
    [ ] break
  [ ]
  [ ] return tReturn


The next question a user may ask, "Do I need to declare Open Agent window declarations to use my custom winclass?", and the answer to this would be no. When using the Open Agent to record against your application, the statements recorded are Dynamic Object Recognition (DOR) statements. These statements use the "Find" method to resolve and locate controls within an application but most importantly, the "Find" method returns a generic "window" type. This generic window type allows us to use any method or property of a winclass that the generic window matches, for example:


[-] testcase TestExtWinClass() appstate none
 [ ]
 [ ] //find the cell matching the specified value
 [ ] print(Desktop.Find("//SWTTable").FindCell("A Test Value"))
 [ ]
 [ ] //Get the cell value at row 2, column 1
 [ ] print(Desktop.Find("//SWTTable").GetCellValue(2,1))

Therefore because our custom winclass falls at the bottom of the winclass extension hierarchy, the generic window returned from Find resolves correctly to our custom winclass and we can successfully call the methods of our custom winclass.