0

We're creating E2E tests in Cypress. One of our tests shows a list of banks to which you can be redirected to complete a payment. After clicking a specific bank with the following code:

cy.get('.modal')
  .contains('Bunq')
  .click()

The following happens:

  1. A request is sent to our back-end http://localhost:4200/api/bunq which responds with an redirect url
  2. The browser is redirected to the redirect URL which is another domain: https://example.com?_id=uniqueIdGeneratedAfterButtonClick. Please note that we can only generate this link after the user has clicked one of the options!

Obviously we could mimmic the request that happens after the click with cy.request and check the response for validity. But I am curious if Cypress can confirm that the browser is indeed redirected to another domain (e.g. catching the error that is thrown).

  • Is there a reason you can't just check what page it's on afterwards? See e.g. stackoverflow.com/q/46839520/3001761 – jonrsharpe Apr 10 at 7:07
  • Redirection means just a different site in the current browser tab? If so, I guess you can check whatever there is on the site, including the url with cy.url(). – pavelsaman Apr 10 at 7:11
  • @jonrsharpe yes there is, since it is another domain it fails to load Refused to display 'https://api.pay.nl/xxxxxxx' in a frame because it set 'X-Frame-Options' to 'sameorigin'.. Therefore calling cy.url() afterwards does not give me the URL to which we are redirected in the end. – TimNode Apr 10 at 10:19
  • 1
    This is useful context to include in the question. – jonrsharpe Apr 10 at 10:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.