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

fix: screenshot() times out when the main Cypress tab is not focused #29038

Merged
merged 18 commits into from Mar 8, 2024

Conversation

cacieprins
Copy link
Contributor

@cacieprins cacieprins commented Feb 29, 2024

Additional details

When the Renderer for a given Chromium tab is paused, CDP commands that query that renderer hang until the renderer is unpaused. Unfortunately, this causes issues with cy.screenshot() in both run and open mode, if the main Cypress tab becomes unfocused. This happens when an anchor is clicked within a test that has a target of _blank, among other scenarios. To keep tests running, we timeout on capturing a screenshot after 30 seconds.

When in run mode, this causes issues when a test assertion fails after a new tab has been opened. By default, Cypress takes a screenshot when an assertion fails. If this screenshot times out, the original assertion failure is replaced by the screenshot timeout error.

To fix this, we now attempt to activate the main Cypress tab in Chromium browsers before taking a screenshot. First, we request the extension to activate the main tab. This can fail if the Cypress extension has been disabled. As a last resort, the Page.bringToFront command is issued to CDP. This is less desirable, as it causes the browser to steal focus.

Steps to test

See: ./system-tests/projects/config-screenshot-on-failure-enabled. To test with the extension disabled, modify ./system-tests/test/issue_5016_spec.js and pass both noExit: true and headed: true. Once the test completes, disable the extension in chrome://extensions/ and reload the main Cypress tab.

How has the user experience changed?

PR Tasks

Copy link

cypress bot commented Mar 1, 2024

Passing run #54404 ↗︎

0 669 1 0 Flakiness 0

Details:

Merge branch 'develop' into cacie/fix/screenshot-timeout
Project: cypress Commit: 5f72d11200
Status: Passed Duration: 09:29 💡
Started: Mar 6, 2024 5:50 PM Ended: Mar 6, 2024 6:00 PM

Review all test suite changes for PR #29038 ↗︎

sanitizeScreenshotDimensions: true,
snapshot: true,
expectedExitCode: 1,
browser: '!webkit',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only run into the issue in chrome. firefox and electron both seem to work as expected prior to the fix.

Suggested change
browser: '!webkit',
browser: 'chrome',

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could also be good to just exercise the behavior since it is a change to CDP automation itself and make sure the behavior doesn't regress in those browsers for whatever reason

@mschile mschile removed their request for review March 8, 2024 06:06
@cacieprins cacieprins merged commit e785318 into develop Mar 8, 2024
81 of 82 checks passed
@cacieprins cacieprins deleted the cacie/fix/screenshot-timeout branch March 8, 2024 16:09
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Mar 13, 2024

Released in 13.7.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v13.7.0, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Mar 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cypress cy.screenshot() timeout during cypress run
3 participants