NSNerd
NSNerd

Reputation: 141

UIDatePicker Automation using KIF dateChangedAction not called

I'm automating date selection on UIDatePicker using KIF. I added the accessibility label and set the target for the picker if the date changes.

Ref: http://bit.ly/140ICwo

+(id) changeDate: (NSDate *) myDate
{

  [s addStep:[KIFTestStep stepToEnterDate:myDate   ToDatePickerWithAccessibilityLabel:@"datePicker"]];
  [self wait:s timeInSeconds:3];
  [s addStep:[KIFTestStep stepToTapViewWithAccessibilityLabel:@"Done" traits:UIAccessibilityTraitButton]];
 return s;
}

- (void) ViewDidLoad
{   
    ... 
    datePicker.maximumDate = lastAvailableDate;
    datePicker.date = (dateValue ? dateValue : [NSDate date]);
    [datePicker addTarget:self action:@selector(dateChangedAction:)
     forControlEvents:UIControlEventValueChanged];
    self.datePicker.accessibilityLabel = @"datePicker";
    self.footerLabel.accessibilityLabel = @"datelabel";
}


- (IBAction)dateChangedAction:(id)sender
{
  [dateValue release];
  dateValue = [datePicker.date retain];
  dateCell.detailTextLabel.text = [[[self class] sharedFormatter]  stringFromDate:dateValue];
  [self setDateTitleText:[[[self class] sharedFormatter] stringFromDate:dateValue]];
}

The Picker rotates and stops at the given date however the "dateChangedAction" function is not getting called, hence the label which displays the selected date is not getting updated.

If I run the app with out KIF everything works fine. Also I tried to manually select a date when running KIF to check it it updates the label but it seems like the UI gets frozen and I cannot click any UI controls.

Looks like the problem is related to this posting

http://bit.ly/10xtbqU

Any help is very much appreciated.

Thanks

Upvotes: 1

Views: 675

Answers (1)

Ben
Ben

Reputation: 31

I run into the same problem you're just missing

[picker sendActionsForControlEvents:UIControlEventValueChanged];

to trigger the dateChangedAction callback, in other words try this:

+ (id)stepToEnterDate:(NSDate*)date ToDatePickerWithAccessibilityLabel:(NSString*)label
{
    NSString *description=[NSString stringWithFormat:@"Enter date to Date picker with accessibility label '%@'",[date description]];
    return [self stepWithDescription:description executionBlock:^(KIFTestStep *step, NSError **error)
            {
                UIAccessibilityElement *element = [[UIApplication sharedApplication] accessibilityElementWithLabel:label];
                KIFTestCondition(element, error, @"View with label %@ not found", label);
                if(!element)
                {
                    return KIFTestStepResultWait;
                }
                UIDatePicker *picker = (UIDatePicker*)[UIAccessibilityElement viewContainingAccessibilityElement:element];

                KIFTestCondition([picker isKindOfClass:[UIDatePicker class]], error, @"Specified view is not a picker");

                [picker setDate:date animated:YES];

                // trigger the UIControlEventValueChanged in case of event listener
                [picker sendActionsForControlEvents:UIControlEventValueChanged];

                return KIFTestStepResultSuccess;         
            }];
}

Upvotes: 3

Related Questions