cypress: onLoad not being called on second cy.visit to current url

  • Operating System: CircleCI 2.0 running the docker container node-9.5.0-browsers and node-8.9.4-browsers
  • Cypress Version: 1.4.2
  • Browser Version: electron 53
{ name: 'electron',
  displayName: 'Electron',
  version: '53.0.2785.143',
  path: '',
  majorVersion: '53',
  info: 'Electron is the default browser that comes with Cypress. This is the browser that runs in headless mode. Selecting this browser is useful when debugging. The version number indicates the underlying Chromium version that Electron uses.' } { width: 1280,
  height: 720,
  show: false,
  automationMiddleware: {},
  projectPath: '/home/circleci/project',
  browsers: 
   [ { name: 'chrome',
       displayName: 'Chrome',
       version: '64.0.3282.140',
       path: 'google-chrome',
       majorVersion: '64' },
     { name: 'electron',
       displayName: 'Electron',
       version: '53.0.2785.143',
       path: '',
       majorVersion: '53',
       info: 'Electron is the default browser that comes with Cypress. This is the browser that runs in headless mode. Selecting this browser is useful when debugging. The version number indicates the underlying Chromium version that Electron uses.' } ],
  proxyUrl: 'http://localhost:46201',
  userAgent: null,
  proxyServer: 'http://localhost:46201',
  socketIoRoute: '/__socket.io',
  chromeWebSecurity: true,
  url: 'http://localhost:3000/__/#/tests/__all',
  browser: 
   { name: 'electron',
     displayName: 'Electron',
     version: '53.0.2785.143',
     path: '',
     majorVersion: '53',
     info: 'Electron is the default browser that comes with Cypress. This is the browser that runs in headless mode. Selecting this browser is useful when debugging. The version number indicates the underlying Chromium version that Electron uses.' },
  x: null,
  y: null,
  devTools: false,
  minWidth: 100,
  minHeight: 100,
  contextMenu: true,
  trackState: 
   { width: 'browserWidth',
     height: 'browserHeight',
     x: 'browserX',
     y: 'browserY',
     devTools: 'isBrowserDevToolsOpen' },
  frame: true,
  recordFrameRate: null,
  onPaint: null,
  webPreferences: 
   { chromeWebSecurity: true,
     nodeIntegration: false,
     backgroundThrottling: false } }

Is this a Feature or Bug?

Bug

Current behavior:

describe('Mock Logging in', () => {
  it('stub cognito', () => {
    cy.server();
    cy.visit('/login');
    cy.visit('/login', { onLoad: (contentWindow) => {
      const state = contentWindow.reduxStore.getState();
      // do stuff with the reduxStore to mock the logged in state here
    }})

Desired behavior:

  • Running in electron on MacOS this runs fine
  • Running in Chrome on MacOS this runs fine
  • Running in Electron on Circle CI the onLoad is never called - resulting in
  1) Mock Logging in:
     CypressError: Timed out after waiting '60000ms' for your remote page to load.

Your page did not fire its 'load' event within '60000ms'.

You can try increasing the 'pageLoadTimeout' value in 'cypress.json' to wait longer.

Browsers will not fire the 'load' event until all stylesheets and scripts are done downloading.

When this 'load' event occurs, Cypress will continue running commands.

Increasing the timeout results in it never being called

How to reproduce:

100% reproducible on CircleCI

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 15 (8 by maintainers)

Commits related to this issue

Most upvoted comments

I have encountered this behavior when visiting the same url that I am currently on. So, if you run the code below, Cypress waits for the onload event on the first visit, but on the second one, the onload event is not going to be fired since you are on the exact same page. Cypress eventually times out.

cy.visit('/login')
cy.visit('/login')

Is there a reason why you need to visit the same url? Could using cy.reload() resolve your usecase?

I think we could handle this situation better in Cypress - as I was very confused when I encountered it as well. I was not blatantly visiting the same url either, my use case was:

cy.visit('runs/123') // visiting here by default routes to runs/123/failures

// wanted to test my direct routing worked
cy.visit('runs/123/failures') // would timeout since I was already on runs/123/failures

@brian-mann thoughts?

Im experiencing the same issue. Running visit first in a beforeEach and then in a command gives me a 60 sec timeout. Im running this on linux mint and it fails locally, so it probably has to do with the Linux distribution?

Snippet causing the failure:

beforeEach(() => {
    cy.visit("/#/registration");
  });

Cypress.Commands.add("register",() => {
    cy.visit("/#/registration")
    const pw = "!abc123abc123";
    cy.get("input#username").type("johndoe");
    cy.get("input#password").type(pw);
    cy.get("input#password-confirmation").type(pw);
    cy.contains("button", "Submit").click();
});