Based on the current online available preview version of Ranorex V2.0 following blog post describes how to do test automation based on the new Ranorex elements and RanoreXPath.

Download Infragistics Ultragrid Sample (5KB)
The test automation code requires a running DynamicStyling application provided through the Infragistics NetAdvantage demo kit.

Ranorex V2.0 comes with a totally redesigned core automation library. Based on the new possibilities of the core, the features of Ranorex tools like Ranorex Recorder have grown extremely to provide a more comfortable way of UI test automation. But not only the Ranorex tool set benefits from the new core library as following example shows.

The code gives a brief overview of how to work with Ranorex V2.0 core library directly. The example describes how to iterate through a 3rd party Infragistics UltraGrid control.

Ranorex V2.0 Spy with Infragistics UltraGrid

InfragisticsObj guiObj = InfragisticsObj.Instance;
guiObj.InfragisticsApp.Window.EnsureVisible();
Mouse.MoveTo(guiObj.InfragisticsApp.Window.Element);

foreach (Row  row in guiObj.InfragisticsApp.UltraGridTable.Rows)
{
  // Checks whether current row (node) is collapsed or not
  //System.Windows.Forms.AccessibleStates states = (System.Windows.Forms.AccessibleStates)row.Element.GetAttributeValue("accessiblestate");
  Accessible accObj = row.Element;

  if ( (accObj.State & System.Windows.Forms.AccessibleStates.Collapsed) != 0)
  {
    row.Focus();
    // Using relative coordinates to expand
    // collapsed node
    Mouse.Click(row.Element, new Location(new System.Drawing.Point(8, 8)));
 }

 // Request all cells of the current row
 // using the children property
 foreach (Cell cell in row.Cells)
 {
   cell.Focus();
   Mouse.Click(cell.Element, 2, new TimeSpan(0,0,0,0,10));
   // Simulate select all using keyboard actions
   Keyboard.Press(System.Windows.Forms.Keys.Home);
   Keyboard.Press("{LShiftKey down}{End}{LShiftKey up}");
   Accessible accCell = cell.Element;
   Keyboard.Press(accCell.Value);
 }

 // Request all cells from the subrows
 // using RanoreXPath
 IList allSubCells = row.Element.Find(new RxPath("row/cell"));

 foreach (Cell cell in allSubCells)
 {
   cell.Focus(); // ensures visibility
   // prepare text to set
   // using parent information
   Accessible accCell = cell.Element;

   string cellText = String.Format("Cell ({0},{1})",
                                    ((Accessible)cell.Element.Parent).Name,
                        			((Accessible)cell.Element).Name);

   accCell.Value = cellText;
 }
}

Normally, the previous code should be quite easy to understand. Maybe the code line

 IList allSubCells = row.Element.Find(new RxPath("row/cell"));

requires a more detailed description.

RanoreXPath could be seen as a query string to search for UI elements within the Ranorex element tree shown by RanorexSpy. In case of the current example the search starts from a specific Ranorex.Row item named ‘row’ to retrieve all sub cells regardless to which sub row element they belong.

Returned cells from RanoreXPath query string

The use of RanoreXPath allows not only a more flexible search or filtering for UI elements, but also some kind of validation to check attributes or current states of a control. In addition there is always the standard way of automation supported through Ranorex adapters (Tables, Rows, Columns, Cells, …) representing role specific UI elements providing access to their children again. In short, everything you see with RanorexSpy is accessible and available through the Ranorex core interface.

You might also like these articles