首页 > 解决方案 > 设备显示屏上的 Espresso UI 测试表情符号

问题描述

我正在使用 Espresso 为聊天应用程序编写 UI 测试。我很想知道是否存在一种方法,我们可以测试设备屏幕上是否存在特定的表情符号。我自己尝试过,但没有找到任何方法。提前致谢。

标签: androidandroid-espressoemojiui-testing

解决方案


您可以使用此函数来确定某个字符串是否存在于屏幕上的任何位置:

public boolean textExists(String text){
    try{
        onView(first(allOf(withText(containsString(text)), isDisplayed()))).perform(closeSoftKeyboard());
        return true;
    }
    catch (NoMatchingViewException e){
        return false;
    }
}

像这样使用它:

boolean emoji = textExists("");

推荐阅读