我有一个Image
编写如下:
Image(
bitmap = ImageBitmap.imageResource(id = R.drawable.testimage),
contentDescription = null, // Only decorative image
contentScale = ContentScale.FillWidth,
modifier = Modifier
.requiredHeightIn(max = 250.dp)
.fillMaxWidth()
.semantics { testTag = "MyTestTag" },
)
在仪器测试期间,我想确保设置了正确的绘图。我在类似的课程中没有找到任何可以实现这一目标的东西SemanticsProperties
编写自定义匹配器。有人可以帮忙吗?
您可以自己添加语义。
val DrawableId = SemanticsPropertyKey<Int>("DrawableResId")
var SemanticsPropertyReceiver.drawableId by DrawableId
val resId = R.drawable.my_drawable
Image(
painter = painterResource(id = resId),
contentDescription = null,
Modifier.semantics { drawableId = resId }
)
并测试它
fun hasDrawable(@DrawableRes id: Int): SemanticsMatcher =
SemanticsMatcher.expectValue(DrawableId, id)
composeRule.onNode(hasDrawable(R.drawable.my_drawable))
.assertIsDisplayed()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)