cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
46.43k stars 3.14k forks source link

Cypress Test runner getting exit while redirect #23751

Open nitish-Datman opened 1 year ago

nitish-Datman commented 1 year ago

Current behavior

while running the test , cypress runner getting disappeared on redirect,

Desired behavior

cypress runner should still be visible on redirect

Test code to reproduce

describe("test", function () {
  it("create payment", function () {

cy.visit(*********) //provide any url that redirect to another url 
})
})

https://user-images.githubusercontent.com/62381266/189370370-c5597087-2d1d-478c-b043-56f31c0c2ce6.mov

Cypress Version

10.6.0

Node version

v16.16.0

Operating System

macOS 11.2.3

Debug Logs

No response

Other

No response

nitish-Datman commented 1 year ago

@emilyrohrbough let me know if this can be resolved

emilyrohrbough commented 1 year ago

@nitish-Datman It appears the redirect is busting out of the AUT (application under test) iframe. Have you tried/considered enabling modifyObstructiveCode to see if this prevent this behavior?

nitish-Datman commented 1 year ago

@emilyrohrbough i have tried , did not help

Yonhoo commented 1 year ago

i meet the same issue, when request my domain , the response submit redirect html ,then cypress runner getting exit, jump to redirect domain , can i know cy.origin can cover it?

nitish-Datman commented 1 year ago

@jennifer-shehane can this be resolved please

chrisbreiding commented 1 year ago

Right now there doesn't seem to be enough information to reproduce the problem on our end. Unless we receive a reliable reproduction, we'll eventually have to close this issue until we can reproduce it. This does not mean that your issue is not happening - it just means that we do not have a path to move forward.

Please provide a reproducible example of the issue you're encountering. Here are some tips for providing a Short, Self Contained, Correct, Example and our own Troubleshooting Cypress guide.

nitish-Datman commented 1 year ago

describe("Test", function () {
  it("Test flow", function () {

    cy.visit('http://shorturl.at/IMNQV')
    cy.get(nameOnCard_input, { timeout: 25000 }).type("nitish");

    cy.get("#cardNumber")
      .iframeLoaded()
      .its("document")
      .getInDocument('input[name="cardnumber"]')
      .type('4929421234600821');

    cy.get("#expiryDate")
      .iframeLoaded()
      .its("document")
      .getInDocument('input[name="exp-date"]')
      .type('1123');

      cy.get("#cvv")
      .iframeLoaded()
      .its("document")
      .getInDocument('input[name="cvc"]')
      .type('356');

      cy.xpath("//body/div[@id='__next']/div[1]/section[2]/div[2]/div[1]/form[1]/div[1]/button[1]")
      .click()

   });
});`

add this in command.js

Cypress.Commands.add(
  'iframeLoaded',
  { prevSubject: 'element' },
  ($iframe) => {
    const contentWindow = $iframe.prop('contentWindow')
    return new Promise(resolve => {
      if (
        contentWindow &&
        contentWindow.document.readyState === 'complete'
      ) {
        resolve(contentWindow)
      } else {
        $iframe.on('load', () => {
          resolve(contentWindow)
        })
      }
    })
  })
Cypress.Commands.add(
  'getInDocument',
  { prevSubject: 'document' },
  (document, selector) => Cypress.$(selector, document)
)

@chrisbreiding i have added the code snippet to replicate the issue , hope this helps

chrisbreiding commented 1 year ago

I'm unable to reproduce the issue with the code provided. The variable nameOnCard_input is undefined. If I substitute it with a selector for the only input on the page visited, the next command (cy.get("#cardNumber")) fails because there's no element with an id of cardNumber on the page.

nitish-Datman commented 1 year ago

@chrisbreiding apologises as i missed to add the locator for nameOnCard_input here is the locator for the same #nameOnCard and for (cy.get("#cardNumber")) its an iframe , you need to add the iframe support command line in the command.js page as mentioned above.

proving you few urls as it gets expired after visiting once,

chrisbreiding commented 1 year ago

Unfortunately none of those urls worked. It's possible, since they're links, a web crawler is picking them up and invalidating them by visiting the url. Could you post a few more, but just the IDs (so they don't turn into links)?

nitish-Datman commented 1 year ago

here are the url id's below,

nitish-Datman commented 1 year ago

seems like all the urls are expiring , i'm adding in the sheet https://docs.google.com/spreadsheets/d/1z08dCTFnGuqmPWmHmaWFY9kGxFwPxgjqZ03NaovQ644/edit?usp=sharing

once you request for access will provide the same

nitish-Datman commented 1 year ago

@chrisbreiding shared

chrisbreiding commented 1 year ago

I was able to get the example code running by visiting one of the urls in the sheet, but the test passes and I don't see any failures or a redirect happening. Although the click command succeeds at the end, it doesn't seem to have any effect, so it doesn't go as far as the test in your video.

I know you tried using modifyObstructiveCode and it didn't work, but this might require using experimentalModifyObstructiveThirdPartyCode. Can you trying setting that to true in your cypress.config.js and see if it helps?

nitish-Datman commented 1 year ago

it didn’t help, now the wired part is while experimentalModifyObstructiveThirdPartyCode: true, adding this to cypress.config.js iframe is not even loading , for iframe to load now i have to give now modifyObstructiveCode: false without experimentalModifyObstructiveThirdPartyCode , no idea what has changed

chrisbreiding commented 1 year ago

Interesting, I was able to reproduce the issue after setting modifyObstructiveCode: false. Now that I've reproduced it, I'm going to route this to a team to look into.

Here are debug logs I captured when reproducing the issue: debug.log

vivekbaskaran24021 commented 1 year ago

@chrisbreiding When is the issue is planned to fix

snehithapothina commented 1 year ago

I am facing the same issue, Can any one share the solution if possible? while running the test , cypress runner getting disappeared on redirect,

requireSol commented 1 year ago

Same here but my dashboard just get restarted.

kamilf92 commented 1 year ago

Same here my dashboard get restarted. I tried to use modifyObstructiveCode and experimentalModifyObstructiveThirdPartyCode but without success

jan-trynda-crustlab commented 10 months ago

I noticed, that in my case that issue mostly exists while using Chrome - both Edge and Electron work fine most of the time (it still happens from time to time) Looking forward for it to be fixed

crismarycastellanos commented 7 months ago

Hello, this is happening to me with the same payment platform! we are simulating a payment and once we confirm it redirects to a new page and the Cypress sidebar disappears! Just like in the video, what can we do ?? is there any workaround ??

snehithapothina commented 7 months ago

Hello,

Please keep proper wait time before redirecting to other page.It works

Best regards

On Fri, Dec 8, 2023, 10:45 AM crismarycastellanos @.***> wrote:

Hello, this is happening to me with the same payment platform! we are simulating a payment and once we confirm it redirects to a new page and the Cypress sidebar disappears! Just like in the video, what can we do ?? is there any workaround ??

— Reply to this email directly, view it on GitHub https://github.com/cypress-io/cypress/issues/23751#issuecomment-1847509014, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOSJZO3A7MQSED4VMOBCCJDYIM74FAVCNFSM6AAAAAAQIW5BE6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNBXGUYDSMBRGQ . You are receiving this because you commented.Message ID: @.***>

DobQA commented 5 months ago

Any news on this issue, seems we facing something similar.

gloAman commented 4 months ago

Any update on the issue?

Sarcolemna commented 3 months ago

I am getting this issue as well. The behavioral difference being that when the redirect fires the Cypress controls disappear and the non AUT browser resolves to the redirected page. This makes the headed runner basically unrecoverable and require a restart.

PK-Tests commented 2 months ago

I have the same issue. Because of security reasons i cant provide any reproducible code, but the problem for me happens when a payment gate redirects to authentication page. For a second the GUI shows "Your tests are loading..." and then exits out of the current test to the Specs list.

I tried both modifyObstructiveCode and experimentalModifyObstructiveThirdPartyCode unfortunately with no luck.

Marrkkov commented 2 weeks ago

I have the same issue. Because of security reasons i cant provide any reproducible code, but the problem for me happens when a payment gate redirects to authentication page. For a second the GUI shows "Your tests are loading..." and then exits out of the current test to the Specs list.

I tried both modifyObstructiveCode and experimentalModifyObstructiveThirdPartyCode unfortunately with no luck.

I am experiencing exactly the same issue with a payment gateway for an e-commerce platform. Unfortunately, I cannot provide the code for security reasons. Is there any news on this issue? I have tried many workarounds, but nothing has worked for me so far.