handle cross-origin redirect in Cypress tests#2387
Conversation
WalkthroughTest code for validating external links and upgrade banners in the Applications and Forms pages was refactored to extract and verify Changes
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
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
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (4)
tests/cypress/e2e/Forms/formsSettings.cy.js (2)
117-119:cy.originblock is fragile – add an explicit visit or URL waitThe code assumes the redirect into
formidableforms.comhas completed before thecy.origincallback executes. In CI this can be timing-sensitive and occasionally leave the command queue on the WP origin, causing “cross origin” errors.Consider either:
- Passing the destination URL and explicitly visiting it inside the
cy.originblock, or- 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: Avoidforce: trueclicks on generic selectorsForcing 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 incy.origincan drift fromhrefThe banner occasionally points to staging or a locale-specific sub-domain. Binding
cy.origintohttps://formidableforms.comwhile visitinghrefrisks 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 retrievedhrefactually targets FormidableFormsBefore jumping into the cross-origin block we only assert that a
hrefexists. If the DOM changes and the link points elsewhere the test would still pass until thecy.origincall 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
📒 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
No description provided.