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

Prompt on cypress #88

Closed
cesarlima-hotmart opened this issue Dec 4, 2019 · 12 comments
Closed

Prompt on cypress #88

cesarlima-hotmart opened this issue Dec 4, 2019 · 12 comments

Comments

@cesarlima-hotmart
Copy link

Prompt alert when testing the application with cypress. Is there a way to solve it?

@sudodoki
Copy link
Owner

sudodoki commented Dec 4, 2019

I guess just disabling fallback might be an okay~ish thing for such case, if you don't need to test successful copying. Then either using fork right now from https://github.com/sudodoki/copy-to-clipboard/pull/82/files or waiting for it to be merged, which also needs some readme/typing updates

@cesarlima-hotmart
Copy link
Author

In fact, i'm testing if the text is successfully copied to clipboard.

@sudodoki
Copy link
Owner

sudodoki commented Dec 4, 2019

@cesarlima-hotmart then you might be in trouble 😬 see https://github.com/sudodoki/copy-to-clipboard/tree/master/tests and https://github.com/sudodoki/copy-to-clipboard/blob/master/e2e_helpers/assertions/assertBuffer.js for possible references. I used extra elements to do 'reseting' of the buffer by calling ctrl/cmd+c with some text selected and pasted stuff into textarea/etc to verify I was able to copy something from buffer and that stuff I needed was copied.
I wasn't able to reliably write tests for at least most commong platforms (Chrome / Firefox) as it seemed line endings were inconsistent across different browsers, so I ended up with regexes that were more relaxed with whitespacing than exact matches on strings

@cesarlima-hotmart
Copy link
Author

cesarlima-hotmart commented Dec 4, 2019

Yeah, cypress runs on chromium, but i think the problem is the app runs in a webview inside it. The weird thing is, in this cypress webview, it works if I click manually on the button that calls the copy, but it prompts if i click on it by the cypress click command.

@sudodoki
Copy link
Owner

sudodoki commented Dec 4, 2019

there're some issues with security which might be in play, as execCommand cannot be executed without user's interaction, not sure whether that's the case here

@cesarlima-hotmart
Copy link
Author

The solution i've found is check the parameters of the alert and assume that it is going to be the copied value in the real scenario.

cy.window().then(win => {
  cy.stub(win, 'prompt').returns(win.prompt).as('copyToClipboardPrompt');
});

let link: string;

cy.get('.transmission-info-container .info .column:last-child .link').find('a').then($a => {
  link = $a.text().trim();
});

cy.get('.transmission-info-container .info .column:last-child .link > div').click();
cy.get('@copyToClipboardPrompt').should('be.called');
cy.get('@copyToClipboardPrompt').should(prompt => {
  expect(prompt.args[0][1]).to.equal(link);
});

@KateKorneeva
Copy link

Thank you!

@She-Wolf
Copy link

She-Wolf commented Oct 7, 2020

@cesarlima-hotmart
I lost 2 days before find your solution. Good life and good health to you !

@inoutw
Copy link

inoutw commented Apr 12, 2021

@cesarlima-hotmart thanks, it works fine in cypress test runner, but when I run it as a node module in Electron( by command npx cypress run --spec "cypress/*/my-spec.js") it showed error as AssertionError: Timed out retrying after 15000ms: expected copyToClipboardPrompt to have been called at least once, but it was never called

@pR13S7
Copy link

pR13S7 commented Jan 5, 2022

@cesarlima-hotmart

God bless you man!

@tit
Copy link

tit commented Nov 4, 2022

@cesarlima-hotmart
This world bless you. Thanks!

@TophatRay
Copy link

TophatRay commented Apr 3, 2023

@inoutw Did you ever find a solution to to your assertion error? I'm having similar issues

Update: Turns out what happens is that Electron does not support alerts, so the "prompt" action didn't register.
To get around this issue I just had a modal/message pop up that shows me what I copied and did a simple

.contains(`Copied ${copiedData}`).should("exist");

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

8 participants