Rick Regan
05/12/2022, 4:57 PMperformTouchInput
and check the text with hasText
. The way I devised to move the slider doesn’t work for all ranges, so I’m looking for suggestions for the best (correct) way to move it. (See 🧵 for details.)composeTestRule.onNodeWithTag(
testTag = "Slider").performTouchInput {
down(topLeft)
moveTo(topLeft + percentOffset(x = xOffsetPercent))
up()
}.assertExists() // Force slider to show current position
(I had achieved that through a bit of trial and error.)
This is how I check the text:
composeTestRule.onNode(
hasTestTag(testTag = "SliderValue")
.and(hasText(expectedSliderValue))
).assertIsDisplayed()
I set xOffsetPercent = (position-sliderStartValue).toFloat()/(sliderEndValue-sliderStartValue)
and expectedSliderValue = position.toString()
.
With sliderStartValue = 1
and sliderEndValue
anything between 2 and 12, the checks of all positions work out. But when I change sliderEndValue
to 13 or greater, some of the checks fail (checking the printToLog
I see the text has the “n-1” position). I suppose the way I am moving the slider is not accurate enough -- is there a better way to do it? Thanks.
(This is actually an attempted distillation of the problem I actually see in my app: moving from Material 3 1.0.0-alpha10 to 1.0.0-alpha11 caused my existing slider instrumented tests to break, without having changed anything else. Does anyone know what change in Material 3 could be affecting this as well? The behavior I discussed above exists on alpha 10 and 11, so that hasn’t helped me figure out what specifically affected my app’s tests.)Kirill Grouchnikov
05/12/2022, 5:30 PMRick Regan
05/12/2022, 6:24 PMSlider
? Having the kludgy “touch-only” simulation was better than nothing, but now I have nothing with alpha 11.Kirill Grouchnikov
05/12/2022, 6:36 PMRick Regan
05/12/2022, 6:40 PMSlider
itself had issues, but I think I could assume it is stable now)Slider
is the last piece for me.