java - 如何在 cucumber 测试中匹配括号

标签 java regex cucumber cucumber-junit

我目前在使用 Java 和 Cucumber 时遇到问题。使用 Selenium 访问网站的元素,我想使用如下短语:

Then the value of the attribute XYZ should be 1000

该示例非常简单,并且通过使用 Java 注释对于每个属性名称都可以正常工作

@Then("the value of the attribute (.*) should be (.*)")

以下用例除外:属性名称包含括号,如 ABC(s)

在使用 Eclipse 和 JUnit 时,使用包含此类括号的字符串进行 Cucumber 测试甚至无法完全识别,而只能识别左括号之前的字符串部分。有什么想法或解决方案吗?

最佳答案

属性名称是否包含括号并不重要。

使用此方法时:

@Then("^the value of the attribute (.*) should be (.*)$")
public void checkAttributeValue(String name, String value)
        throws Throwable {
    System.out.println("Name: " + name + " value: " + value);
}

Then the value of the attribute XYZ(s) should be 1000

我明白

Name: XYZ(s) value: 1000

我认为这正是您所期望的。

关于java - 如何在 cucumber 测试中匹配括号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23468611/

相关文章:

java - 使用 Spring 配置文件的 JBoss 7 多个 log4j 配置

regex - 如何构造正则表达式来比较 shell 脚本中不区分大小写的字符串?

javascript - 无法访问 AfterFeatures Hook 中的世界方法

ruby - 未初始化的常量 Cucumber::ast

javascript - 通过步骤定义和页面对象在 cucumber Protractor 中实现场景大纲

java - 获得广告响应。错误代码 : 0

java - eclipse 中的错误,servlet

java - 索引时间字段在 solr 6.1.0 中未建立索引。给出错误为未定义字段 : "event_timestamp"

mysql - 在 MySQL 中将除一组字符之外的所有字符转换为空格

javascript - RegExp - 如何检查字符串中的两个括号