test_admin FT: wait on post-login content, not on <body> itself — pipeline #300 caught the flake (AssertionError: 'Site administration' not found in 'Django administration\nToggle theme...\nEmail:\nPassword:'); the pre-fix body = self.wait_for(lambda: self.browser.find_element(By.TAG_NAME, "body")) resolved on the FIRST <body> Selenium found — which exists on the login page too — so on a slow CI runner the form submit hadn't navigated yet by the time wait_for completed, the assertion ran against the still-stale login-page body, and the test failed; locally the submit always completes inside the wait window (10s MAX_WAIT) so this never reproduces; fix: wait_for the "Site administration" substring directly via assertIn (the wait decorator retries on AssertionError til MAX_WAIT, so the loop keeps polling the body's text content until the admin home page actually renders), THEN read body.text once + run the remaining Users / Tokens assertions inline — same shape as the working test_admin_tarot / test_admin_post_readonly login flows; 1 FT green locally w. no other changes — TDD
Code architected by Disco DeDisco <discodedisco@outlook.com> Git commit message Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -20,9 +20,15 @@ class AdminLoginTest(FunctionalTest):
|
||||
self.browser.find_element(By.ID, "id_password").send_keys("correct-password")
|
||||
self.browser.find_element(By.CSS_SELECTOR, "input[type=submit]").click()
|
||||
|
||||
body = self.wait_for(
|
||||
lambda: self.browser.find_element(By.TAG_NAME, "body")
|
||||
)
|
||||
self.assertIn("Site administration", body.text)
|
||||
# Wait on the post-login content, not on `body` itself — body exists
|
||||
# on the login page too, so a slow CI runner can grab the pre-submit
|
||||
# body before the form submit navigates and miss `Site administration`
|
||||
# entirely. Pipeline #300 ate this flake; locally the submit always
|
||||
# completes first. wait_for retries on AssertionError up to MAX_WAIT.
|
||||
self.wait_for(lambda: self.assertIn(
|
||||
"Site administration",
|
||||
self.browser.find_element(By.TAG_NAME, "body").text,
|
||||
))
|
||||
body = self.browser.find_element(By.TAG_NAME, "body")
|
||||
self.assertIn("Users", body.text)
|
||||
self.assertIn("Tokens", body.text)
|
||||
|
||||
Reference in New Issue
Block a user