question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cy.clock() preventing the subsequent visit/reload to load completely when running in emulator

See original GitHub issue

Current behavior:

In emulator, Page is not loading completely if we are setting the clock before visiting the page

In emulator: Set the clock --> visit the page again --> page is not loading completely.

Desired behavior:

Page should be completely loaded. (please note : There is no issue with the flow when executed on chrome desktop view)

Test code to reproduce

code snippet which is causing issue

//eg :  url = https://www.amazon.com/  (or) https://www.unibet.co.uk/

cy.clock(new Date().getTime())
cy.visit(url)

config used:

{
    "userAgent": "Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1",
    "viewportWidth":414,
    "viewportHeight":896
}

Versions

“cypress”: “^4.5.0” running on chrome 81

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

14reactions
jennifer-shehanecommented, May 28, 2020

So basically, there is some call using setTimeout that your application requires when it’s on this userAgent in order to load your page. Since calling cy.clock() overwrites setTimeout, the time is not clicking forward in order to trigger what it needed in this call.

You can see that the loading of the site breaks only if you overwrite setTimeout.

// Not working ☹️ 
it('test', () => {
  cy.clock(new Date().getTime(), ['setTimeout'])
  cy.visit('https://www.unibet.co.uk')
})

If you want to only overwrite the Date object, I recommend explicitly specifying to only overwrite that function like below:

// Working!!
it('test', () => {
  cy.clock(new Date().getTime(), ['Date'])
  cy.visit('https://www.unibet.co.uk')
})

If you still want to overwrite the setTimeout timing, you’ll need to tick time forward so that your call to setTimeout is called as time would normally progress.

// Working!!
it('test', () => {
  cy.clock(new Date().getTime())
  cy.visit('https://www.unibet.co.uk')
  cy.tick(5000)
})
1reaction
guruannapantulacommented, May 26, 2020

In the code snippet, I have given another example about loading the site https://www.unibet.co.uk which is under our control, the result is same in this case as well. The page is not loaded completely

Read more comments on GitHub >

github_iconTop Results From Across the Web

clock - Cypress Documentation
cy.clock() overrides native global functions related to time allowing them to be controlled synchronously via cy.tick() or the yielded clock object. This.
Read more >
Cypress clock function makes html body invisible
The cy.clock() command overwrites and freezes the javascript functions relating to timers - setTimeout, setInterval as well as the Date ...
Read more >
Cypress Cy.Tick() Not Forwarding Time The Second Time It Is ...
The fact that Cypress is running inside the same context as the. ... clock preventing the subsequent visit/reload to load completely when running...
Read more >
Make The Test Faster Using cy.clock And cy.tick Commands
If the application uses a setTimeout or other time -related functions, you can speed it up by controlling the application's clock using the ......
Read more >
Stop the time with cy.clock | przemuh.dev
Now it is time to write some cypress tests. We are testing! In our test scenario we would like to check: if the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found