On Mon, Aug 22, 2016 at 2:53 PM, Marcin Erdmann
<[email protected]> wrote:
> Brian,
>
> One thing that I don't understand is why you see a different behaviour if
> the condition is fulfilled (i.e. there is no StaleElementReferenceException)
> and when it is not. Is it the case that the value of the date field does not
> change when your test passes?

Yes, the value of the field does not change.


> A slightly better way of avoiding the exception would be to wrap the
> extraction of the element value in a waitFor:
>
> waitFor { labRequest[0].dateField.value() } == requestDate
>
> This way you will utilise the fact that waitFor() retries if there is an
> exception thrown from the closure passed to it.

I agree. Here's what I ended up using (slightly different from your
suggestion above, but I think it follows the spirit):

            waitFor(0) {
                labRequest[0].dateField == requestDate
            }

Using this, when the comparison succeeds, the test passes. When the
comparison fails, the test immediately fails and geb shows the
expected and actual value:

condition did not pass in 0.0 seconds (failed with exception)
.....
Caused by: Assertion failed:

labRequest[0].dateField == requestDate
|         |   |         |  |
|         |   |         |  2016-02-02T00:00
|         |   |         false
|         |   dateField - SimplePageContent (owner: labRequest -
LabAnalysisRequestRow (owner: ProjectDetailPage, args: [], value:
null), args: [], value: 2016-02-03T00:00)
......

Of course, this isn't a general solution, as if possible we don't want
to put waitFor's around all our assertions.

>
> Anyhow you should probably use a better wait for condition to wait for the
> page to stabilise after performing the action that triggers DOM updates. The
> one you shared previously, that is waitFor {
> labRequest[0].labNameField.value() }, clearly did not work given the
> behaviour you observed after introducing it.

You are correct. The one I shared previously was incorrect, a
cut/paste mistake on my part. Thank you for catching this.

Thanks for all your expertise contributed on this email thread.

-- 
You received this message because you are subscribed to the Google Groups "Geb 
User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/geb-user/CAMvxi925%3D235xU6eGrV%2BLX7gp9wJF-qWQ0hB%3Dr%3DUVUQPYGrfig%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to