【问题标题】:Running Geb + spock tests headless无头运行 Geb + spock 测试
【发布时间】:2014-08-02 19:46:30
【问题描述】:

我对一个 grails 应用程序进行了许多 geb 功能测试。

从终端或 IDE 执行测试时,测试按预期工作。 虽然测试需要由 hudson 执行,所以它们使用 Xvfb 以无头模式运行。

问题在于测试不断失败,或者表现出意外,在没有意义的地方返回诸如RequiredPageContentNotPresent 和Stale Element Reference Exception 之类的错误。

例如: (在上面验证了LicencePage,并且页面没有改变)

when:
   addDocument(Data.Test_Doc_name,Data.Test_Doc_file)

有时会抛出

 Failure:  Add Actual Licence (HomePageSpec)
|  geb.error.RequiredPageContentNotPresent: The required page content 'addDocument - SimplePageContent (owner: LicencePage, args: [Functional Test Doc, /var/lib/hudson/jobs/KB-Functional_Tests/workspace/app/../manual_test_data/so_v3/os_test_1], value: null)' is not present
    at geb.content.TemplateDerivedPageContent.require(TemplateDerivedPageContent.groovy:61)
    at geb.content.PageContentTemplate.create_closure1(PageContentTemplate.groovy:63)
    at geb.content.PageContentTemplate.create(PageContentTemplate.groovy:82)
    at geb.content.PageContentTemplate.get(PageContentTemplate.groovy:54)
    at geb.content.NavigableSupport.getContent(NavigableSupport.groovy:45)
    at geb.content.NavigableSupport.methodMissing(NavigableSupport.groovy:121)
    at geb.Browser.methodMissing(Browser.groovy:194)
    at geb.spock.GebSpec.methodMissing(GebSpec.groovy:51)
    at HomePageSpec.Add Actual Licence (HomePageSpec.groovy:228)

方法addDocument() 定义在一个“抽象”页面上,LicencePage 正在扩展该页面。在大多数情况下,如果我将方法代码直接复制到我的规范中,它就会起作用,尽管它破坏了我在测试页面上的所有结构。

谁有使用 Xvfb 运行 geb 测试的经验?你遇到过这些问题吗?

所有测试在本地执行时都通过了,这不是数据问题,因为数据库总是被清除

此外,如果不进行任何更改,测试的行为是不确定的(在 hudson 上),因此并不总是抛出上述异常。完全不做任何更改,测试有时会成功,有时会失败。

【问题讨论】:

    标签: grails spock geb xvfb


    【解决方案1】:

    您给出的描述似乎是一个笨拙的测试套件的症状。我们前段时间也面临这个问题。一个很好的起点是 presentation(大约 35 分钟左右)和 documentation 关于 geb 中的等待内容。

    如果您认为它可能与 xvfb(我没有经验)有关,您可以尝试使用 phantomjs 作为测试运行器并检查它是否正常工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多