代码之家  ›  专栏  ›  技术社区  ›  Armand

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

  •  0
  • Armand  · 技术社区  · 14 年前

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

    3 回复  |  直到 12 年前
        1
  •  1
  •   robbbert    14 年前

    可能没有正当的努力。不过,您可以很容易地在外部定义代码闭包。“人类可读”部分如下:

    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")
    }
    
        2
  •  1
  •   SJG    14 年前

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

        3
  •  1
  •   Community datashaman    7 年前

    作为 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 最好将它添加为一个故事的最后一部分,这样总是创建“用户”文档,上面的代码片段会导致执行测试,因此不能包含在同一个故事文件中,否则它将进入递归循环。