grails “test-app” fails for functional geb+spock test but “test-app -functional” is successfull

懵懂的女人 提交于 2019-12-11 14:41:50

问题


I have some problems regarding functional testing in Grails using GEB+Spock. If i run "test-app" it always fails, but if i run "test-app -integration" before "test-app" it works!

The following test-sequence illustrates my problem:

Run #1

grails> clean
grails> test-app -functional
...
Tests PASSED

Run #2

grails> clean
grails> test-app
...
Tests FAILED

Run #3

grails> clean
grails> test-app -functional
...
Test PASSED
grails> test-app
...
Test PASSED

The tests that are failing are throwing "geb.waiting.WaitTimeoutException: condition did not pass in 10.0 seconds". It is worth noting that the test cases that are failing are waiting for results from a database query.

So my question is what exactly is the difference then the functional tests are run through "test-app -integration" versus "test-app"?

The only difference from what i thought was that "test-app" is running all test phases (unit, integration, functional).

And the weird thing is that it do works somehow, but only if i run "test-app -integration" first :/

Im using the following setup:

  • grails 2.0.1
  • geb 0.7.0
  • spock 0.6
  • htmlunit-driver 2.0rc3 (ive tried with 2.20.0 but gave me even more problems)

Really hoping that someone can help me on this. Geb+spock seems like a nice solution, when it works...

Regards Tobbe


回答1:


I managed to solve this problem and writing the solution here for others if interested. THe solution was found by using geb report function (great tool!)

The Problem was that im using grails ZKUI alot in the application that the functional tests are working against and zkui generated different html-code in the different test scenarios (yep this is really odd).

For example a zk button i the composer:

<z:button id="simpleSearchButton" class="simpleSearchButton"/>

When running "test-app -integration" it generated the following:

<span id="cECQ4" class="simpleSearchButton z-button"><table id="cECQ4-box" style=""     cellpadding="0" cellspacing="0" border="0"><tbody><tr><td class="z-button-tl"/><td class="z-button-tm"/><td class="z-button-tr"/></tr><tr><td class="z-button-cl"><button type="button" id="cECQ4-btn" class="z-button"/></td><td class="z-button-cm"><img src="/certservice-admin/images/search.png;jsessionid=2ADDD6FA5F1D011A96E447435514BDA2" align="absmiddle"/></td><td class="z-button-cr"><div></div></td></tr><tr><td class="z-button-bl"/>td class="z-button-bm"/><td class="z-button-br"/></tr></tbody></table></span>

But when running "test-app" it generated the following:

<button type="button" id="l9AP4" class="simpleSearchButton z-button-os"><img src="/certservice-admin/images/search.png;jsessionid=835A2B8A3FE0C54341BB4F109A0CCC62" align="absmiddle"/></button>

In my Page object i defined the button as:

simpleSearchButton(required: false) { $("span.simpleSearchButton") }

Which failed with "test-app" but not with "test-app -integration". The simple solution to the hard/wierd problem was:

simpleSearchButton(required: false) { $(".simpleSearchButton") }

:)

Cheers /Tobbe



来源:https://stackoverflow.com/questions/10324664/grails-test-app-fails-for-functional-gebspock-test-but-test-app-functional

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!