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

Add emulate page focus to fix issues with typing or clicking when the Runner is out of focus #21673

Open
sync-by-unito bot opened this issue May 30, 2022 · 16 comments
Labels

Comments

@sync-by-unito
Copy link

sync-by-unito bot commented May 30, 2022

Originally described in this github issue: https://github.com/cypress-io/cypress/issues/5023

Currently, there is non-determinism when you're clicking or typing in the runner and you disable window focus to tab to your editor, your test will fail even though it works.

Enabling Emulate a Focused Page in the chrome devtools fixes this. Luckily, this is an automation flag we can set on browser launch.

Screen Shot 2021-10-13 at 3 28 34 PM

┆Issue is synchronized with this Jira Bug by Unito
┆Attachments: Screen Shot 2021-10-13 at 3.28.34 PM.png
┆author: Jess Sachs
┆epic: Edge Cases
┆friendlyId: UNIFY-456
┆priority: High
┆sprint: Sprint #7
┆taskType: Bug

@sync-by-unito sync-by-unito bot added CT Issue related to component testing epic:edge-cases type: bug labels May 30, 2022
@sync-by-unito

This comment was marked as outdated.

@sync-by-unito

This comment was marked as outdated.

@ThijSlim
Copy link

@jennifer-shehane You're saying that you can automate this flag. I can't find a way to set the Emulate a Focused Page flag

@bkuzma
Copy link

bkuzma commented Nov 11, 2022

I could also use some help figuring out how to launch Chrome with this option enabled 😕 🙏

@taybenlor
Copy link

taybenlor commented Mar 26, 2023

This doesn't appear to be a chrome flag, but rather a devtools protocol command. The method is Emulation.setFocusEmulationEnabled and it takes { enabled: boolean }. You can see a code search here.

More documentation here: https://chromedevtools.github.io/devtools-protocol/tot/Emulation/#method-setFocusEmulationEnabled

@taybenlor

This comment was marked as outdated.

@taybenlor
Copy link

taybenlor commented Mar 27, 2023

As a workaround, a simple solution that appears to work is to add a command that uses Cypress' internal automation API:

Cypress.Commands.add("emulateFocus", (enabled) => {
    return Cypress.automation("remote:debugger:protocol", {
        command: "Emulation.setFocusEmulationEnabled",
        params: { enabled: enabled ?? true },
    });
});

This resolves the issues we were running into.

@cypress-app-bot
Copy link
Collaborator

This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided.

@cypress-app-bot cypress-app-bot added the stale no activity on this issue for a long period label Sep 24, 2023
@wrycu
Copy link

wrycu commented Sep 24, 2023

still a problem.

@taybenlor
Copy link

@brian-mann - I'd be willing to work on a PR to resolve this based off my fix above ^ however I have no context on how Cypress works internally or what direction you would like this fix to take.

We have seen that fix resolve our issues with focus consistently in CI and when running headless.

@cypress-app-bot cypress-app-bot removed the stale no activity on this issue for a long period label Sep 25, 2023
@nagash77

This comment was marked as outdated.

@cypress-app-bot
Copy link
Collaborator

This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided.

@cypress-app-bot cypress-app-bot added the stale no activity on this issue for a long period label Apr 2, 2024
@cypress-app-bot
Copy link
Collaborator

This issue has been closed due to inactivity.

@cypress-app-bot cypress-app-bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 17, 2024
@IvanovAtanass
Copy link

Hi, I have a similar problem with headless mode, my element is not fully rendered when Cyppers tries to interact with it. In the browser, all tests pass, and this problem occurs every time in a different test, and only in headless mode. I used your abovementioned solution, but it didn't solve my problem. Could I ask for your assistance?

@jennifer-shehane jennifer-shehane removed the stale no activity on this issue for a long period label Jul 10, 2024
@jennifer-shehane
Copy link
Member

@IvanovAtanass Likely your issue is not related to this emulate focus issue if the workaround doesn't solve your issue. I'd suggest writing an assertion that ensures the element is fully rendered before interacting with it, like 'should('be.visible')' or similar.

@jennifer-shehane jennifer-shehane added topic: cy.click 🖱 topic: cy.type ⌨️ and removed CT Issue related to component testing labels Jul 10, 2024
@cypress-app-bot
Copy link
Collaborator

This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided.

@cypress-app-bot cypress-app-bot added the stale no activity on this issue for a long period label Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

9 participants