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

feat: add support for clipboard access #42

Open
sdescarries opened this issue Feb 16, 2022 · 6 comments
Open

feat: add support for clipboard access #42

sdescarries opened this issue Feb 16, 2022 · 6 comments
Labels
enhancement New feature or request

Comments

@sdescarries
Copy link

I want to test clipboard interaction and the test will fail because it requires user authorization.

I think it would be a nice feature to add for this plugin.

  it('copies word on click', () => {
    cy.get('.CopyButton').click();

    cy.window()
      .then(({ navigator }) => navigator.clipboard.readText())
      .then((text) => expect(text).to.match(/hello world/));

  });

Fails with NotAllowedError: Read permission denied.

@sdescarries
Copy link
Author

Okay I did a bit of digging, it's not as simple as adding clipboard to the list - the permission is not listed in Chromium's profile.managed_default_content_settings.

Do you think there's another way to allow this?

@miso-belica
Copy link

I just added "clipboard": "allow" into cypress.json and it works. But I found also some other solution that may help somebody.

  "env": {
    "browserPermissions": {
      "clipboard": "allow"
    }
  }

@TeemuKoivisto
Copy link

Somehow I ended up here but the solution by @miso-belica didn't work or the one he linked. Instead, adding this before the clipboard invoking part worked https://stackoverflow.com/questions/60174546/how-grant-cypress-test-application-some-permissions

@AustinMontoya
Copy link

I just tried @miso-belica's { "clipboard": "allow" } solution and it worked like a charm -- I wonder if it's related to specific browser versions?

This is using

Running in Electron 106, Ubuntu linux using cypress-io/[email protected] on ubuntu-latest runner (hoping this helps as a point of comparison for others who might have run into similar issues)

@kamranayub
Copy link
Owner

Very interesting, I'll need to see what I can do to add this natively. Thanks for all the info!

@kamranayub kamranayub added the enhancement New feature or request label Feb 23, 2023
@jacsongmendes-tester
Copy link

Hello guys, This repository has a solution for the issue.
https://github.com/cypress-io/cypress-example-recipes/tree/master/examples/testing-dom__clipboard
it worked for me in cypress 12.6.0, macOS and navigator chrome.

  cy.wrap(Cypress.automation('remote:debugger:protocol', {
        command: 'Browser.grantPermissions',
        params: {
          permissions: ['clipboardReadWrite', 'clipboardSanitizedWrite'],
          origin: window.location.origin,
        },
  }))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants