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()
 }
}

是否可以将 Groovy 与英语分开,以呈现更像这样的内容:

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 搞糊涂了。

4

3 回答 3

1

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

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")
}
于 2010-11-19T14:46:37.507 回答
1

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

于 2011-01-07T13:48:24.807 回答
1

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

http://www.easyb.org/running.html 上的easyb文档仅描述了如何从命令行创建“故事”文本视图。使用 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 已修复最好将其添加为故事的最后一部分,以便始终创建“用户”文档,上面的代码片段会导致执行测试,因此不能包含在相同的故事文件,否则它将进入递归循环。

于 2011-01-24T15:57:45.880 回答