是否可以将 easyb 的 Groovy 与简单的英语场景定义分开?

发布于 2024-10-03 20:14:53 字数 1380 浏览 11 评论 0原文

下面是来自 easyb 网站的一个示例 easyb 场景:

before "start selenium", {
 given "selenium is up and running", {
  selenium = new DefaultSelenium("localhost",
    4444, "*firefox", "http://acme.racing.net/greport")
  selenium.start()
 }
}

scenario "a valid person has been entered", {

 when "filling out the person form with a first and last name", {
  selenium.open("http://acme.racing.net/greport/personracereport.html")
  selenium.type("fname", "Britney")
  selenium.type("lname", "Smith")
 }

 and "the submit link has been clicked", {
  selenium.click("submit")
 }

 then "the report should have a list of races for that person", {
  selenium.waitForPageToLoad("5000")
  values = ["Mclean 1/2 Marathon", "Reston 5K", "Herndon 10K", "Leesburg 10K"]
  for(i in 0..<values.size()){
    selenium.getText("//table//tr[${(i+3)}]/td").shouldBeEqualTo values[i]
  }
 }
}

after "stop selenium" , {
 then "selenium should be shutdown", {
  selenium.stop()
 }
}

Is it possible to split the Groovy from the English, topresent some more like this:

scenario "a valid person has been entered"
  given "the website is running"
  when "filling out the person form with a first and last name"
  and "the submit link has been clicked"
  then "the report should have a list of races for that person"

这样我的 PHB 就不会被大括号和 Groovy 搞糊涂了。

Here's an example easyb scenario from the easyb website:

before "start selenium", {
 given "selenium is up and running", {
  selenium = new DefaultSelenium("localhost",
    4444, "*firefox", "http://acme.racing.net/greport")
  selenium.start()
 }
}

scenario "a valid person has been entered", {

 when "filling out the person form with a first and last name", {
  selenium.open("http://acme.racing.net/greport/personracereport.html")
  selenium.type("fname", "Britney")
  selenium.type("lname", "Smith")
 }

 and "the submit link has been clicked", {
  selenium.click("submit")
 }

 then "the report should have a list of races for that person", {
  selenium.waitForPageToLoad("5000")
  values = ["Mclean 1/2 Marathon", "Reston 5K", "Herndon 10K", "Leesburg 10K"]
  for(i in 0..<values.size()){
    selenium.getText("//table//tr[${(i+3)}]/td").shouldBeEqualTo values[i]
  }
 }
}

after "stop selenium" , {
 then "selenium should be shutdown", {
  selenium.stop()
 }
}

Is it possible to separate the Groovy from the English, to present something more like this:

scenario "a valid person has been entered"
  given "the website is running"
  when "filling out the person form with a first and last name"
  and "the submit link has been clicked"
  then "the report should have a list of races for that person"

That way my PHB won't get all confused by the braces and Groovy.

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

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

发布评论

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

评论(3

刘备忘录 2024-10-10 20:14:53

可能没有经过合理的努力。尽管如此,您可以轻松地在外部定义代码闭包。 “人类可读”部分将如下所示:

scenario "a valid person has been entered", {
    when "filling out the person form with a first and last name", 
        fillOutPersonForm
    and "the submit link has been clicked", 
        clickSubmitLink
    then "the report should have a list of races for that person", 
        checkRacesList
}

确保闭包名称具有描述性和自记录性。实际上,我发现它们比完整的描述更容易阅读......

闭包定义是这样定义的:

def fillOutPersonForm = {
    selenium.open("http://acme.racing.net/greport/personracereport.html")
    selenium.type("fname", "Britney")
    selenium.type("lname", "Smith")
}

Probably not with justifiable effort. Nevertheless, you can easily define the code closures externally. The "human readable" parts would then look like this:

scenario "a valid person has been entered", {
    when "filling out the person form with a first and last name", 
        fillOutPersonForm
    and "the submit link has been clicked", 
        clickSubmitLink
    then "the report should have a list of races for that person", 
        checkRacesList
}

Make sure that the closure names are descriptive and self-documenting. Actually, I find them easier to read than the fully-written descriptions ...

The closure definitions were defined like that:

def fillOutPersonForm = {
    selenium.open("http://acme.racing.net/greport/personracereport.html")
    selenium.type("fname", "Britney")
    selenium.type("lname", "Smith")
}
卷耳 2024-10-10 20:14:53

实际上,我相信这已经是通过 ANT 集成的 easyb 的一个功能。查看“故事”部分下的 http://www.easyb.org/running.html印刷”。

Actually, I believe this is already a feature of easyb via the ANT integration. Check out http://www.easyb.org/running.html, under the section "Story Printing".

坠似风落 2024-10-10 20:14:53

作为 SJG 的扩展 答案这里是一个以编程方式执行此操作的代码片段。

easyb 位于 http://www.easyb.org/running.html 的文档仅描述了如何从命令行创建“故事”文本视图。使用 Groovy 代码执行此操作是一项简单的任务...

import org.easyb.BehaviorRunner

def params=["C:/temp/teststory.story", "-txtstory", "C:/temp/testoutput.html"] as String[]
BehaviorRunner.main(params)

您可以使用类似的方法使用 -html 或 -xml 作为第二个参数来进行 HTML 报告和 XML 报告。

我仍然不确定需要哪些参数,以便仅创建报告而不运行测试。这应该是可行的,请参阅问题 165 已修复 最好将其添加为故事的最后一部分,以便始终创建“用户”文档,代码片段上面会导致执行测试,因此不能包含在同一个故事文件中,否则会进入递归循环。

As an extension of SJG's answer here is a code snippet to do this programmatically.

The easyb documentation at http://www.easyb.org/running.html only describes how create the 'Story' text view from the command line. It's a simple task to do this with Groovy code...

import org.easyb.BehaviorRunner

def params=["C:/temp/teststory.story", "-txtstory", "C:/temp/testoutput.html"] as String[]
BehaviorRunner.main(params)

You can use a similar approach for the HTML reporting and XML reporting using -html or -xml as the 2nd parameter.

I'm still not sure which parameters are required so that just the reports are created without running the tests. This should be possible, see issue 165 fixed It would be nice to add this as the last part of a story so that the 'user' documentation is always created, the snippet above causes the tests to be executed so can't be included in the same story file otherwise it would get into a recursive loop.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文