Tobbe
Tobbe

Reputation: 149

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

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:

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

Regards Tobbe

Upvotes: 1

Views: 1467

Answers (1)

Tobbe
Tobbe

Reputation: 149

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

Upvotes: 2

Related Questions