强制一个测试用例失败

发表于:2016-4-19 10:17

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:老夫子_22    来源:51Testing软件测试网采编

  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软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号