How to get the 'clipboard' content in cypress. I have a button in my web application, on click of button system will perform 'copy to clipboard' and a message will get displayed. Below is an example of the url content that is copy to clipboard ( this url content is different from web site url)
I have double check that there is no href
attribute in that button tag. So I have use a plugin called clipboardy and I have added plugins/index.js
file
const clipboardy = require('clipboardy');
module.exports = ( on ) => {
on('task', {
getClipboard () {
return clipboardy.readSync();
}
});
};
In my test I have used cy.task() to get the clipboard content, but this is not printing the actual url content
cy.get('td').find('div').find('span').find('button').find('i').eq(0).click().then(()=>{
cy.task('getClipboard').then((data)=>{
console.log("Helloooo:"+data);
})
})
<td class="sc-hgRTRy duUdhJ">
<div>
<span class="sc-bYwvMP jTmLTC">
<span class="sc-jzJRlG iVpVVy">
<span role="button" aria-expanded="true" aria-haspopup="true" aria-owns="5aa03785-1370-455e-a838-4154f7481a7b">
<button class="sc-feJyhm cJOKrG">
<i class="icon fas fa-link sc-htpNat cQABgO" aria-hidden="true" data-component-type="icon">
</i>
</button>
</span>
</span>
</span>
</div>
</td>
getClipboard () { return clipboardy.read(); }
as well – soccerway May 7 '20 at 7:11.click()
is not triggering the event. That may be the 'native events' problem, but it's also possible the click is not on the right element. Can you show part of the html that has thetd
? – Richard Matsen May 7 '20 at 23:29.then()
is a jquery object, so you probably can't do"Hello:" + data
, instead maybe"Hello:" + data[0]
. – Richard Matsen May 8 '20 at 5:33