首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >有可能将easyb的Groovy与简单的英语场景定义分开吗?

有可能将easyb的Groovy与简单的英语场景定义分开吗?
EN

Stack Overflow用户
提问于 2010-11-19 18:38:37
回答 3查看 240关注 0票数 0

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

代码语言:javascript
复制
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从英语中分离出来,呈现出更像这样的东西:

代码语言:javascript
复制
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搞糊涂了。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2010-11-19 22:46:38

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

代码语言:javascript
复制
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
}

确保闭包名称是描述性的和自文档化的。实际上,我发现它们比完整的描述更容易阅读……

闭包定义是这样定义的:

代码语言:javascript
复制
def fillOutPersonForm = {
    selenium.open("http://acme.racing.net/greport/personracereport.html")
    selenium.type("fname", "Britney")
    selenium.type("lname", "Smith")
}
票数 1
EN

Stack Overflow用户

发布于 2011-01-07 21:48:25

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

票数 1
EN

Stack Overflow用户

发布于 2011-01-24 23:57:46

作为SJG's answer的扩展,这里有一个以编程方式完成此操作的代码片段。

easyb documentation at http://www.easyb.org/running.html只描述了如何从命令行创建“故事”文本视图。使用Groovy代码完成此任务非常简单……

代码语言:javascript
复制
import org.easyb.BehaviorRunner

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

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

我仍然不确定需要哪些参数,以便在不运行测试的情况下只创建报告。这应该是可能的,见issue 165 fixed这将很好地添加到故事的最后部分,以便始终创建'user‘文档,上面的代码片段导致测试被执行,因此不能包含在相同的故事文件中,否则它将进入递归循环。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4224168

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档