cypress: Cypress cy.screenshot() timeout during `cypress run`

Current behavior:

All of our tests pass locally, but when running the Codeship CI we get errors for a few tests.

The error during Codeship CI builds: CypressError: cy.screenshot() timed out waiting '30000ms' to complete.

Desired behavior:

All tests pass in Codeship CI

Steps to reproduce:

For our app the reproduction is running the ci:codeship command runs which calls cy:record "cy:record": "cypress run --record --key *key* --config video=false", "ci:codeship": "start-server-and-test start http://localhost:5000 cy:record"

I’m not exactly sure how to reproduce this other than creating a Codeship Basic app and attempting to run tests there. I have seen a few other issues point to a problem with how Cypress and Codeship interact.

Versions

Cypress version: 3.4.1

Sidenote: We are using the cypress-autorecord package, but it doesn’t seem like this is involved.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 47
  • Comments: 202 (23 by maintainers)

Commits related to this issue

Most upvoted comments

CypressError: cy.screenshot() timed out waiting 30000ms to complete.

version :8.7.0

occurs frequently in all the suites why this is open for years ?

can anyone please take this as priority and fix it it will be helpful for many

@jennifer-shehane

I just upgraded Cypress to 4.0.1, and we now started to see tests failing on Github Actions with screenshot() timeout warning 😢

any progress on this? this issue open for years…

@jennifer-shehane , hi is no one checking this issue please? i am stuck to using version 12:12.0 and would really like to update the version. Please do let me know if any other info is required. Thank you

Be careful… we upgraded and ran in to this: https://github.com/cypress-io/cypress/issues/23903

Really frustrated with Cypress ATM … spending a lot of cycles dealing with framework issues rather than actually writing/reasoning about tests.

I’m working with cypress 13.3.0 and I have the issue. After the test failed, we have the screenshot error. The test was executed on github pipeline: image It is randomly, not appears in all failed test

Hey, guys! For all who still struggling from this issue the solution will be only one – return back to the Cypress version 7.7! I returned back to the 7.7 version and it works on the CI.

Yup this is ridiculous that they announce Cypress 10, but still not fixed this issue, it’s really critical for many to have screenshot on failed tests (not only logs). Especyaly when you pay for the cypress dashboard.

@marktnoonan yes, can confirm that experimentalMemoryManagement set to true fixed this error. (at least following the results of a single test cycle run)

cypress version 13.2.0

The fix did not last too long. Now receive this error again 13.2.0

Also seeing this issue.

Just upgraded to Cypress 13.2.0, prior to the upgrade we were not having any issues with screenshots. Since the upgrade we can no longer capture screenshots when running headless locally on Chrome. Local headless screenshots appear to work fine when running on Electron, screenshots also seem to capture just fine when the tests are running in an azure devops pipeline (on Chrome).

Video capture appears to also be working fine in all cases.

@jennifer-shehane this is getting more and more problematic. Any change you can get this on the fix list?

I just timed running with video: true, it was generally 3-4 x slower than without (!) and this is on beefy c5.large AWS instances.

This issue appeared for us when attempting to upgrade to Cypress 8.x - we are stuck on 7.x as a consequence.

Hi,

Please remove me from this email trail.

Thanks

BP

Billy Papageorgiou Developer CRS Engineering, Customer Relationship Systems CUSTOMER PROCESSING SYSTEMS @.*** Level 5 South, 55 Currie Street, Adelaide

