In Cucumber, is it possible to programmatically get the current step being executed?(在 Cucumber 中,是否可以以编程方式获取正在执行的当前步骤?)
问题描述
Scenario: As a user, I want to login to the system
Given I am on my website
When I enter valid credentials
Then I am taken to the home page
可以使用 getName()
函数检索场景名称.有没有办法也让正在执行的步骤(在 Java
中)?我们预计将在日志记录和报告中使用它.
The scenario name can be retrieved using the getName()
function. Is there a way to also get the step being executed (in Java
)? We foresee the use of this in logging and reporting.
因此,对于上述场景,I am on my website
将在执行相应的步骤定义时返回.
So, for the scenario above, I am on my website
would be returned while the corresponding step definition is being executed.
推荐答案
我们通过将整个步骤作为参数包装到步骤定义中来解决了这个问题.换句话说,步骤
We solved this problem by wrapping the entire step as a parameter into the Step Definition. In other words, the step
Given I am on my website
翻译成
'Given I am on my website'
步骤定义实际上会接受一个字符串参数,该参数将对应于步骤
And the step definition will actually accept a string parameter that will correspond to the step
@And("(.*)") //plus something specific to map step
public void Initialization(String step) throws Exception {
//do something with step
}
这篇关于在 Cucumber 中,是否可以以编程方式获取正在执行的当前步骤?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Cucumber 中,是否可以以编程方式获取正在执行的当前步骤?


基础教程推荐
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01
- 如何强制对超级方法进行多态调用? 2022-01-01
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01
- 在螺旋中写一个字符串 2022-01-01
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01
- 如何对 HashSet 进行排序? 2022-01-01
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01