Skip to content

handle cross-origin redirect in Cypress tests#2387

Merged
Crabcyborg merged 1 commit into
masterfrom
fix-cross-origin-failures
Jun 11, 2025
Merged

handle cross-origin redirect in Cypress tests#2387
Crabcyborg merged 1 commit into
masterfrom
fix-cross-origin-failures

Conversation

@lauramekaj1
Copy link
Copy Markdown
Contributor

No description provided.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 10, 2025

Walkthrough

Test code for validating external links and upgrade banners in the Applications and Forms pages was refactored to extract and verify href attributes before navigation. Assertions were made more robust by including checks for presence and correctness of attributes, and explicit failure messages were added for invalid cases. Additionally, form settings tests now perform immediate cleanup and use more flexible URL assertions.

Changes

File(s) Change Summary
tests/cypress/e2e/Applications/validateApplicationsPage.cy.js Refactored test to extract and verify the "Upgrade to Pro" button's href before visiting the external URL.
tests/cypress/e2e/Forms/formPageDataValidation.cy.js Improved banner link validation by extracting href, adding presence checks, and consolidating navigation logic.
tests/cypress/e2e/Forms/formsSettings.cy.js Moved form deletion to the end of the test, changed URL assertions to substring checks, and adjusted formatting.

Sequence Diagram(s)

sequenceDiagram
    participant TestRunner
    participant AppPage
    participant ExternalSite

    TestRunner->>AppPage: Visit Applications/Forms page
    TestRunner->>AppPage: Locate upgrade button/banner
    AppPage-->>TestRunner: Provide button/banner element with href
    TestRunner->>TestRunner: Extract and verify href
    alt href is valid
        TestRunner->>ExternalSite: Visit extracted href (cy.origin)
        ExternalSite-->>TestRunner: Render external page
        TestRunner->>ExternalSite: Assert heading text
    else href is missing/invalid
        TestRunner->>TestRunner: Fail test with message
    end
Loading
sequenceDiagram
    participant TestRunner
    participant FormsPage
    participant Server

    TestRunner->>FormsPage: Create new form
    FormsPage-->>TestRunner: Form created
    TestRunner->>FormsPage: Update form settings
    FormsPage-->>TestRunner: Settings updated
    TestRunner->>FormsPage: Verify redirect URL (substring check)
    TestRunner->>Server: Delete form (cleanup)
    Server-->>TestRunner: Form deleted
Loading
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@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: 2

🧹 Nitpick comments (4)
tests/cypress/e2e/Forms/formsSettings.cy.js (2)

117-119: cy.origin block is fragile – add an explicit visit or URL wait

The code assumes the redirect into formidableforms.com has completed before the cy.origin callback executes. In CI this can be timing-sensitive and occasionally leave the command queue on the WP origin, causing “cross origin” errors.

Consider either:

  1. Passing the destination URL and explicitly visiting it inside the cy.origin block, or
  2. Waiting for the location to change in the outer context before asserting.

Example fix:

-cy.origin('https://formidableforms.com', () => {
-  cy.location('href').should('include', 'https://formidableforms.com/')
-});
+const target = 'https://formidableforms.com/';
+cy.origin(target, { args: { target } }, ({ target }) => {
+  cy.visit(target); // guarantees we are on the correct origin
+  cy.location('href').should('include', target);
+});

Also applies to: 131-133


75-76: Avoid force: true clicks on generic selectors

Forcing a click on a[aria-label='Close'] can hide legitimate failures (e.g., the modal never opened). Prefer asserting visibility / interactability instead of bypassing it, or add a more specific data-cy attribute to reduce selector brittleness.

tests/cypress/e2e/Forms/formPageDataValidation.cy.js (1)

21-31: Hard-coded host in cy.origin can drift from href

The banner occasionally points to staging or a locale-specific sub-domain. Binding cy.origin to https://formidableforms.com while visiting href risks a domain mismatch error. Extract the host dynamically to keep the assertion future-proof:

- cy.origin('https://formidableforms.com', { args: { href } }, ({ href }) => {
+ const { protocol, host } = new URL(href);
+ cy.origin(`${protocol}//${host}`, { args: { href } }, ({ href }) => {
tests/cypress/e2e/Applications/validateApplicationsPage.cy.js (1)

17-31: Ensure the retrieved href actually targets FormidableForms

Before jumping into the cross-origin block we only assert that a href exists. If the DOM changes and the link points elsewhere the test would still pass until the cy.origin call explodes.

Add a quick sanity check so the intent is explicit and failures are clearer:

-  .should('have.attr', 'href')
+  .should('have.attr', 'href')
+  .and('include', 'https://formidableforms.com')
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e52e239 and ac953c5.

📒 Files selected for processing (3)
  • tests/cypress/e2e/Applications/validateApplicationsPage.cy.js (1 hunks)
  • tests/cypress/e2e/Forms/formPageDataValidation.cy.js (3 hunks)
  • tests/cypress/e2e/Forms/formsSettings.cy.js (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (18)
  • GitHub Check: Run Rector inspection
  • GitHub Check: PHP 7.4 tests in WP trunk
  • GitHub Check: Cypress
  • GitHub Check: PHP 8 tests in WP trunk
  • GitHub Check: Run PHP Syntax inspection (8.3)
  • GitHub Check: Run PHPCS inspection
  • GitHub Check: Cypress
  • GitHub Check: Run PHPCS inspection
  • GitHub Check: PHP 8 tests in WP trunk
  • GitHub Check: Run PHP Syntax inspection (8.3)
  • GitHub Check: Psalm
  • GitHub Check: PHP 7.4 tests in WP trunk
  • GitHub Check: Run PHPCS inspection
  • GitHub Check: PHP 7.4 tests in WP trunk
  • GitHub Check: PHP 8 tests in WP trunk
  • GitHub Check: Cypress
  • GitHub Check: Run PHP Syntax inspection (8.3)
  • GitHub Check: Run ESLint

Comment thread tests/cypress/e2e/Forms/formsSettings.cy.js
Comment thread tests/cypress/e2e/Forms/formPageDataValidation.cy.js
@lauramekaj1 lauramekaj1 requested a review from Crabcyborg June 10, 2025 22:44
Copy link
Copy Markdown
Contributor

@Crabcyborg Crabcyborg left a comment

Choose a reason for hiding this comment

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

Thank you @lauramekaj1!

These changes look good.

🙌

@Crabcyborg Crabcyborg merged commit 7a09b2a into master Jun 11, 2025
36 checks passed
@Crabcyborg Crabcyborg deleted the fix-cross-origin-failures branch June 11, 2025 14:19
@coderabbitai coderabbitai Bot mentioned this pull request Aug 12, 2025
@coderabbitai coderabbitai Bot mentioned this pull request Aug 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants