scala - 如何在多行中实现步骤定义?
问题描述
我正在使用 Scala、Cucumber、Gherkin 语言进行自动化测试。我的功能文件中有以下场景,用 Gherkin 语言编写:
Scenario Outline: Do something
When I do something
Then result should have field1 as "<filed_1>", field2 as "<filed_2>" and filed3 as "<filed_3>"
生成的stepdef是:
When("""^I do something$""") {
// do operation
}
Then("""^result should haveresult should have field1 as "([^"]*)",
field2 as "([^"]*)" and filed3 as "([^"]*)"$""") {
// do operation
}
这里Then语句在一行中有超过 120 个字符,我必须分成两部分。我不应该更改功能文件。
当 break然后在两行
Then("""^result should haveresult should have field1 as "([^"]*)",
| field2 as "([^"]*)" and filed3 as "([^"]*)"$""".stripMargin)
它说您可以使用以下代码段实现缺少的步骤:
Then("""^result should have field1 as "([^"]*)", field2 as "([^"]*)" and filed3 as "([^"]*)"$"""){ (arg0:String, arg1:String, arg2:String) =>
//// Write code here that turns the phrase above into concrete actions
throw new PendingException()
}
我不确定我应该采取哪种方法来打破Then多行。感谢任何帮助。
解决方案
您可以String
将它们分成两部分并将它们加在一起:
Then("""^result should have field1 as "(.*)", field2 as "(.*)" """ +
"""and filed3 as "(.*)"$""") { (arg0:String, arg1:String, arg2:String) =>
//etc
}
String
这与您要拆分然后相加的任何内容相同:
"""1234567890""" == """12345""" + """67890""" // true