我正试图用Cucumber(Behave)编写一个测试。“给定”语句需要能够接受可选参数,它用于验证字符串中的内容
两种方案的功能语法示例如下:
Given Verify text "this is a test string"
When String validation is "success"
Then Store form contents.
Given Verify text "this is a test string" exclude "test,trial,hello"
When String validation is "success"
Then Store form contents.
我尝试实施的步骤是:
# Verify text "this is a test string" exclude "test,trial,hello"
@given('Verify text "{text_to_clean}" {?: exclude "{excluded}')
def step_verify_text(context, text_to_clean, excluded):
context.verified = verify_string(text_to_clean, excluded)
我该怎么做?我试着使用可选的?
符号,但我想不出来。使用可选参数需要做什么
我在macOS Catalina上使用Mac
可选部分的正则表达式:
(?: exclude "(?P<excluded>[^"]*?)")?
如果没有对所有步骤使用Regex解析器,请将步骤匹配器恢复为默认的
'parse'
注意:
feature
文件名和steps
文件夹中的文件名应该匹配例如:如果
feature
文件名是question_regex.feature
,那么steps
文件夹中的文件名应该是question_regex.py
一,。选项-Regex解析器
功能/问题\正则表达式功能
功能/步骤/问题\u regex.py
二,。选项-CFParse
功能/步骤/问题\u cfparse.feature
功能/步骤/问题\u cfparse.py
注意:
cfparse
如果有多个可选的parameters
相继出现,那么解析器不是一个好的选择相关问题 更多 >
编程相关推荐