grails - headless 运行 Geb + spock 测试

标签 grails spock geb xvfb

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

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

问题是测试不断失败,或者表现出意外,在没有意义的地方返回诸如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 测试的经验吗?你遇到过这些问题吗?

All tests are passing when executed locally, and this not a data issue as the DB is always cleared



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

最佳答案

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

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

关于grails - headless 运行 Geb + spock 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24185173/

相关文章:

hudson - 无法运行Webdriver测试,Hudson永远挂起

grails - 在 IntelliJ 中运行 grails 测试时遇到困难 : Illegal use of nonvirtual function call

testing - 在 Grails Spock 测试中是否有输出到 STDOUT 的方法?

spock - 如何使用 athaydes 插件仅对 geb 中的失败步骤进行屏幕截图

html - 浏览器无法正确解析HTML-Grails 2

Grails 2.0 和 servletContext

grails - 我应该在哪里将build.groovy文件放在我的grails项目中?

grails - 如何注入(inject)具有单例范围依赖关系的 Grails 2.4.x 服务?

android - 如何测试依赖于Android插件的本地Gradle插件?

user-interface - Geb 测试经常失败并出现 WaitTimeoutException : condition did not pass in 99. 0 秒