我正在使用Espresso为聊天应用程序编写UI测试。我很想知道是否存在一种方法,我们可以测试设备屏幕上是否存在特定的表情符号。我自己尝试过,但没有找到任何方法。提前谢谢。
您可以使用此函数来确定屏幕上的任何位置是否存在某个字符串:
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("😀");