对于Android应用,如何检查特定图像视图中正在使用的资源ID?

问题描述 投票:0回答:1

我正在为公司的应用程序编写自动化测试。这些测试结合使用了Espresso和Robotium。这些测试中的几个应该用来检查某些ReactImageView元素是否正在显示特定图像。

我首先尝试使用hasBackground()如下:

onView(...).check(matches(hasBackground(R.drawable...)));

但是,这将返回NoMatchingViewException

然后,我按此处所述尝试了Daniele Bottillo的匹配器:https://medium.com/@dbottillo/android-ui-test-espresso-matcher-for-imageview-1a28c832626f

onView(allOf(..., new DrawableMatcher(R.drawable....), isDisplayed())).check(matches(isDisplayed()));

但是这也不起作用:

java.lang.ClassCastException: com.facebook.drawee.generic.RootDrawable cannot be cast to android.graphics.drawable.BitmapDrawable

最后,我尝试了Frankie Sardo的解决方案:Android Espresso match BitmapDrawables with different tint

onView(allOf(..., withImageDrawable(R.drawable...), isDisplayed())).check(matches(isDisplayed()));

但是,这再次抛出NoMatchingViewException。我的想法不多了。甚至可以检查图像视图上附加了哪些资源?

android android-espresso android-drawable android-testing
1个回答
0
投票

最简单的方法是使用Barista库及其assertHasDrawable(R.id.<imageview_id>, R.drawable.<drawable_id>)断言函数。

© www.soinside.com 2019 - 2024. All rights reserved.