强制一个测试用例失败
作者:网络转载 发布时间:[ 2016/4/19 10:53:04 ] 推荐标签:软件测试 测试用例
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
相关推荐
更新发布
功能测试和接口测试的区别
2023/3/23 14:23:39如何写好测试用例文档
2023/3/22 16:17:39常用的选择回归测试的方式有哪些?
2022/6/14 16:14:27测试流程中需要重点把关几个过程?
2021/10/18 15:37:44性能测试的七种方法
2021/9/17 15:19:29全链路压测优化思路
2021/9/14 15:42:25性能测试流程浅谈
2021/5/28 17:25:47常见的APP性能测试指标
2021/5/8 17:01:11