Check title text label on button?

325 views
Skip to first unread message

kyleplattner

unread,
May 1, 2012, 2:30:26 PM5/1/12
to KIF iOS Automated Testing Framework
How should I go about checking the title text label on a UIButton?

Eric Firestone

unread,
May 1, 2012, 4:26:20 PM5/1/12
to kif-fr...@googlegroups.com
I'm not sure exactly what you're trying to do, but generally you'll want to use the following with a traits set to UIAccessibilityTraitButton.

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

If you explicitly set the accessibility label for the button to something then look for that value, otherwise UIButton will return the title of the button as the accessibility label. This step simply waits for a button with the given label to appear in the UI. This is useful in verifying that your UI changes in response to some other action, for example if when starting a new game you wanted to verify that the "Choose Number of Players" button appeared.

If you're trying to find and tap a specific button, then use this step instead:

+ (id)stepToTapViewWithAccessibilityLabel:(NSString *)label traits:(UIAccessibilityTraits)traits;


kyleplattner

unread,
May 3, 2012, 3:41:12 PM5/3/12
to kif-fr...@googlegroups.com
It doesn't appear to be working. I am setting the label here

[scenario addStep:[KIFTestStep stepToSetTitle:@"300" forButtonWithAccessibilityLabel:@"LEGENDEDITORmax_button"]];

    

which works fine - and then I check for it right afterwards using this: 

    

[scenario addStep:[KIFTestStep stepToWaitForViewWithAccessibilityLabel:@"LEGENDEDITORmax_button" value:@"300" traits:UIAccessibilityTraitButton]];


and it fails. 


kyleplattner

unread,
May 3, 2012, 3:42:13 PM5/3/12
to kif-fr...@googlegroups.com
with this: 

FAIL (10.02s): Wait for view with accessibility label "LEGENDEDITORmax_button" and accessibility value "300"

FAILING ERROR: Error Domain=KIFTest Code=0 "The step timed out after 10.00 seconds." UserInfo=0x12db6100 {NSUnderlyingError=0x12dacea0 "Waiting for presence of accessibility element with label "LEGENDEDITORmax_button" and accessibility value "300"", NSLocalizedDescription=The step timed out after 10.00 seconds.}

Reply all
Reply to author
Forward
0 new messages