Skip to content

Conversation

asirvadAbrahamVarghese
Copy link
Contributor

@asirvadAbrahamVarghese asirvadAbrahamVarghese commented Sep 9, 2025

  • Problem:

From beforeEach, intercepts & waits on "/api/tenants" endpoint (matched with regex "//api/tenants.*/"), method is POST here with alias name as "tenantOperationsApi":
image

When the API method changes(PUT), the wait fails due to validation relying solely on the alias name:
image

After:
Intercepts and waits when the API method is different.

Waits on POST:
image
Waits on PUT(key registered before was post-tenantOperationsApi):
image

  • Follow up work from here

To conditionally wait only when a request is actually initiated, allowing interceptApi to be reused across support commands, eliminating the need to intercept and wait in each test.

Why use Cypress.env for just a flag and not a let variable like let requestIntercepted?

When !isAlreadyRegistered is true (first registration) - works as expected:

  • Register a new intercept with a callback that sets requestIntercepted = true
  • Intercept’s callback runs when a request is detected
  • The cy.then() block sees the updated value - true
image

When !isAlreadyRegistered is false (already registered) - won't work as expected due to variable scope and closure in JavaScript:

  • No new intercept is registered
  • The previously registered intercept’s callback runs, but it’s modifying a different requestIntercepted variable from previous execution
  • The current execution’s requestIntercepted remains false in cy.then()
image

@miq-bot assign @jrafanie
@miq-bot add-label cypress
@miq-bot add-label test
@miq-bot add-label enhancement

Copy link
Member

@jrafanie jrafanie left a comment

Choose a reason for hiding this comment

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

LGTM

@jrafanie jrafanie merged commit 7cefa15 into ManageIQ:master Sep 9, 2025
18 checks passed
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.

3 participants