I am testing a page that has an embed modal with a textbox with an embed code and a "Copy" button that should copy the contents of the textbox onto the clipboard so a user can paste it elsewhere. Is there a way to test clicking the "Copy" button and verifying that the clipboard contents match the contents of the textbox? Thanks!
Asked
Active
Viewed 2,293 times
7
Alex Skorkin
- 4,034
- 3
- 21
- 44
Samantha Blasbalg
- 729
- 3
- 11
-
Did you try simulating a "CTRL+V" key press somewhere to assert that the content pasted is ok ? – Ricovitch Sep 12 '18 at 15:43
-
No, I don't have anywhere on the page to paste it other than that single textbox, which seems like an odd test. Plus I don't think CTRL+V works in testcafe right now? https://github.com/DevExpress/testcafe/issues/2466 – Samantha Blasbalg Sep 12 '18 at 18:31
1 Answers
3
TestCafe cannot automate a browser's built-in behavior, including the Copy & Paste functionality. It is expected that this functionality works correctly as it is tested by browser developers.
You can try to check that your script/button executes the copy command in the following way:
const overwriteCopyCommand = ClientFunction(() => {
document.execCommand = command => window.lastExecutedCommand = command;
});
const getLastExecutedCommand = ClientFunction(() => window.lastExecutedCommand);
await overwriteCopyCommand();
await t
.click('.copy-url-button')
.expect(getLastExecutedCommand()).eql('copy');
Unfortunately, according to JavaScript restrictions, I don't see a way how to check the copied text.
See additional workarounds in these threads:
Support 'ctrl+c' and 'ctrl+v' key combinations for copying/pasting selected text
Alex Skorkin
- 4,034
- 3
- 21
- 44
Marion
- 1,034
- 5
- 10