Best EarlGrey code snippet using performAction.grey_moveSliderToValue
FTRSlideTest.m
Source:FTRSlideTest.m
...22 [self openTestViewNamed:@"Slider Views"];23}24- (void)testSlider1SlidesCloseToZero {25 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"slider1")]26 performAction:grey_moveSliderToValue(0.125f)]27 assertWithMatcher:grey_sliderValueMatcher(28 grey_closeTo(0.125f, kGREYAcceptableFloatDifference))];29 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"slider1")]30 performAction:grey_moveSliderToValue(0.0f)]31 assertWithMatcher:grey_sliderValueMatcher(grey_closeTo(0.0f, 0))];32}33- (void)testSlider2SlidesToValue {34 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"slider2")]35 performAction:grey_moveSliderToValue(15.74f)]36 assertWithMatcher:grey_sliderValueMatcher(37 grey_closeTo(15.74f, kGREYAcceptableFloatDifference))];38 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"slider2")]39 performAction:grey_moveSliderToValue(21.03f)]40 assertWithMatcher:grey_sliderValueMatcher(41 grey_closeTo(21.03f, kGREYAcceptableFloatDifference))];42}43- (void)testSlider3SlidesToClosestValue {44 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"slider3")]45 performAction:grey_moveSliderToValue(0.0f)]46 assertWithMatcher:grey_sliderValueMatcher(grey_closeTo(0, 0))];47 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"slider3")]48 performAction:grey_moveSliderToValue(900.0f)]49 assertWithMatcher:grey_sliderValueMatcher(50 grey_closeTo(900.0f, kGREYAcceptableFloatDifference))];51}52- (void)testSlider4IsExactlyValue {53 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"slider4")]54 performAction:grey_moveSliderToValue(500000.0f)]55 assertWithMatcher:grey_sliderValueMatcher(56 grey_closeTo(500000.0f, kGREYAcceptableFloatDifference))];57}58- (void)testSlider5SnapsToValueWithSnapOnTouchUp {59 // For sliders that "stick" (have tick marks) to certain values, the tester must calculate the60 // tick value that will result by setting the slider to an arbitrary value.61 // See FTRSliderViewController.m for details on how my slider's tick values were calculated.62 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"slider5")]63 performAction:grey_moveSliderToValue(60.0f)]64 assertWithMatcher:grey_sliderValueMatcher(65 grey_closeTo(60.3f, kGREYAcceptableFloatDifference))];66}67- (void)testSlider6SnapsToValueWithContinuousSnapping {68 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"slider6")]69 performAction:grey_moveSliderToValue(37.5f)]70 assertWithMatcher:grey_sliderValueMatcher(71 grey_closeTo(50.0f, kGREYAcceptableFloatDifference))];72 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"slider6")]73 performAction:grey_moveSliderToValue(62.5f)]74 assertWithMatcher:grey_sliderValueMatcher(75 grey_closeTo(50.0f, kGREYAcceptableFloatDifference))];76}77- (void)testSmallSliderSnapsToAllValues {78 for (int i = 0; i <= 10; i++) {79 id<GREYMatcher> closeToMatcher = grey_closeTo((double)i, kGREYAcceptableFloatDifference);80 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"sliderSnap")]81 performAction:grey_moveSliderToValue((float)i)]82 assertWithMatcher:grey_sliderValueMatcher(closeToMatcher)];83 }84}85@end...
SlideTest.m
Source:SlideTest.m
...22 [self openTestViewNamed:@"Slider Views"];23}24- (void)testSlider1SlidesCloseToZero {25 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"slider1")]26 performAction:grey_moveSliderToValue(0.125f)]27 assertWithMatcher:grey_sliderValueMatcher(28 grey_closeTo(0.125f, kGREYAcceptableFloatDifference))];29 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"slider1")]30 performAction:grey_moveSliderToValue(0.0f)]31 assertWithMatcher:grey_sliderValueMatcher(grey_closeTo(0.0f, 0))];32}33- (void)testSlider2SlidesToValue {34 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"slider2")]35 performAction:grey_moveSliderToValue(15.74f)]36 assertWithMatcher:grey_sliderValueMatcher(37 grey_closeTo(15.74f, kGREYAcceptableFloatDifference))];38 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"slider2")]39 performAction:grey_moveSliderToValue(21.03f)]40 assertWithMatcher:grey_sliderValueMatcher(41 grey_closeTo(21.03f, kGREYAcceptableFloatDifference))];42}43- (void)testSlider3SlidesToClosestValue {44 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"slider3")]45 performAction:grey_moveSliderToValue(0.0f)]46 assertWithMatcher:grey_sliderValueMatcher(grey_closeTo(0, 0))];47 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"slider3")]48 performAction:grey_moveSliderToValue(900.0f)]49 assertWithMatcher:grey_sliderValueMatcher(50 grey_closeTo(900.0f, kGREYAcceptableFloatDifference))];51}52- (void)testSlider4IsExactlyValue {53 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"slider4")]54 performAction:grey_moveSliderToValue(500000.0f)]55 assertWithMatcher:grey_sliderValueMatcher(56 grey_closeTo(500000.0f, kGREYAcceptableFloatDifference))];57}58- (void)testSlider5SnapsToValueWithSnapOnTouchUp {59 // For sliders that "stick" (have tick marks) to certain values, the tester must calculate the60 // tick value that will result by setting the slider to an arbitrary value.61 // See SliderViewController.m for details on how my slider's tick values were calculated.62 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"slider5")]63 performAction:grey_moveSliderToValue(60.0f)]64 assertWithMatcher:grey_sliderValueMatcher(65 grey_closeTo(60.3f, kGREYAcceptableFloatDifference))];66}67- (void)testSlider6SnapsToValueWithContinuousSnapping {68 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"slider6")]69 performAction:grey_moveSliderToValue(37.5f)]70 assertWithMatcher:grey_sliderValueMatcher(71 grey_closeTo(50.0f, kGREYAcceptableFloatDifference))];72 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"slider6")]73 performAction:grey_moveSliderToValue(62.5f)]74 assertWithMatcher:grey_sliderValueMatcher(75 grey_closeTo(50.0f, kGREYAcceptableFloatDifference))];76}77- (void)testSmallSliderSnapsToAllValues {78 for (int i = 0; i <= 10; i++) {79 id<GREYMatcher> closeToMatcher = grey_closeTo((double)i, kGREYAcceptableFloatDifference);80 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"sliderSnap")]81 performAction:grey_moveSliderToValue((float)i)]82 assertWithMatcher:grey_sliderValueMatcher(closeToMatcher)];83 }84}85@end...
grey_moveSliderToValue
Using AI Code Generation
1[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"sliderID")] performAction:grey_moveSliderToValue(0.5)];2+ (id<GREYAction>)grey_moveSliderToValue:(CGFloat)value;3+ (id<GREYAction>)grey_moveSliderToValue:(CGFloat)value {4 constraints:grey_interactable()5 performActionBlock:^BOOL(id element, __strong NSError **errorOrNil) {6 UISlider *slider = (UISlider *)element;7 [slider setValue:value animated:YES];8 return YES;9 }];10}11+ (id<GREYMatcher>)grey_accessibilityID:(NSString *)accessibilityID;12+ (id<GREYMatcher>)grey_accessibilityID:(NSString *)accessibilityID {13 return [GREYElementMatcherBlock matcherWithMatchesBlock:^BOOL(id element) {14 return [accessibilityID isEqualToString:[element accessibilityIdentifier]];15 }16 descriptionBlock:^NSString *{17 return [NSString stringWithFormat:@"accessibilityID: %@", accessibilityID];18 }];19}20- (id<GREYAction>)grey_moveSliderToValue:(CGFloat)value;21- (id<GREYAction>)grey_moveSliderToValue:(CGFloat)value {22 return [GREYActions grey_moveSliderToValue:value];23}24+ (id<GREYElementInteraction>)selectElementWithMatcher:(id<GREYMatcher>)matcher;25+ (id<GREYElementInteraction>)selectElementWithMatcher:(id<GREYMatcher>)matcher {26 return [[GREYElementInteraction alloc] initWithElementMatcher:matcher];27}
grey_moveSliderToValue
Using AI Code Generation
1[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"slider")] performAction:grey_moveSliderToValue(0.9)];2GREY_EXPORT id<GREYAction> grey_moveSliderToValue(float value);3id<GREYAction> grey_moveSliderToValue(float value) {4 constraints:grey_respondsToSelector(@selector(setValue:))5 performBlock:^BOOL(id element, NSError *__strong *errorOrNil) {6 [(UISlider *)element setValue:value animated:YES];7 return YES;8 }];9}10GREY_EXPORT id<GREYMatcher> grey_respondsToSelector(SEL selector);11id<GREYMatcher> grey_respondsToSelector(SEL selector) {12 return [GREYElementMatcherBlock matcherWithMatchesBlock:^BOOL(id element) {13 return [element respondsToSelector:selector];14 }15 descriptionBlock:^NSString *{16 return [NSString stringWithFormat:@"responds to selector: %@", NSStringFromSelector(selector)];17 }];18}19+ (instancetype)matcherWithName:(NSString *)name20 matchesBlock:(GREYMatchesBlock)matchesBlock21 descriptionBlock:(GREYDescriptionBlock)descriptionBlock;
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!