-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
cy.window() to access clipboard immediately results in 'document is not focused' error #28488
Comments
Can you please specify the path of file in which this code is written? |
e2e folder for sure and there is another point I forgot to mention when i write this code in (it) it will not run any cy command inside the the window function |
@aosama94 We changed some of the behavior around tab focusing in recent versions. I suspect this may have introduced the change in behavior: #28334
I've been unable to reproduce the issue, so want to understand the circumstances for us to address it. |
Hmm, I found this thread so now I wonder if this has always been a problem and isn't new: #18198 There is a workaround in that issue. |
question here
And why wee need a wait ? and what we can use instead of wait here |
any improvement in this issue? |
Hi - @jennifer-shehane I'm facing similar issues as reported here. In this case we're writing text to the clipboard, which is then read in the actual test down the line. The issue however seems to be around I've created the simplest possible use case that is fairly generic below. Note that the application of describe('Create test that reliably fails with Document Not focused', () => {
beforeEach(() => {
// Allow clipboard access
cy.wrap(
Cypress.automation('remote:debugger:protocol', {
command: 'Browser.grantPermissions',
params: {
permissions: ['clipboardReadWrite', 'clipboardSanitizedWrite'],
origin: window.location.origin,
},
})
);
// Write any gibberish to clipbaord
cy.window().then((window) => {
window.navigator.clipboard.writeText('gibberish');
window.focus(); // Important: without this the test will fail also in both headed (with focus) and headless mode
});
cy.visit('/');
});
it('Should not fail', () => {
expect(true).to.eq(true);
});
}); Let me know if I can provide more details. |
Could you all try to update to 13.6.6 and let us know if you're still experiencing this issue? We fixed an issue in 13.6.5 that was introduced in 13.6.0 and we want to understand if this has also resolved this issue. Thank you! |
Updated to 13.6.6 but unfortunately the same issue persists for me (with the same example test as in my prev post). The test only passes if the cypress browser window is focused (or in headless), but unfocused window does not |
That's unfortunate. 😞 |
Just to note that, updated to 13.7.1, I'm still experiencing the same issue! |
I found a solution using It worked for me. |
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. |
This issue has been closed due to inactivity. |
Current behavior
I used cy.window() to acces the clipboard, and it doesn't let me do any cypress command till i use cy.wait()
and there is no option instead the wait:
If i used cy.log() without wait it will throw an error (document is not focused) so there is no way to use any cypress command inside it
if I used cy.get('element').type('test); it will not see this command or will not throw any errors just like it doesn't exist
conclusion:
cy.log(somthine). will throw error (document is not focused)
cy.get.type. will be considered as not existing command
I just need to get the clipboard text to use it ino an input filed to continue my testing
I hope that you got my point
Desired behavior
Should be any way to not show the error (document is not focused) instead of the cy.wait()!!
Test code to reproduce
Cypress Version
"cypress": "^13.6.0
Node version
v20.9.0
Operating System
Version 14.0 (23A344)
Debug Logs
No response
Other
No response
The text was updated successfully, but these errors were encountered: