Skip to content

refactor(e2e): Replace arbitrary waits with state-based waiting in flag tests#6829

Closed
talissoncosta wants to merge 1 commit intomainfrom
chore/improve-flag-tests-wait-strategy-clean
Closed

refactor(e2e): Replace arbitrary waits with state-based waiting in flag tests#6829
talissoncosta wants to merge 1 commit intomainfrom
chore/improve-flag-tests-wait-strategy-clean

Conversation

@talissoncosta
Copy link
Contributor

@talissoncosta talissoncosta commented Mar 2, 2026

Summary

Improves E2E test reliability and speed by replacing arbitrary timeout waits with proper state-based waiting in flag-tests.

Changes

Replace fixed t.wait(500) timeouts with waitForElementVisible('#try-it-results') in three locations within flag-tests.ts.

Why This Approach is Better

Fixed timeouts:

await t.wait(500)  // Hope this is enough
  • Too short = flaky tests
  • Too long = slow tests
  • Doesn't adapt to different environments (local vs staging vs CI)

State-based waiting:

await waitForElementVisible('#try-it-results')  // Wait for actual state
  • Fast when API responds quickly (no artificial delays)
  • Reliable when API is slow (uses 40s timeout)
  • Works consistently across all environments

Technical Details

The #try-it-results element only receives its ID when !this.state.isLoading (TryIt.js:82), guaranteeing:

  • API request completed
  • State updated
  • Results rendered and ready to parse

This is the standard pattern already used throughout our E2E test suite.

Test Plan

  • Run E2E tests locally: make test
  • Verify all E2E tests pass in CI

…ag tests

Replace fixed 500ms timeouts with `waitForElementVisible('#try-it-results')`
to wait for the actual loading state to complete. This approach:

- Eliminates race conditions on slow CI runners
- Runs faster when API responds quickly (no artificial 500ms delays)
- More semantically correct (waits for the element we actually need)
- Consistent with E2E best practices already used elsewhere

The #try-it-results element only receives its ID when the TryIt component
finishes loading (isLoading: false), making it the perfect indicator to
wait for rather than guessing arbitrary timeout values.

Related: #6827 (increased timeouts from 500ms to 2000ms/1500ms)
This PR provides a better alternative to arbitrary timeout increases.
@talissoncosta talissoncosta requested a review from a team as a code owner March 2, 2026 20:20
@talissoncosta talissoncosta requested review from kyle-ssg and removed request for a team March 2, 2026 20:20
@vercel
Copy link

vercel bot commented Mar 2, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
flagsmith-frontend-preview Building Building Preview, Comment Mar 2, 2026 8:20pm
flagsmith-frontend-staging Building Building Preview, Comment Mar 2, 2026 8:20pm
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Ignored Ignored Mar 2, 2026 8:20pm

Request Review

@github-actions github-actions bot added front-end Issue related to the React Front End Dashboard refactor labels Mar 2, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2026

Docker builds report

Image Build Status Security report
ghcr.io/flagsmith/flagsmith-api-test:pr-6829 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-e2e:pr-6829 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-api:pr-6829 Finished ✅ Results
ghcr.io/flagsmith/flagsmith:pr-6829 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-private-cloud:pr-6829 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-frontend:pr-6829 Finished ✅ Results

@matthewelwell
Copy link
Contributor

@talissoncosta I don't think this will work. The issue is that the tests will also need to wait for the feature change to propagate from the Core API, to dynamodb (London), and then get replicated to the dynamodb table in the US. That can take a second or 2 some times. If we want to make this more robust, we'd need to have it keep trying the try it button until it gets the result it's expecting. Until then, I suggest we go with the longer static timeouts.

@matthewelwell
Copy link
Contributor

Closing based on the above comment. We can perhaps revisit replacing at least the first wait once we merge the playwright changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

front-end Issue related to the React Front End Dashboard refactor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants