document.execCommand("copy") does not work in cypress
See original GitHub issueHi there,
I’m curious as to why a document.execCommand("copy")
fails when being run during a cypress test (as a side effect to a cy.get().click()
). Curiously it works fine once I’m manually clicking the same element after the test has run.
The failing test in question can be reproduced by running the following code:
describe("menuBar", function() {
beforeEach(() => {
cy.visit("http://teselagen.github.io/openVectorEditor/#/Editor");
});
it("select range, copy, cut works", function() {
cy.clock()
cy.get('.tg-menu-bar').contains("Edit").click()
cy.get('.tg-menu-bar-popover').contains("Select").click()
cy.get(`[label="From:"]`).clear().type("10")
cy.get(`[label="To:"]`).clear().type("20")
cy.get(`.dialog-buttons`).contains("OK").click()
cy.get(".veStatusBar").contains(`10 to 20`)
cy.get(".veStatusBar").contains(`5299`)
cy.get('.tg-menu-bar').contains("Edit").click().tick(200)
cy.get('.tg-menu-bar-popover').contains("Copy").click()
cy.contains("Selection Copied")
cy.get('.tg-menu-bar').contains("Edit").click()
cy.get('.tg-menu-bar-popover').contains("Cut").click()
cy.contains("Selection Cut")
cy.get(".veStatusBar").contains(`5288`)
});
});
If you run the above example, the test will fail to find “Selection Copied”. This is because
const worked = document.execCommand(type);
evaluates to false
so the “Selection Copied” popover is not shown.
You can add a breakpoint manually to the commands/index.js
file and see it not working.
Strangely, after the test has run if you manually click “File > Edit > Copy” then the document.execCommand("copy")
works just fine. Not sure what is going on here to stop it from working when cypress is running its tests.
Thanks!
Issue Analytics
- State:
- Created 5 years ago
- Reactions:18
- Comments:20 (12 by maintainers)
@Bkucera ship it! I’d love to use your suggested
Is there any update on this?