robotframework - Roboframework 用户关键字可以包含正则表达式吗?
问题描述
有一个关键字来测试类似的行为是很常见的,但语义略有不同,如下所示:
The ${element_a} (gets updated with reference|has a reference) to the ${element_b}
但是,我无法在任何地方找到此功能的文档。我知道其他用于测试的库,例如 Cucumber 通过正则表达式支持匹配步骤,我想因为机器人框架支持关键字名称中的嵌入参数,这也可以在机器人中工作。
有没有办法编写一次关键字并在稍微不同的情况下重新使用它?
解决方案
*** Keywords ***
The ${element_a} ${updated_or_has} to the ${element_b}
IF """${update_or_has}""" == 'gets updated with reference'
Do Actions For Updated
ELSE IF """${update_or_has}""" == 'has a reference'
Do Other Actions
ELSE
Fail Unsupported value
END
这是一种方法,根据关键字名称中包含的字符串来分支执行。
调用它The element_a gets updated with reference to the element_b
将使关键字采用一条路径,而The element_y has a reference to the element_z
- 另一条路径。
顺便说一句,您可能会重新考虑稍微更改动词,因为框架将很难区分变量中的子字符串${element_a}
和输入的内容${updated_or_has}
- 输入静态单词,这将是关键字名称的一部分并充当两个变量的分隔符 b/n。
根据评论,不需要分支,只需确认调用者使用了两个可能/支持的值之一。这可以通过以下检查来完成:
Run Keyword If """${update_or_has}""".lower() not in ('gets updated with reference', 'has a reference', ) Fail Unsupported value
推荐阅读
- c - 如何在用户按下回车之前制作一个 scanf 循环(仅使用
) - html - 如何在 GitHub Pages 上隐藏提交确认页面(Google Forms)?
- python - 在 Python/Pandas 中执行不同操作的多列有条件地聚合分组数据
- vue.js - 是否“请求的资源上不存在'Access-Control-Allow-Origin'标头”错误完全死胡同
- excel - 制作 VBA 脚本以更高效地将 Excel 字段映射到 Project
- authentication - Silverstripe 4 LoginForm 重定向 default_login_dest
- angular - Ngrx + Jasmin 测试问题(actual.subscribe 不是函数)
- node.js - Chrome/Nodejs 堆快照 - 为什么将 javascript 源代码作为字符串分配在内存中?
- jmeter - 使用 JMeter 5.4.1 记录 .Net 应用程序得到错误响应或错误响应代码:500
- python - python - os.remove() 一个文件然后创建一个新文件但创建日期没有更新