以下是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弄得一团糟。
答案 0 :(得分: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")
}
答案 1 :(得分:1)
实际上,我相信这已经是通过ANT集成的easyb功能。查看“故事打印”部分下的http://www.easyb.org/running.html。
答案 2 :(得分:1)
作为SJG's answer的扩展,这里是一个以编程方式执行此操作的代码段。
easyb documentation at http://www.easyb.org/running.html仅描述了如何从命令行创建“Story”文本视图。使用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将它添加为故事的最后一部分以便始终创建“用户”文档会很好,上面的代码片段会导致测试被执行,所以不能包含在同一个故事文件中,否则它将进入一个递归循环。