我正在使用KIF在UIDatePicker上自动进行日期选择。我添加了可访问性标签,并在日期更改时为选择器设置了目标。

参考: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]];
}

选择器旋转并在给定日期停止,但是未调用“dateChangedAction”功能,因此显示所选日期的标签没有更新。

如果我在没有KIF的情况下运行该应用程序,则一切正常。另外,我尝试在运行KIF时手动选择一个日期以检查它是否会更新标签,但UI似乎冻结了,无法单击任何UI控件。

看起来问题与该帖子有关

http://bit.ly/10xtbqU

很感谢任何形式的帮助。

谢谢

最佳答案

我遇到了同样的问题,你只是想念

[picker sendActionsForControlEvents:UIControlEventValueChanged];

触发dateChangedAction回调,
换句话说,请尝试以下操作:
+ (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;
            }];
}

关于ios - 使用KIF dateChangedAction的UIDatePicker Automation不被调用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16555693/

10-12 00:25