borinquenkid commented on code in PR #15793:
URL: https://github.com/apache/grails-core/pull/15793#discussion_r3567142779
##########
grails-test-examples/scaffolding/src/integrationTest/groovy/com/example/pages/LoginPage.groovy:
##########
@@ -33,6 +33,9 @@ class LoginPage extends NavigationPage {
void login(String username = '[email protected]', String password =
'letmein') {
this.username = username
this.password = password
- clickAndWaitForNavigation(loginButton)
+ loginButton.click()
+ // Wait for a definitive authenticated signal: the login page must be
fully replaced
+ // (title changed AND the login form is gone), not merely a transient
title change.
+ waitFor(30) { title != pageTitle && $('input', name: 'username').empty
}
Review Comment:
Agreed on dropping the hardcoded `30`. One option, in case it's useful:
rather than falling back to a single global timeout, make the escalation opt-in
and scoped to just this call site, so it doesn't change the default for every
other test using this Page Object, but still gives the flaky path more patience
without re-running the interaction the way `@Retry` would:
```groovy
void login(String username, String password, List<Number> waitTimeouts =
[5]) {
usernameField = username
passwordField = password
loginButton.click()
waitForEscalating(waitTimeouts) {
title != pageTitle && $('input', name: 'username').empty
}
}
private <T> T waitForEscalating(List<Number> timeouts, Closure<T> condition)
{
def remaining = timeouts.iterator()
while (true) {
Number t = remaining.next()
try {
return waitFor(t, condition)
} catch (geb.waiting.WaitTimeoutException e) {
if (!remaining.hasNext()) throw e
}
}
}
```
Default callers get plain `waitFor(5)` (matches
`grails.geb.timeouts.timeout`'s default). Only the flaky spec would opt in with
`login(username, password, [5, 15, 45])`. Same idea would apply to
`LogoutPage.groovy`. Just floating this as an option — happy to go with plain
`waitFor()` too if that's preferred.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]