【问题标题】:How to fail the test case - Cucumber with Groovy如何使测试用例失败 - 带有 Groovy 的 Cucumber
【发布时间】:2019-06-24 07:15:43
【问题描述】:

当我检查步骤定义文件中的特定黄瓜步骤时,如果条件为假,我想让该特定测试用例停止并失败并继续下一个测试用例。

如果我必须使用FailureHandling.STOP_ON_FAILURE,如何编码?

@When("User enters the (.*) in the Login")
def user_enter_userid_in_the_Login(String uid) {
if (uid=='')
    /** FAIL the TEST CASE **/
else
    WebUI.setText(findTestObject('Object Repository/ORTC01/Page_/input_userid'), uid,
     FailureHandling.STOP_ON_FAILURE)
    WebUI.delay(5)
}

【问题讨论】:

  • assert uid!='' 或只是assert uid
  • 谢谢你,jonrsharpe。 如何编写代码?请提及。如何使测试用例失败?
  • def user_enter_userid_in_the_Login(String uid) { assert uid!='' WebUI.setText(findTestObject('Object Repository/ORTC01/Page_/input_userid'), uid, FailureHandling.STOP_ON_FAILURE) WebUI.delay(5 ) } 否则测试会失败?

标签: groovy cucumber


【解决方案1】:
def user_enter_userid_in_the_Login(String uid) {
    assert uid!='' //this will fail test if uid==''
    ...continue success code
}

也可以提供错误信息

assert uid!='' : "the parameter 'uid' could not be empty"

大致对应:

if(uid=='')throw new Exception("the parameter 'uid' could not be empty")

【讨论】:

  • 完美,达格特。感谢您的澄清。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-31
  • 1970-01-01
相关资源
最近更新 更多