我使用KIF框架自動化我的應用程序。對於其中一種場景,我需要從UIDatePicker中自動選擇日期。如何從使用KIF框架的UIDatePicker中自動選擇日期
有沒有人做過這個?並拋出一些關於如何繼續或分享一些代碼的想法。
任何幫助,非常感謝。
感謝
我使用KIF框架自動化我的應用程序。對於其中一種場景,我需要從UIDatePicker中自動選擇日期。如何從使用KIF框架的UIDatePicker中自動選擇日期
有沒有人做過這個?並拋出一些關於如何繼續或分享一些代碼的想法。
任何幫助,非常感謝。
感謝
上的日期選取器使用setAccessibilityLabel
然後在KIFTestStep
類這樣的定義使用setDate
的方法:
+ (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];
return KIFTestStepResultSuccess;
}];
}
這裏有一個更先進的日期(非常基本的)方法你可以放在一個類別上KIFUITestActor
- (void)enterDate:(NSDate *)date intoDatePickerWithAccessibilityLabel:(NSString *)label {
[tester runBlock:^KIFTestStepResult(NSError **error) {
UIAccessibilityElement *element;
[self waitForAccessibilityElement:&element view:nil withLabel:label value:nil traits:UIAccessibilityTraitNone tappable:NO];
KIFTestCondition(element, error, @"Date picker with label %@ not found", label);
KIFTestCondition([element isKindOfClass:[UIDatePicker class]], error, @"Specified view is not a picker");
UIDatePicker *picker = (UIDatePicker *)element;
[picker setDate:date animated:NO];
[self waitForTimeInterval:1.f];
return KIFTestStepResultSuccess;
}];
}
然後,你可以使用它像這樣:
[tester enterDate:[NSDate distantPast] intoDatePickerWithAccessibilityLabel:kLocaleDatePicker];
更多更新的答案。
使用來自KIF這種方法:
- (void) selectDatePickerValue:(NSArray*)datePickerColumnValues;
可用上KIF 3.1.0
它看起來OK。任何人都試過嗎? – 2013-04-03 14:38:53