Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Playback file is not created when the command cy.reload() is used in the test #123

Open
alaney opened this issue Dec 8, 2023 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@alaney
Copy link

alaney commented Dec 8, 2023

Describe the bug
I have a spec where I reload the page using cy.reload(). The test is expecting the page to be in the same state after a page reload. When I run the spec, no playback file is created. If I simply remove the reload command, the playback file is successfully created. The command log shows that there is "one pending request" when I use the reload command. I only have one matcher and it works just fine without the reload.

To Reproduce
I have tried to reproduce this using another site like Google but I was unsuccessful. I'm wondering if you know of any reason that this may happen? Here's an idea of what my test looks like:

describe('Playback', () => {
  beforeEach(() => {
    cy.playback('GET', '/some/json/request*');
  });

  it('should record after page reload', () => {
    cy.visit('/my/page');
    cy.get('.button').click();
    cy.get('h1').should('have.text', 'Endpoint Information');
    cy.reload();
    cy.get('h1').should('have.text', 'Endpoint Information');
  });
});

Expected behavior
The matcher should have recorded the requests and a playback file should be created.

Environment

  • OS: Windows
  • Cypress Version: 13.6.0
  • Browser: Chrome
  • Browser Version: 120
@alaney alaney added the bug Something isn't working label Dec 8, 2023
@DigTheDoug
Copy link
Contributor

Hi @alaney, thanks for the report. I can reproduce what you're seeing as well, something with the cy.reload() in that test is causing an issue. My initial thought was that it had to do with the default hybrid mode getting mixed up with having both a record and playback possibility in the same test, but setting it explicitly to record mode shows the same issue.

We'll take a look, thanks!

@tvsbrent
Copy link
Contributor

Sorry it took so long to look at this issue. This is looking to be an interesting challenge, let me explain what I believe is going on:

  • The page is loaded by the browser. (Cypress in this case.)
  • The app code makes requests to a certain API endpoint.
  • The Cypress playback plugin intercepts that request and waits for it to complete.
  • A reload is triggered in Cypress, but that request has not completed, so it is cancelled by the browser.
    • This is where the problem enters, as the plugin is not notified of cancelled requests.
  • The page begins to load again, and the plugin is notified of the new request and waits for that new request to complete.
  • In this case, that request does complete and it is marked as such.
  • Unfortunately, the plugin is never notified about the cancelled requests, so waits for them to complete, which will never happen.

I'm going to look deeper in Cypress to see if it is possible to be notified of cancelled requests. Until then, you may want to add code to the test to ensure it is "stable" (meaning the inflight requests the plugin is waiting on are complete) prior to triggering the reload.

@alaney
Copy link
Author

alaney commented Jan 17, 2024

Thanks for the feedback. I can work with that 🙂

@malibagci
Copy link

Hi @DigTheDoug,

Any news about this issue?

@DigTheDoug
Copy link
Contributor

Hey sorry @malibagci no updates on this issue. It's a bit more of a complex one and we haven't had time to look at it. PRs always welcome if you or anyone else has any ideas or thoughts though. @tvsbrent 's comment above covers the gist of it, specifically the last bullet point:

Unfortunately, the plugin is never notified about the cancelled requests, so waits for them to complete, which will never happen

If you know of a way to hook into knowing when a reload is triggered in Cypress or when there are cancelled requests that might be where the library could interrupt to save the snapshot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants