如何在Cucumber-JVM中明确匹配这些步骤? [英] How to match these steps unambiguously in Cucumber-JVM?

查看:191
本文介绍了如何在Cucumber-JVM中明确匹配这些步骤?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法明确匹配以下步骤?

 我应该有2个警报
应该有两个警报与param 71

我已经实现它们:

  @And(^ I should have(\\d +)alerts)
@And(^ I should have \\ d +])

当Cucumber评估第二个步骤它说它是不明确的,因为它可以匹配两个步骤定义之一,即使它有额外的单词'与param'。



提前感谢。 / p>

解决方案

 我应该有param 71的警报71 
  

> @And(^ I should have(\\d +)alerts)

开始

  ^我应该有(\\d +)警告

使用 $ 终止该步骤定义,继续执行的步骤:

  @And(^ I should have(\\d +)alerts $)


Is there any way to match the following steps unambiguously?

And I should have 2 alerts
And I should have 2 alerts with param 71

I have implemented them as:

@And("^I should have (\\d+) alerts")
@And("^I should have (\\d+) alerts with param (\\d+)")

When Cucumber evaluates the second step it says that it is ambiguous because it could have matched either of the two step definitions, even though it has the extra words 'with param'.

Thanks in advance.

解决方案

And I should have 2 alerts with param 71

is matched by both steps because

@And("^I should have (\\d+) alerts")

matches anything that begins with

^I should have (\\d+) alerts

Terminate that step definition with $ and it will no longer match steps which keep going:

@And("^I should have (\\d+) alerts$")

这篇关于如何在Cucumber-JVM中明确匹配这些步骤?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