0

I'm writing some tests and I need to go to the middle of a slider. I would like to get minimumValue and maximumValue of the slider, like on a picture below: enter image description here

These values may change so every time I need to get them in my code. Later, I just want to get average of these two values and move the slider to the middle using a method

performAction:grey_moveSliderToValue(valueToMove)

How can I get minumumValue and maximumValue in my code? Is this the best approach or is there any better to move playhead to the middle of the slider?

Tomas
  • 129
  • 2
  • 14

1 Answers1

2

You can use EarlGrey's GREYActionBlock to create a new action that slides to half

// Create a new action that slides to half.
GREYActionBlock *slideToHalfAction = [GREYActionBlock actionWithName:@"slideToHalf"
                                                         constraints:grey_kindOfClass([UISlider class])
                                                        performBlock:^BOOL(id element, NSError *__strong *errorOrNil) {
  UISlider *slider = element;
  float minValue = slider.minimumValue;
  float maxValue = slider.maximumValue;
  float halfValue = (minValue + maxValue) / 2;
  return [grey_moveSliderToValue(halfValue) perform:element error:errorOrNil];
}];

// Use the new action on the slider.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"slider4")] performAction:slideToHalfAction];
Gautam
  • 286
  • 1
  • 3
  • Just make sure the halfValue doesn't fall into fractional pixels otherwise Earlgrey will fail to set the slider to halfValue because it is not user attainable. – khandpur Nov 30 '16 at 20:15