cypress icon indicating copy to clipboard operation
cypress copied to clipboard

Browser send too many xhr and fetch requests during execution

Open idanElitzur opened this issue 2 years ago • 3 comments

Current behavior

Browser send too many xhr, fetch and cache requests, part of them are canceled or return 400 bad requests. It's defiantly not the case when browsing the web app outside cypress. I've tried to change browser and cypress configuration and the login with the cy.session() as well but can't able to solve this issue.

Desired behavior

in the same use case Cypress sent above 6k requests and without Cypress is sent around 300 requests and non of them are canceled or return 400 bad request. it's a huge gap.

Test code to reproduce

Cypress config:

	e2e: {
		supportFile: 'cypress/support/e2e.ts',
		downloadsFolder: 'cypress/downloads',
		chromeWebSecurity: false,
		experimentalSourceRewriting: false,
		experimentalInteractiveRunEvents: true,
		experimentalFetchPolyfill: true,
		defaultCommandTimeout: 15000,
		requestTimeout: 30000,
		responseTimeout: 30000,
		numTestsKeptInMemory: 1,
		pageLoadTimeout: 30000,
		screenshotsFolder: 'mochawesome-report/assets',
		screenshotOnRunFailure: true,
		reporter: 'mochawesome',
		reporterOptions: {
			reportDir: cypress/report',
			code: false,
			charts: true,
			overwrite: false,
			html: false,
			json: true,
			embeddedScreenshots: true,
		},
		video: false,
		viewportHeight: 1080,
		viewportWidth: 1920,
		waitForAnimations: true,

Chrome browser options:

			on('before:browser:launch', (browser, launchOptions) => {
				if (browser.name === 'chrome' && browser.isHeadless) {
					launchOptions.args.push(
						'--disable-gpu',
						'--no-sandbox',
						'--disable-dev-shm-usage',
						'--window-size=1920,1080',
						'–-disable-sync',
						'-–disable-background-mode'
						);
					return launchOptions;
				}
			});

Login helper:

export const login = (userType: string) => {
  cy.session(userType, () => {
    cy.fixture('testUsers').then((user) => {
      cy.visit('/login');
      cy.get(loc.login.emailField)
        .should('be.visible')
        .type(user[`${userType}`].email);
      //wait for typed value will be complete
      cy.get(loc.login.emailField)
        .should('be.visible')
        .and('have.attr', 'value', user[`${userType}`].email);
      cy.get(loc.login.submitEmail).should('be.visible').click();
      //wait for some element in the landing page will be visible
      cy.get(loc.sideNavBar.buyersPipeline).should('be.visible');
  },
      {
        validate() {
          cy.visit('/app');
        }
      }
  );
};

Cypress Version

10.8.0

Node version

14.19.1

Operating System

macOS 12.3.1

Debug Logs

`
  cypress:server:stream_buffer extending buffer to accomodate new chunk { bufferLength: 2048, newBufferLength: 4096 } +548ms
  cypress:server:stream_buffer appending chunk to buffer { bytesWritten: 0, chunkLength: 3961 } +0ms
  cypress:network:agent addRequest called { isHttps: true, href: 'https://capture.trackjs.com/capture?token=111111111111&v=3.10.1' } +548ms
  cypress:network:agent got family { family: 4, href: 'https://capture.trackjs.com/capture?token=1111111111111&v=3.10.1' } +0ms
  cypress:server:stream_buffer stream buffer writeable final called +0ms
  cypress:network:cors Parsed URL { port: '443', tld: 'com', domain: 'mydomain' } +1ms
  cypress:network:cors Parsed URL { port: '443', tld: 'com', domain: 'mydomain' } +0ms
  cypress:network:cors Parsed URL { port: '443', tld: 'com', domain: 'trackjs' } +1ms
  cypress:server:remote-states getting remote state: undefined for: https://capture.trackjs.com/capture?token=1111111111&v=3.10.1 +2ms
  cypress:network:cors Parsed URL { port: '443', tld: 'com', domain: 'mydomain' } +0ms
  cypress:server:remote-states getting remote state: { auth: null, origin: 'https://myurl.com', strategy: 'http', fileServer: null, domainName: 'mydomain.com', props: { port: '443', tld: 'com', domain: 'mydomain' } } for: https://myurl.com +0ms
  cypress:server:stream_buffer extending buffer to accomodate new chunk { bufferLength: 2048, newBufferLength: 4096 } +1ms
  cypress:server:stream_buffer appending chunk to buffer { bytesWritten: 0, chunkLength: 4023 } +0ms
  cypress:network:agent addRequest called { isHttps: true, href: 'https://capture.trackjs.com/capture?token=11111111de&v=3.10.1' } +1ms
  cypress:network:agent got family { family: 4, href: 'https://capture.trackjs.com/capture?token=111111de&v=3.10.1' } +0ms
  cypress:server:stream_buffer stream buffer writeable final called +0ms
  cypress:network:cors Parsed URL { port: '443', tld: 'com', domain: 'doordawn' } +1ms
  cypress:server:remote-states getting remote state: { auth: null, origin: 'https://myurl.com', strategy: 'http', fileServer: null, domainName: 'mydomain.com', props: { port: '443', tld: 'com', domain: 'doordawn' } } for: https://myurl.com/nyc/backoffice-api +1ms
  cypress:network:cors Parsed URL { port: '443', tld: 'com', domain: 'mydomain' } +0ms
  cypress:server:remote-states getting remote state: { auth: null, origin: 'https://myurl.com', strategy: 'http', fileServer: null, domainName: 'mydomain.com', props: { port: '443', tld: 'com', domain: 'mydomain' } } for: https://myurl.com +0ms
  cypress:server:stream_buffer appending chunk to buffer { bytesWritten: 0, chunkLength: 119 } +1ms
  cypress:network:agent addRequest called { isHttps: true, href: 'https://myurl.com/nyc/backoffice-api' } +1ms
  cypress:network:agent got family { family: 4, href: 'https://myurl.com/nyc/backoffice-api' } +0ms
  cypress:server:stream_buffer stream buffer writeable final called +0ms
  cypress:server:request received status code & headers on request { requestId: 'request82', statusCode: 202, headers: {} } +339ms
  cypress:server:request successful response received { requestId: 'request82' } +0ms
  cypress:net-stubbing:server:intercept-response InterceptResponse { req: { url: '/capture?token=11111e&v=3.10.1' }, request: undefined } +339ms

Other

Screen Shot 2022-09-20 at 10 35 00

idanElitzur avatar Sep 20 '22 07:09 idanElitzur

@AtofStryker Can you please assist with this issue? IDK if I missing something over there with wrong config options or is it a bug Thanks

idanElitzur avatar Sep 21 '22 10:09 idanElitzur

Hey @idanElitzur . This seems concerning. Do you have a code reproduction we might be able to take a look at?

AtofStryker avatar Sep 21 '22 14:09 AtofStryker

Thanks for your quickly answer. Actually I've already posted here the login helper, the test cases are not effected about this behavior. I can publish here something but i'm pretty sure they will be not give you any value about this issue @AtofStryker

idanElitzur avatar Sep 21 '22 14:09 idanElitzur

@idanElitzur unfortunately I do not think this login function will run for us to enable us to reproduce this problem. Can you describe the scenario you are running into this problem? Are you rerunning your tests many times?

Ultimately though we will need you to 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.

nagash77 avatar Sep 21 '22 18:09 nagash77

/// <reference types="./../../../my-shared-cy-infra/node_modules/cypress" />
import * as loc from '../utils/locators';
import { IBuyer } from '../utils/interfaces/IBuyer';
import { generateRandomBuyerData } from '../utils/utils';
import { login } from '../utils/login';
import { searchListingButton, createShowingButton } from '../utils/utils';

let buyer: IBuyer = generateRandomBuyerData();

// @ts-ignore
describe('Check that user can add showing', { tags: 'smoke' }, () => {
  beforeEach(() => {
    login('backofficeAdvisor');
  });

  it('Create new showing', () => {
    cy.get(loc.sideNavBar.buyersPipeline).should('be.visible').click();
    cy.get(loc.pipelineBuyer.addBuyerButton)
      .should('be.visible')
      .click({ force: true });
    cy.get(loc.pipelineBuyer.newBuyerNameField).type(buyer.name);
    cy.get(loc.pipelineBuyer.newBuyerPhoneField).type(buyer.phone);
    cy.get(loc.pipelineBuyer.newBuyerEmailField).type(buyer.email);
    cy.get(loc.pipelineBuyer.newBuyerLeadSourceField).click();
    cy.get(loc.pipelineBuyer.newBuyerAutocompleteList)
      .eq(0)
      .should('be.visible')
      .click();
    cy.get(loc.pipelineBuyer.newBuyerAddNewBuyerButton).click();
    cy.get(loc.pipelineBuyer.viewButtonToast)
      .contains('View')
      .should('be.visible')
      .click();
    cy.get(loc.buyerDetails.navigationTabs)
      .contains('Explorer')
      .should('be.visible')
      .click();
    cy.get(loc.buyerDetails.listingIdExplorerCopyId).then(($listing1) => {
      const listing1 = $listing1.eq(0).text();
      cy.get(loc.buyerDetails.navigationTabs)
        .contains('Showings')
        .should('be.visible')
        .click();
      cy.get(loc.showingOfferTab.addShowingButton).should('be.visible').click();
      cy.get(loc.showingOfferTab.listingIdLink)
        .should('be.visible')
        .type(listing1);
    });
    cy.get('button').contains(searchListingButton).should('be.visible').click();
    cy.get('button').contains(createShowingButton).should('be.visible').click();
  });
});

@nagash77

idanElitzur avatar Sep 22 '22 07:09 idanElitzur

Hi @idanElitzur Unfortunately we will not be able to run this test as it contains lots of custom plugins and imports. Can you come up with a very simple test that reproduces the problem? I would suggest forking the Cypress tiny test repo and recreating the issue there and then sharing that repo with us.

nagash77 avatar Sep 22 '22 20:09 nagash77

Unfortunately we have to close this issue due to inactivity. Please comment if there is new information to provide concerning the original issue and we can reopen.

nagash77 avatar Sep 29 '22 14:09 nagash77