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

Clipboard works with cypress open and not cypress run (permissions) #8957

Closed
haug1 opened this issue Oct 23, 2020 · 3 comments
Closed

Clipboard works with cypress open and not cypress run (permissions) #8957

haug1 opened this issue Oct 23, 2020 · 3 comments

Comments

@haug1
Copy link

haug1 commented Oct 23, 2020

Current behavior

I have a test that is testing clipboard functionality. When I run cypress open --browser chromium, my tests are passing, but when I am running cypress run --browser chromium they will not pass. Error is that the app (not the test) can not read the clipboard with window.navigator.clipboard.readText() without manually granting permission inside chromium.

image

Why am I getting this behavior only with cypress run? How can I bypass it?

I've been debugging, passing DEBUG=cypress:launcher and found that the browser launch arguments are identical. I have noticed one huge difference within the chromium browser: when I go to Settings>Security>Safe Browsing, it is set to "Standard protection" when running cypress run, but it's set to No protection when using cypress open.

(Manually setting Safe Browsing to 'No protection' and re-running tests does not fix the issue)

Desired behavior

Same browser behavior with cypress open and cypress run when the provided configuration is identical.

Versions

5.2.0

@haug1
Copy link
Author

haug1 commented Oct 26, 2020

Solved like this

image

Now I am facing the issue that my test will not pass in headless mode or when browser is not focused.

@IoanStoianov
Copy link

IoanStoianov commented Jun 20, 2023

Adding the following code at the beginning of my test body resolved it for me in the headless:

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

@ememisya
Copy link

ememisya commented May 30, 2024

Does this help anyone? #21673 (comment)

For me the same issue appears to be intermittently failing my headless tests however I have not been able to successfully test the success of something like:

const setFocusEmulationEnabled = (enabled: boolean): any => {
  return cy.wrap(
    Cypress.automation("remote:debugger:protocol", {
        command: "Emulation.setFocusEmulationEnabled",
        params: {
          enabled
        },
      }),
  );
};

As at the moment I have been testing it, setting it false also seems to yield document.hasFocus() true, and subsequent tests after removing the call all together are also working (until they won't). This involves diving deep into Chrome internals to debug it, something I am not very familiar with at this time.

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

No branches or pull requests

3 participants