简体   繁体   中英

How can I use protractor to test ngx-clipboard?

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(); ``` 

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM