Ranorex使用异常处理来决定一个测试用例是失败还是成功。只要所有的ranorex方法都没有抛出异常(例如 Ranorex.Validate方法或是使用一个无效的对象库项),测试将会成功。如果你不想让Ranorex抛出异常,但是同时想自己决定是否一个测试用例失败,你需要在程序里抛出Ranorex异常。
  C#
  Ranorex.Cell cellObject = null; // Try to find a cell object using two // different RanoreXPath expressions bool found=false; found = Host.Local.TryFindSingle<Ranorex.Cell>("/form//table/row/cell[3]", 2000, out cellObject); found = Host.Local.TryFindSingle<Ranorex.Cell>("/form//table/row/cell[4]", 2000, out cellObject); // If none of the expressions returns an object // throw new 'ElementNotFoundException' and test case fails if (!found) { throw new Ranorex.ElementNotFoundException("Both RanoreXPath with no return", null); } else { // If the value of attribute 'Text' does not equal to the expected value // throw new 'ValidationException' to break the test case if ( cellObject.Text == "MyExpectedTextValue" ) { Report.Success("User Specific Validation","Text validation of cell object succeeded"); } else { throw new Ranorex.ValidationException("Text validation of cell object succeeded failed"); } }
  VB.NET
  Dim cellObject As Ranorex.Cell = Nothing ' Try to find a cell object using two ' different RanoreXPath expressions Dim found As Boolean = Host.Local.TryFindSingle(Of Ranorex.Cell)("/form//table/row/cell[3]", 2000, cellObject) found = Host.Local.TryFindSingle(Of Ranorex.Cell)("/form//table/row/cell[4]", 2000, cellObject) ' If none of the expressions returns an object ' throw new 'ElementNotFoundException' and test case fails If Not found Then Throw New Ranorex.ElementNotFoundException("Both RanoreXPath with no return", Nothing) Else ' If the value of attribute 'Text' does not equal to the expected value ' throw new 'ValidationException' to break the test case If cellObject.Text = "MyExpectedTextValue" Then Report.Success("User Specific Validation", "Text validation of cell object succeeded") Else Throw New Ranorex.ValidationException("Text validation of cell object succeeded failed") End If End If