0

How can I use protractor to test ngx-clipboard ? I have tried using the following code with Chrome's navigator API but it doesn't work. Navigator is undefined...any ideas?

         try {
             const text = await navigator.clipboard.readText();
             console.log('Pasted content: ', text);
         } catch (err) {
             console.error('Failed to read clipboard contents: ', err);
         }
     }

     getClipboardContents(); ``` 
snikt
  • 581
  • 4
  • 11
  • 27

1 Answers1

0

That package does appear to have some specific version requirements based on the angular version so make sure to you are matching.

If what you are trying to achieve is simply testing text is copied and pasted to the clipboard correctly there is another package I have used called 'clipboardy' which was very straigt forward. Usage is as below

const clipboardy = require('clipboardy');

//create variable with value from clipboard
let urlFromClipboard= await clipboardy.read();

await browser.get(urlFromClipboard);

Similar question here.

If I've misunderstood what you are looking for let me know.

DublinDev
  • 2,318
  • 2
  • 8
  • 31
  • How does it know when the clipboard is populated with text, or do you just call if after the click() ? – snikt Feb 12 '19 at 17:01
  • I'm assuming you have an element on your page that when clicked copies something to the clipboard but correct me if I am mistaken. In this case it wouldn't know that information when it is supposed to have something. It would be up to you to do that comparison yourself like so when the info is expected to be copied `let clipboardContents= await clipboardy.read(); expect(clipboardContents).toBe(expectedClipboardContents)` – DublinDev Feb 12 '19 at 17:29