How can I validate the Text of a Label in Kif

815 views
Skip to first unread message

Farhan Syed

unread,
Feb 1, 2012, 12:08:03 PM2/1/12
to kif-fr...@googlegroups.com
Hi guys,

I am very new to KIF and have been trying to implement it at my work place, we are working on a monstrous application.

I've gotten KIF up and running and have messed around with the sample projects I've made. I have on issue though. Is there a way to validate the text of a Static Label? I've been trying to figure out how exactly KIF uses accessibility labels to find it's elements, but I am pretty new to objective C and this is a little bit over my head. Does anyone have a suggestion?

I would like to have a step that finds and accessibility label and validates that that text inside of it,

Thanks for all your help.

Leeroy

unread,
Feb 1, 2012, 9:10:43 PM2/1/12
to kif-fr...@googlegroups.com

+ (id)stepToCheckTextWithAccessibilityLabel:(NSString *)text accessibilityLabel:(NSString *)accessibilityLabel traits:(UIAccessibilityTraits)traits;

{

return [KIFTestStep stepWithDescription:[NSString stringWithFormat:@"Match string \"%@\" against view with accessibility label \"%@\"", text, accessibilityLabel] executionBlock:^(KIFTestStep *step, NSError **error)

{

UIAccessibilityElement *element = [self

  _accessibilityElementWithLabel:accessibilityLabel

  accessibilityValue:nil

  tappable:NO

  traits:traits

  error:error];

if (!element)

{

return KIFTestStepResultWait;

}

KIFTestCondition([text isEqualToString:[element text]], error, @"Text doesn't match.");

return KIFTestStepResultSuccess;

}];

}


Hope this may help

Eric Firestone

unread,
Feb 3, 2012, 3:24:04 PM2/3/12
to kif-fr...@googlegroups.com
You may also just be able to use either of these:

+ (id)stepToWaitForViewWithAccessibilityLabel:(NSString *)label;

This will wait until a view with the given accessibility label appears. If one doesn't appear within the timeout period (10s by default) then the step will fail.

+ (id)stepToWaitForViewWithAccessibilityLabel:(NSString *)label value:(NSString *)value traits:(UIAccessibilityTraits)traits;

This will wait until a view with a given accessibility label has a given value and will fail if none appears before the timeout.

For a bit more context on labels vs. values and when and why you should use them, see my diatribe here: https://groups.google.com/d/msg/kif-framework/JKNVKbjJKDM/yq4TE3hpNBEJ
Reply all
Reply to author
Forward
0 new messages