cypress: cy.window() to access clipboard immediately results in 'document is not focused' error

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:

    cy.window().then((win) => {
      win.navigator.clipboard.readText().then((data) => {
        // console.log(data);
        cy.wait(1000);
        cy.writeFile('cypress/genericTestData/importedService.json', data);
        cy.log(data);
      });
    });

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

    cy.window().then((win) => {
      win.navigator.clipboard.readText().then((data) => {
        // console.log(data);
        cy.wait(1000);
        cy.writeFile('cypress/genericTestData/importedService.json', data);
        cy.log(data);
      });
    });

Cypress Version

“cypress”: "^13.6.0

Node version

v20.9.0

Operating System

Version 14.0 (23A344)

Debug Logs

No response

Other

No response

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 16 (4 by maintainers)

Most upvoted comments

Just to note that, updated to 13.7.1, I’m still experiencing the same issue!

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

any improvement in this issue?