var sliderValue by remember { mutableStateOf(value = 0f) }
Slider(
value = sliderValue,
valueRange = 0f..100f,
onValueChange = {
sliderValue = it
},
)
我有这个滑块代码,现在我正在编写 ScreenShot 测试,我必须在滑块处于 50 % 时测试一项功能
我尝试在互联网上搜索,但没有找到任何相关资源来测试滑块或更改 Compose Test 类中的滑块值。
非常感谢任何有关代码或资源的帮助。
这是我用来实现解决方案的方法。
我利用
performGesture
函数来模拟滑块的移动。根据您的具体要求,您可以执行向左滑动或向右滑动的手势。
要执行向右滑动:
composeRule.onNodeWithTag("SliderTag").performGesture {
this.swipeRight()
}
向左滑动:
composeRule.onNodeWithTag("SliderTag").performGesture {
this.swipeLeft()
}