Skip to content

fix(e2e): add visibility waits for new-session-btn to fix timing issues#971

Closed
Gkrumbach07 wants to merge 1 commit intomainfrom
fix/e2e-test-failures
Closed

fix(e2e): add visibility waits for new-session-btn to fix timing issues#971
Gkrumbach07 wants to merge 1 commit intomainfrom
fix/e2e-test-failures

Conversation

@Gkrumbach07
Copy link
Contributor

Summary

Fixes the E2E test failures across multiple PRs by adding proper visibility checks before clicking the new-session-btn.

Problem

The E2E tests were failing with:

AssertionError: Timed out retrying after 10000ms: Expected to find element: `[data-testid="new-session-btn"]`, but never found it.

This caused all 58 tests to be skipped in the before() hook, failing the E2E suite on PRs #962, #964, #965, and others.

Root Cause

The workspace page (/projects/{slug}) shows a loading spinner while fetching project data. The test's cy.request() API calls complete successfully, but the UI is still rendering. When the test immediately tries to click new-session-btn, the page is still showing the loading state, so the button doesn't exist yet.

Solution

Added should('be.visible') checks before clicking the button in three places:

  1. before() hook (line 80) - with 20s timeout
  2. "should open create session dialog" test (line 184)
  3. "Agent Interaction" test (line 248)

This ensures the button is fully rendered and interactive before the test attempts to click it.

Test Plan

🤖 Generated with Claude Code

The E2E tests were failing because they attempted to click the
new-session-btn before the workspace page finished loading. The page
shows a loading spinner while fetching project data, and the test's
cy.request() calls don't wait for the UI to render.

Changes:
- Add `should('be.visible')` check before clicking new-session-btn in
  the before() hook (with 20s timeout)
- Add `should('be.visible')` to existing timeout checks in other tests
- Ensures the button is rendered and interactive before interaction

This fixes the "Expected to find element: [data-testid="new-session-btn"],
but never found it" error that was causing all 58 tests to be skipped.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@coderabbitai
Copy link

coderabbitai bot commented Mar 19, 2026

Walkthrough

Updated Cypress e2e test file to add explicit visibility waits and assertions before interacting with the "new session" button. Changes include adding timeout parameters and .should('be.visible') checks across multiple test cases to improve test stability.

Changes

Cohort / File(s) Summary
Test Stability Enhancement
e2e/cypress/e2e/sessions.cy.ts
Added explicit visibility waits with timeout configurations (10s and 20s) and .should('be.visible') assertions before clicking the new-session-btn element across three test cases to prevent premature interaction attempts.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: adding visibility waits for the new-session-btn to fix timing issues in E2E tests.
Description check ✅ Passed The description is well-detailed and directly related to the changeset, explaining the problem, root cause, and solution for the E2E test failures.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/e2e-test-failures
📝 Coding Plan
  • Generate coding plan for human review comments

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


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

Copy link

@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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@e2e/cypress/e2e/sessions.cy.ts`:
- Around line 80-82: Chained element queries are inconsistent: instead of
calling cy.get(selector, { timeout: ... }) and then re-querying the same
selector before clicking, chain .click() directly off the initial cy.get call
used around lines 80–82 in sessions.cy.ts (replace the redundant
cy.get(...).click() with the original cy.get(..., { timeout: ... }).click()).
Remove the duplicate query so the click uses the timeout-aware subject and
matches the chaining pattern used elsewhere (e.g., the patterns at lines ~184
and ~248).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 21e30491-c41f-468f-a65e-287178041021

📥 Commits

Reviewing files that changed from the base of the PR and between f8ac621 and 2c12e38.

📒 Files selected for processing (1)
  • e2e/cypress/e2e/sessions.cy.ts

Comment on lines +80 to 82
// Wait for the workspace page to finish loading before creating a session
cy.get('[data-testid="new-session-btn"]', { timeout: 20000 }).should('be.visible')
cy.get('[data-testid="new-session-btn"]').click()
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Redundant element query; chain the click for consistency.

Line 81 queries the element with a timeout, but line 82 re-queries without one. This is inconsistent with the chained pattern used in lines 184 and 248. Chain the click directly to avoid the redundant query.

Proposed fix
     // Wait for the workspace page to finish loading before creating a session
-    cy.get('[data-testid="new-session-btn"]', { timeout: 20000 }).should('be.visible')
-    cy.get('[data-testid="new-session-btn"]').click()
+    cy.get('[data-testid="new-session-btn"]', { timeout: 20000 }).should('be.visible').click()
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@e2e/cypress/e2e/sessions.cy.ts` around lines 80 - 82, Chained element queries
are inconsistent: instead of calling cy.get(selector, { timeout: ... }) and then
re-querying the same selector before clicking, chain .click() directly off the
initial cy.get call used around lines 80–82 in sessions.cy.ts (replace the
redundant cy.get(...).click() with the original cy.get(..., { timeout: ...
}).click()). Remove the duplicate query so the click uses the timeout-aware
subject and matches the chaining pattern used elsewhere (e.g., the patterns at
lines ~184 and ~248).

@Gkrumbach07
Copy link
Contributor Author

Closing this PR as obsolete. The E2E test timing issues have already been fixed on main via commit da4285c and commit 6a487e0, which refactored session creation to use direct API calls instead of UI interactions. This is a more robust solution than adding visibility waits, as it completely bypasses the UI rendering timing issues. The failures seen on PRs #962, #964, and #965 were on an older version of main that has since been updated.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant