Skip to content

refactor: replace UI timeout magic numbers with named constants#935

Merged
emmaaroche merged 1 commit intoKuadrant:mainfrom
emmaaroche:add-ui-test-timeout-constants
Apr 14, 2026
Merged

refactor: replace UI timeout magic numbers with named constants#935
emmaaroche merged 1 commit intoKuadrant:mainfrom
emmaaroche:add-ui-test-timeout-constants

Conversation

@emmaaroche
Copy link
Copy Markdown
Contributor

@emmaaroche emmaaroche commented Apr 14, 2026

Description

  • Refactored UI test timeout values to use named constants instead of magic numbers across all page objects and test configuration
  • Introduced three semantic timeout constants (UI_PAGE_LOAD_TIMEOUT, UI_NAVIGATION_TIMEOUT, UI_ELEMENT_TIMEOUT) to improve code maintainability and consistency
  • All repeated timeout values (60s, 30s, 10s) replaced with appropriately named constants; single-use timeouts intentionally left as literals
  • Constants defined in a separate constants.py module to avoid cyclic import issues between conftest.py and page objects

Contributes to #930 - effort to eliminate magic numbers across the test suite

Changes

New Constants Module (constants.py)

  • Created testsuite/tests/singlecluster/ui/console_plugin/constants.py to hold timeout constants
  • Added UI_PAGE_LOAD_TIMEOUT = 60000 (60s) for page navigation, editor loads, and major UI elements
  • Added UI_NAVIGATION_TIMEOUT = 30000 (30s) for URL changes and navigation state transitions
  • Added UI_ELEMENT_TIMEOUT = 10000 (10s) for quick element interactions (buttons, form fields)
  • Added comprehensive documentation explaining timeout usage and Playwright behavior
  • Why separate file: Prevents cyclic imports since conftest.py imports page objects (like NavBar) which now import these constants

Refactored Files (9 total)

  • testsuite/tests/singlecluster/ui/console_plugin/conftest.py - imports constants, updated 4 timeout usages
  • testsuite/page_objects/nav_bar.py - replaced 2 hardcoded 60000 with UI_PAGE_LOAD_TIMEOUT
  • testsuite/page_objects/overview/overview_page.py - replaced 60000 and 10000 with appropriate constants
  • testsuite/page_objects/policies/auth_policy.py - replaced 60000 with UI_PAGE_LOAD_TIMEOUT
  • testsuite/page_objects/policies/rate_limit_policy.py - replaced 60000 with UI_PAGE_LOAD_TIMEOUT
  • testsuite/page_objects/policies/dns_policy.py - replaced 3 hardcoded timeouts with constants
  • testsuite/page_objects/policies/tls_policy.py - replaced 2 hardcoded 60000 with UI_PAGE_LOAD_TIMEOUT
  • testsuite/page_objects/policies/policies_new_page.py - replaced policy enforcement timeouts with UI_PAGE_LOAD_TIMEOUT
  • testsuite/page_objects/policies/policies_list_page.py - replaced 5 hardcoded timeouts across delete operations and list loading

Verification steps

No new test files added.

To verify the refactoring didn't break anything, run existing UI tests:

make ui

Summary by CodeRabbit

  • Chores
    • Standardised test infrastructure by introducing shared UI timeout constants and replacing scattered hardcoded timeouts across the test suite.
    • Results in more consistent, reliable UI tests and reduced flakiness during page loads and UI interactions, improving confidence in test outcomes.

@emmaaroche emmaaroche requested review from silvi-t and zkraus April 14, 2026 11:55
@emmaaroche emmaaroche self-assigned this Apr 14, 2026
@emmaaroche emmaaroche added the refactor Refactor with same functionality label Apr 14, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 14, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0cc0f73a-06af-42de-b439-3014110e3673

📥 Commits

Reviewing files that changed from the base of the PR and between 56e032a and 591a130.

📒 Files selected for processing (10)
  • testsuite/page_objects/nav_bar.py
  • testsuite/page_objects/overview/overview_page.py
  • testsuite/page_objects/policies/auth_policy.py
  • testsuite/page_objects/policies/dns_policy.py
  • testsuite/page_objects/policies/policies_list_page.py
  • testsuite/page_objects/policies/policies_new_page.py
  • testsuite/page_objects/policies/rate_limit_policy.py
  • testsuite/page_objects/policies/tls_policy.py
  • testsuite/tests/singlecluster/ui/console_plugin/conftest.py
  • testsuite/tests/singlecluster/ui/console_plugin/constants.py
✅ Files skipped from review due to trivial changes (6)
  • testsuite/page_objects/policies/auth_policy.py
  • testsuite/page_objects/overview/overview_page.py
  • testsuite/page_objects/policies/tls_policy.py
  • testsuite/page_objects/policies/policies_new_page.py
  • testsuite/tests/singlecluster/ui/console_plugin/conftest.py
  • testsuite/page_objects/policies/rate_limit_policy.py
🚧 Files skipped from review as they are similar to previous changes (3)
  • testsuite/page_objects/policies/dns_policy.py
  • testsuite/page_objects/policies/policies_list_page.py
  • testsuite/tests/singlecluster/ui/console_plugin/constants.py

📝 Walkthrough

Walkthrough

Consolidated hardcoded Playwright timeout values across the test suite into shared constants (UI_PAGE_LOAD_TIMEOUT, UI_NAVIGATION_TIMEOUT, UI_ELEMENT_TIMEOUT, UI_SESSION_INIT_TIMEOUT) and replaced numeric timeouts in multiple page objects and fixtures with these constants.

Changes

Cohort / File(s) Summary
Timeout Constants Definition
testsuite/tests/singlecluster/ui/console_plugin/constants.py
New module adding four exported UI timeout constants (60000, 30000, 10000, 2000 ms).
Test Setup & NavBar
testsuite/page_objects/nav_bar.py, testsuite/tests/singlecluster/ui/console_plugin/conftest.py
Replaced hardcoded page.goto, wait_for, and wait_for_url timeouts with UI_PAGE_LOAD_TIMEOUT, UI_NAVIGATION_TIMEOUT, and UI_SESSION_INIT_TIMEOUT.
Overview Page Object
testsuite/page_objects/overview/overview_page.py
Replaced hardcoded 60000/10000ms waits with UI_PAGE_LOAD_TIMEOUT and UI_ELEMENT_TIMEOUT.
Policy Page Objects (visibility & element waits)
testsuite/page_objects/policies/...
testsuite/page_objects/policies/auth_policy.py, .../dns_policy.py, .../policies_list_page.py, .../policies_new_page.py, .../rate_limit_policy.py, .../tls_policy.py
Replaced page and element wait timeouts with UI_PAGE_LOAD_TIMEOUT, UI_ELEMENT_TIMEOUT, and UI_NAVIGATION_TIMEOUT where appropriate (page_displayed, element waits, post-delete navigation).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested labels

Test case

Suggested reviewers

  • trepel
  • azgabur

Poem

🐰 Hopping through waits, I tidy each line,

Replacing numbers with constants that shine.
No more scattered timeouts to chase,
Tests feel calmer, one steady pace. ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: replacing hardcoded UI timeout values with named constants across the codebase.
Description check ✅ Passed The description comprehensively covers the refactoring with clear sections on rationale, new constants module, refactored files, and verification steps, following the repository template structure.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 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 66 still 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 in has_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

📥 Commits

Reviewing files that changed from the base of the PR and between ba58cec and 56e032a.

📒 Files selected for processing (10)
  • testsuite/page_objects/nav_bar.py
  • testsuite/page_objects/overview/overview_page.py
  • testsuite/page_objects/policies/auth_policy.py
  • testsuite/page_objects/policies/dns_policy.py
  • testsuite/page_objects/policies/policies_list_page.py
  • testsuite/page_objects/policies/policies_new_page.py
  • testsuite/page_objects/policies/rate_limit_policy.py
  • testsuite/page_objects/policies/tls_policy.py
  • testsuite/tests/singlecluster/ui/console_plugin/conftest.py
  • testsuite/tests/singlecluster/ui/console_plugin/constants.py

@emmaaroche emmaaroche force-pushed the add-ui-test-timeout-constants branch from 56e032a to 72a8abc Compare April 14, 2026 12:08
Copy link
Copy Markdown
Contributor

@zkraus zkraus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread testsuite/tests/singlecluster/ui/console_plugin/conftest.py Outdated
@zkraus
Copy link
Copy Markdown
Contributor

zkraus commented Apr 14, 2026

UI tests are passing on my machine, refactor is functionally ok.

Signed-off-by: emmaaroche <eroche@redhat.com>
@emmaaroche emmaaroche force-pushed the add-ui-test-timeout-constants branch from 72a8abc to 591a130 Compare April 14, 2026 13:05
@emmaaroche emmaaroche requested a review from zkraus April 14, 2026 13:15
Copy link
Copy Markdown
Contributor

@zkraus zkraus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requested change addressed as expected.
Tests are passing.
LGTM.

@emmaaroche emmaaroche merged commit ed20455 into Kuadrant:main Apr 14, 2026
6 checks passed
@emmaaroche emmaaroche deleted the add-ui-test-timeout-constants branch April 14, 2026 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Refactor with same functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants