refactor: replace UI timeout magic numbers with named constants#935
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (10)
✅ Files skipped from review due to trivial changes (6)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughConsolidated hardcoded Playwright timeout values across the test suite into shared constants ( Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
testsuite/page_objects/policies/policies_new_page.py (1)
65-70: Make the first post-create wait use the same explicit timeout.
Line 66still relies on Playwright’s default timeout, so this step can fail before the longer reconciliation waits are reached on slower environments.Suggested patch
- self.page.wait_for_selector(f"text={self.policy_type} details") + self.page.wait_for_selector(f"text={self.policy_type} details", timeout=UI_PAGE_LOAD_TIMEOUT)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@testsuite/page_objects/policies/policies_new_page.py` around lines 65 - 70, The first post-create wait uses Playwright's default timeout; update the call to self.page.wait_for_selector(f"text={self.policy_type} details") to pass the same explicit timeout (UI_PAGE_LOAD_TIMEOUT) as used in the subsequent waits so all three waits use consistent, longer timeouts for reconciliation.testsuite/page_objects/policies/policies_list_page.py (1)
32-32: Use condition-based wait for table visibility inhas_policy()instead of fixed sleep.Fixed
wait_for_timeout()delays execution unconditionally and may hide readiness issues. Waiting on the table's visible state is more stable and faster.Proposed refactor
- self.page.wait_for_timeout(UI_ELEMENT_TIMEOUT) + self.page.locator("//table").first.wait_for(state="visible", timeout=UI_ELEMENT_TIMEOUT) locator = self.page.locator(f"//tr//a[`@data-test-id`='{name}']") return locator.count() > 0🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@testsuite/page_objects/policies/policies_list_page.py` at line 32, The fixed sleep call in has_policy() (self.page.wait_for_timeout(UI_ELEMENT_TIMEOUT)) should be replaced with a condition-based wait: wait for the policies table or its rows to become visible using the page/locator wait API (e.g., page.wait_for_selector(...) or locator.wait_for(state="visible")) before proceeding to check contents; update has_policy() to wait on the specific table/row selector or the existing table locator rather than using wait_for_timeout so the check is deterministic and faster.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@testsuite/page_objects/policies/policies_list_page.py`:
- Line 32: The fixed sleep call in has_policy()
(self.page.wait_for_timeout(UI_ELEMENT_TIMEOUT)) should be replaced with a
condition-based wait: wait for the policies table or its rows to become visible
using the page/locator wait API (e.g., page.wait_for_selector(...) or
locator.wait_for(state="visible")) before proceeding to check contents; update
has_policy() to wait on the specific table/row selector or the existing table
locator rather than using wait_for_timeout so the check is deterministic and
faster.
In `@testsuite/page_objects/policies/policies_new_page.py`:
- Around line 65-70: The first post-create wait uses Playwright's default
timeout; update the call to
self.page.wait_for_selector(f"text={self.policy_type} details") to pass the same
explicit timeout (UI_PAGE_LOAD_TIMEOUT) as used in the subsequent waits so all
three waits use consistent, longer timeouts for reconciliation.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 4b96b16d-6cf5-40c2-ba8c-c4896f139ae9
📒 Files selected for processing (10)
testsuite/page_objects/nav_bar.pytestsuite/page_objects/overview/overview_page.pytestsuite/page_objects/policies/auth_policy.pytestsuite/page_objects/policies/dns_policy.pytestsuite/page_objects/policies/policies_list_page.pytestsuite/page_objects/policies/policies_new_page.pytestsuite/page_objects/policies/rate_limit_policy.pytestsuite/page_objects/policies/tls_policy.pytestsuite/tests/singlecluster/ui/console_plugin/conftest.pytestsuite/tests/singlecluster/ui/console_plugin/constants.py
56e032a to
72a8abc
Compare
zkraus
left a comment
There was a problem hiding this comment.
Found one stray magic number, please also include that as a constant.
I ran a git grep -e '[0-9]\+' in testsuite/tests/singlecluster/ui and it seems that no other magic number for timeout appears.
|
UI tests are passing on my machine, refactor is functionally ok. |
Signed-off-by: emmaaroche <eroche@redhat.com>
72a8abc to
591a130
Compare
zkraus
left a comment
There was a problem hiding this comment.
Requested change addressed as expected.
Tests are passing.
LGTM.
Description
UI_PAGE_LOAD_TIMEOUT,UI_NAVIGATION_TIMEOUT,UI_ELEMENT_TIMEOUT) to improve code maintainability and consistencyconstants.pymodule to avoid cyclic import issues betweenconftest.pyand page objectsContributes to #930 - effort to eliminate magic numbers across the test suite
Changes
New Constants Module (
constants.py)testsuite/tests/singlecluster/ui/console_plugin/constants.pyto hold timeout constantsUI_PAGE_LOAD_TIMEOUT = 60000(60s) for page navigation, editor loads, and major UI elementsUI_NAVIGATION_TIMEOUT = 30000(30s) for URL changes and navigation state transitionsUI_ELEMENT_TIMEOUT = 10000(10s) for quick element interactions (buttons, form fields)conftest.pyimports page objects (likeNavBar) which now import these constantsRefactored Files (9 total)
testsuite/tests/singlecluster/ui/console_plugin/conftest.py- imports constants, updated 4 timeout usagestestsuite/page_objects/nav_bar.py- replaced 2 hardcoded60000withUI_PAGE_LOAD_TIMEOUTtestsuite/page_objects/overview/overview_page.py- replaced60000and10000with appropriate constantstestsuite/page_objects/policies/auth_policy.py- replaced60000withUI_PAGE_LOAD_TIMEOUTtestsuite/page_objects/policies/rate_limit_policy.py- replaced60000withUI_PAGE_LOAD_TIMEOUTtestsuite/page_objects/policies/dns_policy.py- replaced 3 hardcoded timeouts with constantstestsuite/page_objects/policies/tls_policy.py- replaced 2 hardcoded60000withUI_PAGE_LOAD_TIMEOUTtestsuite/page_objects/policies/policies_new_page.py- replaced policy enforcement timeouts withUI_PAGE_LOAD_TIMEOUTtestsuite/page_objects/policies/policies_list_page.py- replaced 5 hardcoded timeouts across delete operations and list loadingVerification steps
No new test files added.
To verify the refactoring didn't break anything, run existing UI tests:
Summary by CodeRabbit