如何访问 Cucumber 中的场景和示例名称?

发布于 2024-07-15 12:36:39 字数 94 浏览 4 评论 0原文

我正在使用黄瓜生成可以由工具或人类执行的测试脚本......所以不是标准用途。

不过,我想将场景和示例名称传递到我的输出。

这可能吗?

I'm using cucumber to generate test scripts that can be executed by a tool or human... so not the standard use.

However I would like to pass through the scenario and example names through to my output.

Is this possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

分开我的手 2024-07-22 12:36:39

找到了..(在 Tim Walker 的帮助下)

Before do |scenario|
 puts "Before Scenario: #{scenario.to_sexp[2]}"
 .
 .
 .
end

您的 SExpression 可能有所不同,因此值得执行 scenario.to_sexp.inspect 来查看该树是什么。

Aslak 热衷于避免暴露他的类中的属性(这是我碰巧同意的决定,所以我很乐意做这项工作)。

Found it.. (with some help from Tim Walker)

Before do |scenario|
 puts "Before Scenario: #{scenario.to_sexp[2]}"
 .
 .
 .
end

Your SExpression may differ, so it's worth doing a scenario.to_sexp.inspect to see what that tree is.

Aslak is keen to avoid exposing properties on his classes (which is a decision I happen to agree with, so I'm happy to do this work around).

流星番茄 2024-07-22 12:36:39

一个更严肃的答案(或者至少是建议):利用 ruby​​ 的反射来尝试找到您正在寻找的内容。 抓住可能的物体,找出它们有什么方法,然后看看你是否能找到它。 例如:

File.open('happy_hunting.log','a') { |f|
    f.print "Scenario supports: #{(scenario.methods - Object.methods).inspect}\n"
    }

然后重复一遍以找出什么在哪里。

另一个建议,看看源码。

A more serious answer (or at least, suggestion): make use of ruby's reflection to try to find what you are looking for. Grab likely objects, find out what methods they have, and see if you can find it. For example:

File.open('happy_hunting.log','a') { |f|
    f.print "Scenario supports: #{(scenario.methods - Object.methods).inspect}\n"
    }

and then repeat it to figure out whats where.

Another suggestion, look at the source.

只为一人 2024-07-22 12:36:39

我做了一些斗志旺盛的事情。 由于我仅使用此信息进行调试,因此现在这将有效,直到我找到更好的东西。

@Before
public void printTestInfoBeforeScenario(Scenario scenario) {
    LOGGER.info("Upcoming Test: "+scenario.getSourceTagNames());
}

@After
public void printTestInfoAfterScenario(Scenario scenario) {
    LOGGER.info("Test Complete: " + scenario.getSourceTagNames() + " Status: " + scenario.getStatus());
}

I did something scrappy. As I use this info for only debugging, this will work for now, until I find something better.

@Before
public void printTestInfoBeforeScenario(Scenario scenario) {
    LOGGER.info("Upcoming Test: "+scenario.getSourceTagNames());
}

@After
public void printTestInfoAfterScenario(Scenario scenario) {
    LOGGER.info("Test Complete: " + scenario.getSourceTagNames() + " Status: " + scenario.getStatus());
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文