2013-03-25 26 views

回答

4

上的日期選取器使用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;   
      }]; 
} 
+0

它看起來OK。任何人都試過嗎? – 2013-04-03 14:38:53

0

這裏有一個更先進的日期(非常基本的)方法你可以放在一個類別上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]; 
2

更多更新的答案。

使用來自KIF這種方法:

- (void) selectDatePickerValue:(NSArray*)datePickerColumnValues;

可用上KIF 3.1.0

相關問題