Cucumber步骤定义中的转义字符

3

我有以下步骤,用于使用Cucumber-jvm。如何在我的步骤定义中转义特定字符?

When user verifies if ABC widget exists
Then the 'The 7 Things $channel' label is displayed

在这种情况下,我需要将7$ 作为普通字符串进行转义。


你为什么认为需要转义数字? - Dave Schweisguth
@DaveSchweisguth 7或任何其他数字在我的步骤中没有数值上下文价值。它只是一个需要验证的文本标签。 - nabster
你的意思是希望“7”和“$channel”成为该步骤的参数? - Dave Schweisguth
@DaveSchweisguth 不是单独的参数,只有一个字符串参数,如“The 7 Things $channel”。稍后在我的代码中,我会用其他值替换$channel中的一些字符串。我想“7”和“$”字符可能让你感到困惑。 - nabster
是的,因为数字在正则表达式中并不特殊。看看这个编辑是否有意义... - Dave Schweisguth
1个回答

5

您可以这样做:

Then the /'The 7 Things $channel' label is displayed/

相应的 Step def 应该是:

 @Then("^the /'The 7 Things \\$channel' label is displayed/$")
   public void the_The_Things_$channel_label_is_displayed() throws Throwable {
      System.out.println("hello");
   }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接