Swapnil Musale
Swapnil Musale

Reputation: 91

Android Compose Test Slider Functionality

var sliderValue by remember { mutableStateOf(value = 0f) }
Slider(
       value = sliderValue,
       valueRange = 0f..100f,
       onValueChange = {
           sliderValue = it
       },
)

I have this slider code, now I'm writing ScreenShot Testing, where I have to test one functionality when Slider is at 50 %

I tried to search on the internet but didn't find any relevant resource to test the slider or alter the slider value from Compose Test class.

Any help with code or resources much appreciated.

Upvotes: 3

Views: 935

Answers (1)

Ashaluwala Kazeem
Ashaluwala Kazeem

Reputation: 121

Here's the approach I used to implement my solution.

I utilized the performGesture function to simulate the movement of the slider. Depending on your specific requirements, you can perform a swipe left or swipe right gesture.

To perform a swipe right:

composeRule.onNodeWithTag("SliderTag").performGesture {
        this.swipeRight()
}

To perform a swipe left:

composeRule.onNodeWithTag("SliderTag").performGesture {
        this.swipeLeft()
}

Upvotes: 2

Related Questions