How to use grey_setDate method of performAction class

Best EarlGrey code snippet using performAction.grey_setDate

PickerViewInteractionTest.m

Source:PickerViewInteractionTest.m Github

copy

Full Screen

...39 dateFormatter.dateFormat = @"YYYY/MM/dd";40 NSDate *desiredDate = [dateFormatter dateFromString:dateString];41 [[EarlGrey selectElementWithMatcher:grey_text(@"Date")] performAction:grey_tap()];42 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"DatePickerId")]43 performAction:grey_setDate(desiredDate)];44 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"DatePickerId")]45 assertWithMatcher:grey_datePickerValue(desiredDate)];46 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"DateLabelId")]47 assertWithMatcher:grey_text(dateString)];48}49- (void)testDateUpdateCallbackIsNotInvokedIfDateDoesNotChange {50 NSString *dateString = @"1986/12/26";51 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];52 dateFormatter.dateFormat = @"YYYY/MM/dd";53 NSDate *desiredDate = [dateFormatter dateFromString:dateString];54 [[EarlGrey selectElementWithMatcher:grey_text(@"Date")] performAction:grey_tap()];55 // Changing the date must change the label.56 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"DatePickerId")]57 performAction:grey_setDate(desiredDate)];58 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"DatePickerId")]59 assertWithMatcher:grey_datePickerValue(desiredDate)];60 // Clearing the label to revert the changes.61 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"ClearDateLabelButtonId")]62 performAction:grey_tap()];63 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"DateLabelId")]64 assertWithMatcher:grey_text(@"")];65 // Executing the change date action with the same value should not change the value, thus not66 // invoking the update callback.67 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"DatePickerId")]68 performAction:grey_setDate(desiredDate)];69 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"DateLabelId")]70 assertWithMatcher:grey_text(@"")];71}72- (void)testTimeOnlyPicker {73 NSString *timeString = @"19:30:00";74 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];75 dateFormatter.dateFormat = @"HH:mm:ss";76 NSDate *desiredTime = [dateFormatter dateFromString:timeString];77 [[EarlGrey selectElementWithMatcher:grey_text(@"Time")] performAction:grey_tap()];78 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"DatePickerId")]79 performAction:grey_setDate(desiredTime)];80 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"DatePickerId")]81 assertWithMatcher:grey_datePickerValue(desiredTime)];82}83- (void)testDateTimePicker {84 NSString *dateTimeString = @"1986/12/26 19:30:00";85 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];86 dateFormatter.dateFormat = @"YYYY/MM/dd HH:mm:ss";87 NSDate *desiredDateTime = [dateFormatter dateFromString:dateTimeString];88 [[EarlGrey selectElementWithMatcher:grey_text(@"DateTime")] performAction:grey_tap()];89 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"DatePickerId")]90 performAction:grey_setDate(desiredDateTime)];91 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"DatePickerId")]92 assertWithMatcher:grey_datePickerValue(desiredDateTime)];93}94- (void)testCountdownTimePicker {95 NSString *timerString = @"12:30:00";96 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];97 dateFormatter.dateFormat = @"HH:mm:ss";98 NSDate *desiredTimer = [dateFormatter dateFromString:timerString];99 [[EarlGrey selectElementWithMatcher:grey_text(@"Counter")] performAction:grey_tap()];100 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"DatePickerId")]101 performAction:grey_setDate(desiredTimer)];102 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"DatePickerId")]103 assertWithMatcher:grey_datePickerValue(desiredTimer)];104}105- (void)testCustomPicker {106 [[EarlGrey selectElementWithMatcher:grey_text(@"Custom")] performAction:grey_tap()];107 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]108 performAction:grey_setPickerColumnToValue(0, @"Blue")];109 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]110 performAction:grey_setPickerColumnToValue(1, @"5")];111 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]112 assertWithMatcher:grey_pickerColumnSetToValue(0, @"Blue")];113 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]114 assertWithMatcher:grey_pickerColumnSetToValue(1, @"5")];115}...

Full Screen

Full Screen

FTRPickerViewInteractionTest.m

Source:FTRPickerViewInteractionTest.m Github

copy

Full Screen

...63 dateFormatter.dateFormat = @"HH:mm:ss";64 NSDate *desiredTime = [dateFormatter dateFromString:timeString];65 [[EarlGrey selectElementWithMatcher:grey_text(@"Time")] performAction:grey_tap()];66 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"DatePickerId")]67 performAction:grey_setDate(desiredTime)];68 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"DatePickerId")]69 assertWithMatcher:grey_datePickerValue(desiredTime)];70}71- (void)testDateTimePicker {72 NSString *dateTimeString = @"1986/12/26 19:30:00";73 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];74 dateFormatter.dateFormat = @"YYYY/MM/dd HH:mm:ss";75 NSDate *desiredDateTime = [dateFormatter dateFromString:dateTimeString];76 [[EarlGrey selectElementWithMatcher:grey_text(@"DateTime")] performAction:grey_tap()];77 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"DatePickerId")]78 performAction:grey_setDate(desiredDateTime)];79 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"DatePickerId")]80 assertWithMatcher:grey_datePickerValue(desiredDateTime)];81}82- (void)testCountdownTimePicker {83 NSString *timerString = @"12:30:00";84 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];85 dateFormatter.dateFormat = @"HH:mm:ss";86 NSDate *desiredTimer = [dateFormatter dateFromString:timerString];87 [[EarlGrey selectElementWithMatcher:grey_text(@"Counter")] performAction:grey_tap()];88 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"DatePickerId")]89 performAction:grey_setDate(desiredTimer)];90 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"DatePickerId")]91 assertWithMatcher:grey_datePickerValue(desiredTimer)];92}93- (void)testCustomPicker {94 [[EarlGrey selectElementWithMatcher:grey_text(@"Custom")] performAction:grey_tap()];95 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]96 performAction:[GREYActions actionForSetPickerColumn:0 toValue:@"Blue"]];97 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]98 performAction:[GREYActions actionForSetPickerColumn:1 toValue:@"5"]];99 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]100 assertWithMatcher:grey_pickerColumnSetToValue(0, @"Blue")];101 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]102 assertWithMatcher:grey_pickerColumnSetToValue(1, @"5")];103}...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful