如何检查是否文本present在剪贴板中Robotium测试?剪贴板、文本、测试、present

2023-09-07 02:13:57 作者:活着真没意思

我使用Robotium测试我的Andr​​oid应用程序。在对话框中,我有一个按钮,将对话框到剪贴板中的文本复制。是否有可能访问剪贴板在我的测试,看看是否按钮已被pressed后的文字已被复制?如果是这样,怎么样?

I am testing my Android application using Robotium. In a dialog, I have a button that will copy the text in the dialog to the clipboard. Is it possible to access the clipboard in my test to see if the text has been copied after the button has been pressed? If so, how?

推荐答案

您可以在您的应用程序做同样的方式使用剪贴板管理服务,然后使用它的getText()方法来检索值。它应该是这个样子(未经测试,从内存中,我已经喝了几杯...):

You can use the clipboard manager service in the same way you do in your application and then use its getText() method to retrieve the value. It should look something like (untested, from memory and I have had a few drinks...):

public String getClipboardText(){
    if (android.os.Build.VERSION.SDK_INT; >= android.os.Build.VERSION_CODES.HONEYCOMB){
         android.content.ClipboardManager clipboard =  (android.content.ClipboardManager) getSystemService(CLIPBOARD_SERVICE); 
            return clipboard.getText(); 
    } else{
        android.text.ClipboardManager clipboard = (android.text.ClipboardManager)getSystemService(CLIPBOARD_SERVICE); 
        return clipboard.getText(); 
    }
}

您一定要去断言这预期的结果(无论你的对话框中设置)匹配

You will then need to assert that this matches the expected result (Whatever you set in the dialog)

 
精彩推荐
图片推荐