在黄瓜中,是否可以通过编程获取当前执行的步骤? [英] In Cucumber, is it possible to programmatically get the current step being executed?
本文介绍了在黄瓜中,是否可以通过编程获取当前执行的步骤?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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.
因此,对于上述情况,我在我的网站上
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
}
这篇关于在黄瓜中,是否可以通过编程获取当前执行的步骤?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文