简体   繁体   English

如何使用量角器测试ngx-clipboard?

[英]How can I use protractor to test ngx-clipboard?

How can I use protractor to test ngx-clipboard ? 如何使用量角器测试ngx-clipboard? I have tried using the following code with Chrome's navigator API but it doesn't work. 我已尝试将以下代码与Chrome的导航器API结合使用,但无法正常工作。 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. 如果我误解了您要寻找的内容,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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