TestCafe does not have built-in clipboard tools at the moment.
However, you can use the client function to emulate the clipboard:
import { Selector, ClientFunction } from 'testcafe';
fixture `Example`
.page `http://devexpress.github.io/testcafe/example/`;
test('Clipboard test', async t => {
const text = 'Value for copy-paste';
const emulateClipboard = ClientFunction(() => {
let buffer = '';
document.addEventListener('keypress', event => {
if (event.ctrlKey) {
if (event.key === 'c')
buffer = document.getSelection().toString();
if (event.key === 'v')
document.activeElement.value = buffer;
}
});
});
await emulateClipboard();
await t
.typeText('#developer-name', text)
.selectText('#developer-name')
.pressKey('ctrl+c')
.click('#tried-test-cafe')
.click('#comments')
.pressKey('ctrl+v')
.expect(Selector('#comments').value).eql(text)
});
This example works correctly in Chrome. It may not work in other browsers due to the difference in accessing the content of <textarea> elements.
You may be able to glean more information from this discussion: https://github.com/DevExpress/testcafe/issues/2668
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…