下面是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搞糊涂了。
发布于 2010-11-19 22:46:38
可能不会有合理的努力。不过,您可以很容易地在外部定义代码闭包。然后,“人类可读”部分将如下所示:
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")
}发布于 2011-01-07 21:48:25
实际上,我相信这已经是easyb通过ANT集成的一个特性了。查看http://www.easyb.org/running.html,在“故事打印”部分下。
发布于 2011-01-24 23:57:46
作为SJG's answer的扩展,这里有一个以编程方式完成此操作的代码片段。
easyb documentation at 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作为第二个参数。
我仍然不确定需要哪些参数,以便在不运行测试的情况下只创建报告。这应该是可能的,见issue 165 fixed这将很好地添加到故事的最后部分,以便始终创建'user‘文档,上面的代码片段导致测试被执行,因此不能包含在相同的故事文件中,否则它将进入递归循环。
https://stackoverflow.com/questions/4224168
复制相似问题