From: toannguyen83 @.> Sent: Friday, 15 October 2021 12:49 AM To: cypress-io/cypress @.> Cc: Papageorgiou, Billy @.>; Comment @.> Subject: Re: [cypress-io/cypress] Cypress cy.screenshot() timeout during cypress run (#5016)

I’m having the same problem that during cypress run, after the test finished, it hangs for a while and then it throws an error

CypressError: cy.screenshot() timed out waiting 30000ms to complete.

I have a sample code that can reproduce the issue in Cypress 8.6.0 cypress-run-replication.ziphttps://github.com/cypress-io/cypress/files/7346695/cypress-run-replication.zip

Run Sample Code Instructions (on Windows Machine)

  • Extract the sample code
  • Run npm install to install cypress
  • There is a sample test that will purposely fail so that it can take failed test screenshot
  • Now run npx cypress run
  • Notice that the process hangs at the end and after waited for a while, it throws an error about cy.screenshot()

I noticed that when I set the cypress.config video to true, then it works fine.

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/cypress-io/cypress/issues/5016#issuecomment-943404688, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ARUARGYJIUFHLC3FHKMGTDDUG3RG5ANCNFSM4IOJQN6Q. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub. ********************************************************************** IMPORTANT: This e-mail is for the use of the intended recipient only and may contain information that is confidential, commercially valuable and/or subject to legal or parliamentary privilege. If you are not the intended recipient you are notified that any review, re-transmission, disclosure, dissemination or other use of, or taking of any action in reliance upon, this information is prohibited and may result in severe penalties. If you have received this e-mail in error please notify the sender immediately and delete all electronic and hard copies of this transmission together with any attachments. Please consider the environment before printing this e-mail **********************************************************************

Is there a way to catch these failures to screenshot? It would be nice if those didn’t result in a CypressError and didn’t overwrite the stack trace of the actual reason for failure

@droca I was able to recreate this situation. Only within the Chrome browser. This can be recreated with cypress open and cypress run.

test.js

it('click on new tab', () => {
  cy.visit('index.html')
  cy.get('a').click().should('have.attr', 'foo')
})

index.html

<html>
  <script>
  </script>
<body>
  <a target="_blank" href="new.html">Click me</a>
</body>
</html>

new.html

<html>
</html>

Screenshot 2024-02-26 at 11 15 38 AM

To try and help, I created a minimal repro of the issue here with some README details on the environment I’m using, and a snippet of the last line of the DEBUG logging I sometimes see before it “hangs”/times out.

I also noticed some interesting cause/effect observations in the README (some of which have been noted here by others). For example, I notice that invoking cy.screenshot() directly doesn’t fail for me, only when it’s done indirectly by a failed test assertion. When I do invoke it directly, it seems to make subsequent failed assertions & screenshots NOT timeout.

Mentioning @jennifer-shehane as I kindly saw her asking for these details above. Hoping this will help.

Our workaround for now is to enable video: true which works (as stated by others) but is obviously not ideal if you don’t want the video.

This didn’t worked for me since v7. Switched to playwright, it produces much more stable tests, not just screenshots.

Maybe this will be helpful. I found what was causing this issue on my side. One test was clicking link that opens new tab, and basically leave it hanging, and then next test was always failing withcy.screenshot() timed out waiting 30000ms … as soon as I removed that link click - no more issues.

@jennifer-shehane I could be wrong, but I think the problem here is when Cypress loses focus on main browser tab or something of that nature.

s it possible that this is being caused by the number of tests being run? I have 130+ tests and facing this issue from 12.14.0+ only in gitlab… I very rarely run all the tests in GUI.

No, I’m facing this issue running only 13 tests.

its already 2023 and still a problem

Hi all, I first want to say I can understand the frustration with an issue like this. Especially when it seems simple, like there is a single solution. But from what I can tell, it’s not just one error, but it’s a condition Cypress reaches that could point back to multiple causes. That’s one of the challenges with just providing a fix.

Anyway, a small update: it appears that Chrome’s new headless mode that was turned on in v12.15.0 is connected to at least some the more recent reports of problems above. That’s suggested in this Discord thread from today, as well as the increased activity in these comments after 12.15.0 came out in June.

You can still opt-in to passing the old headless flag, as described in our docs here, which should get you back to the default behavior prior to v12.15.0. If you started seeing this issue recently, and this is the reason, that should unblock you while we look into it further.

Also I am really curious if setting experimentalMemoryManagement to true in your config file might also make difference here. I may have missed it above, if anybody who experiences it regularly has already configured that, or if not, please let me know if changes the amount of times this happens.

I do not understand how such a critical issue is not being addressed…

Does anyone have an update on this issue? It’s about to be 3 years and no fix

Any news on this?

A workaround that worked for me (using v9.3.1):

I found that this was occurring for me if during each describe block, my first action was to do a cy.visit(<url>), then running tests that would fail with NO screenshot.

After playing around with what was semi working, I tried assigning the url I wanted to visit at the beginning of each test to the baseUrl: <url> configuration in either cypress.json or plugins/index.js module.exports config. Then instead of using cy.visit(<url>), I change my in-test visit() to `cy.visit(‘/’). Doing this caused my screenshots to work while having videos disabled/set to false.

Before:

cypress.json
{
  ...,
  "video": false
}

dummy.spec.js:
describe('should fail', () => {
    it('visit url', () => {
         cy.visit(<url>)
    }

    it('test that should've failed and triggered a screenshot', () => {
         cy.get('[data-testid=header]').contains(<incorrect title>) 
    }
}

After:

cypress.json
{
  ...,
  "video": false,
  "baseUrl": <url>
}

dummy.spec.js:
describe('should fail', () => {
    it('visit url', () => {
         cy.visit('/')
    }

    it('test that failed and SUCCESSFULLY trigger a screenshot', () => {
         cy.get('[data-testid=header]').contains(<incorrect title>) 
    }
}

We also get this sometimes during our CI (Docker/k8s). We’re running the latest version of Cypress (6.8.0) on Debian 9 Docker containers.

Hi again Cypress team!

It seems, it is getting weirder and more unreliable than 6 months ago since I used the cy.screenshot. Now I often get the 30000ms timeout.

Please help 😢. It is one of the features what made me using Cypress.

Hm… It seems that setting numTestsKeptInMemory to 0 helps me and it is working with chrome 80 in Travis.

@alexbjorlig Hmm, I haven’t seen the ECONNREFUSED error for proxy requests before. Yeah, I would open a new issue. May be more due to the Node upgrade.

The fact that screenshots work in Chrome 80 is very promising though. Thanks for the update.

We are running multiple feature files in Azure pipelines. We see this issue always at the first feature file. All of the others are okay. Hope this information hepls.

We’re taking another look into this. Spiking into it. We’ve looked into a few avenues in the past. It’s still incredibly difficult to track down without a reproducible example that triggers it reliably.

If anyone can share a reproducible example that we can run - and provide the info about where you’re running it, how many CPU/resources you have, it’d be helpful.

It seems to be some kind of intermittent issue with the timing of things and perhaps available resources which makes this difficult to pin down.

Not a solution, but a potential workaround to add to the commands.js file in order not to fail the hook (and just log the error) in case the screenshot fails to complete, is this command overwrite legit, @marktnoonan @jennifer-shehane ?

Cypress.Commands.overwrite('screenshot', (originalFn, name, options) => {
  try {
    originalFn(name, options)
  } catch (error) {
    Cypress.log({
      name: 'screenshot',
      message: [`Could not take a screenshot: ${error.message}`]
    })
  }
})

When running the test in CI using ver.13.3.0 and debian-linux a single test also fails, and upon checking in cypress-cloud test replay, it fails in the command cy.screenshot() although I don’t have that command written in my test. When running locally using npx cypress run... this test is passing

image

cy.screenshot() timed out waiting 120000ms to complete.


View stack trace
at https://xxxxxxxxxxxxxxxxxxxxxx/__cypress/runner/cypress_runner.js:134350:73 
at tryCatcher (https://xxxxxxxxxxxxxxxxxxxxxx/__cypress/runner/cypress_runner.js:1807:23) 
at https://xxxxxxxxxxxxxxxxxxxxxx/__cypress/runner/cypress_runner.js:4186:41 
at tryCatcher (https://xxxxxxxxxxxxxxxxxxxxxx/__cypress/runner/cypress_runner.js:1807:23) 
at Promise._settlePromiseFromHandler (https://xxxxxxxxxxxxxxxxxxxxxx/__cypress/runner/cypress_runner.js:1519:31) 
at Promise._settlePromise (https://xxxxxxxxxxxxxxxxxxxxxx/__cypress/runner/cypress_runner.js:1576:18) 
at Promise._settlePromise0 (https://xxxxxxxxxxxxxxxxxxxxxx/__cypress/runner/cypress_runner.js:1621:10) 
at Promise._settlePromises (https://xxxxxxxxxxxxxxxxxxxxxx/__cypress/runner/cypress_runner.js:1697:18) 
at _drainQueueStep (https://xxxxxxxxxxxxxxxxxxxxxx/__cypress/runner/cypress_runner.js:2407:12)
at _drainQueue (https://xxxxxxxxxxxxxxxxxxxxxx/__cypress/runner/cypress_runner.js:2400:9) 
at Async._drainQueues (https://xxxxxxxxxxxxxxxxxxxxxx/__cypress/runner/cypress_runner.js:2416:5) 
at Async.drainQueues (https://xxxxxxxxxxxxxxxxxxxxxx/__cypress/runner/cypress_runner.js:2286:14)

I’m working with cypress 13.3.0 and I have the issue. After the test failed, we have the screenshot error. The test was executed on github pipeline: image It is randomly, not appears in all failed test

cypress 12.17.3, same issue here.

I guess that the github pipeline might have some issues

Hi @marktnoonan. Unfortunately, In my case, experimentalMemoryManagement: true didn’t help. I still have the cy.screenshot() timed out waiting 30000ms to complete. I’m with cypress v12.17.3 I’m running the tests on github, with self-hosted runners and using node 18.16.0 Running the tests with parameter --browser chrome

Any updates ?

I want to leave a comment here, because we found the cause of this issue and its something we could work around:

Our tests had a link that when clicked opened a new tab. The tab was on another domain and the browser could not perform cy.screenshot().

We changed the test so that it asserted this another way and it passed through fine.

We were using Lambdatest when this problem manifested itself.

  • Check your domains
  • Check for new tabs
  • They are fast, faster than you could believe. Don’t turn your back, don’t look away, and don’t blink!

I am getting same error with Cypress version 10.11.0: CypressError: cy.screenshot() timed out waiting 30000ms to complete. with Webkit run.

Stacktrace: CypressError: cy.screenshot() timed out waiting 30000ms to complete.

Because this error occurred during a after each hook we are skipping the remaining tests in the current suite: User should be able to chec... tryCatcher@http://localhost:3000/__cypress/runner/cypress_runner.js:11318:28 tryCatcher@http://localhost:3000/__cypress/runner/cypress_runner.js:11318:28 <unknown>@http://localhost:3000/__cypress/runner/cypress_runner.js:9253:35 <unknown>@http://localhost:3000/__cypress/runner/cypress_runner.js:9310:43 <unknown>@http://localhost:3000/__cypress/runner/cypress_runner.js:9355:24 <unknown>@http://localhost:3000/__cypress/runner/cypress_runner.js:9431:33 _drainQueueStep@http://localhost:3000/__cypress/runner/cypress_runner.js:6025:27 _drainQueue@http://localhost:3000/__cypress/runner/cypress_runner.js:6018:24 <unknown>@http://localhost:3000/__cypress/runner/cypress_runner.js:6034:16 <unknown>@http://localhost:3000/__cypress/runner/cypress_runner.js:5904:26

It might be that your CI machine does not have enough resources to run your tests

Besides the screenshots themselves failing, I find it worrying that the timeout does’t throw an error in CI environment thus tests running indefinetly. At least when using GH Actions.

It throws an error for us in GH actions - I bet there’s something else causing your issue

Besides the screenshots themselves failing, I find it worrying that the timeout does’t throw an error in CI environment thus tests running indefinetly. At least when using GH Actions.

I think just set "screenshotOnRunFailure": false in CI would be quiet reasonable work around, of course it’s not a best solution if you want to log where error occurs.

Any progress in the matter?

This needs to be addressed @jennifer-shehane

A workaround that worked for me (using v9.3.1):

I found that this was occurring for me if during each describe block, my first action was to do a cy.visit(<url>), then running tests that would fail with NO screenshot.

After playing around with what was semi working, I tried assigning the url I wanted to visit at the beginning of each test to the baseUrl: configuration in either cypress.json or plugins/index.js module.exports config. Then instead of using cy.visit(), I change my in-test visit() to `cy.visit(‘/’). Doing this caused my screenshots to work while having videos disabled/set to false.

This didn’t work for me unfortunately (Cypress v9.5.3, ubuntu 20.04, circle ci) - everything works locally just fine but not in CI

The challenge is… when a test fails is often when you most need to see the video, if you are running in a headless build environment and need to ex post facto work out why a certain test failed.

I agree 100%. This should be fixed by Cypress.

But this worked for my use case, I wanted to disable for local runs so my CPU doesn’t get too hot 🔥

@toannguyen83

Same here, after enable video on cypress config the screenshot stoped to throw timeout error. What make no sense if you won’t record video after error.

I’m having the same problem that during cypress run, after the test finished, it hangs for a while and then it throws an error

 CypressError: `cy.screenshot()` timed out waiting `30000ms` to complete.

I have a sample code that can reproduce the issue in Cypress 8.6.0 cypress-run-replication.zip

Run Sample Code Instructions (on Windows Machine)

  • Extract the sample code
  • Run npm install to install cypress
  • There is a sample test that will purposely fail so that it can take failed test screenshot
  • Now run npx cypress run
  • Notice that the process hangs at the end and after waited for a while, it throws an error about cy.screenshot()

Workaround

  • In cypress.config, when I set video to true, then it works fine.
  • Also in the cypress.config, if I set the baseUrl to the app url that I need to test, then it also work fine

I have this problem too, however I noticed that the error only happens when I minimize the browser screen. If I run the tests with it maximized, I don’t suffer from this problem. And if I run the tests in headless mode, I can also run them without any problem.

The version of cypress I am using is 6.6.0

This might sound weird, but I experienced this ONLY when I had Norton antivirus firewall enabled.

When we ran into this problem , we solved it by using a workaround by passing "screenshotOnRunFailure": false in your cypress.json file. In the scenario, the cypress doesn’t try to capture the screenshot on failure and you get the actual error.

Seems that problem is solved on Travis CI when I have start the cypress with --headless --browser chrome params. The chrome version is 73 in Travis CI.

We’re seeing this on Chrome 80.0.3987.122 (Official Build) (64-bit)

Hello there,

A little update: I tried Cypress’ docker images with Chrome 80 (Cypress 4.0.0 and newer) as recommended in https://github.com/cypress-io/cypress/issues/6023#issuecomment-584472171 and after a week or so, I don’t see any more screenshot related failures until now.

In 3.8.2, there was Chrome 79 installed iirc. So it looks like it was the mentioned Chrome bug for me as well. Thank you so much for your advice! 👍

I also have this issue with 3.8.1 and Chrome 79 on CircleCI’s ubuntu-1604:201903-01 machine. It’s not there with Chrome 78 or the embedded version of Electron. It’s probably related to #6023.