I want to comare Text From UI and What I get from WebService Using KIF V3.0. I know how to compare in KIF 1.0 but KIF V3.0 I don't know.
For V1.0
+(id)stepToverifyOutput:(NSString *) expectedLabel accessibility:(NSString *)mylabel
{
NSString *description = [NSString stringWithFormat:@"Verify label text for %@",expectedLabel];
return [self stepWithDescription:description executionBlock:^(KIFTestStep *step, NSError **error) {
UIAccessibilityElement *element = [[UIApplication sharedApplication] accessibilityElementWithLabel:mylabel];
BOOL isValid;
UINavigationController *navbar;
UILabel *lblName;
if([element isKindOfClass:[UILabel class]]){
isValid=YES;
lblName = (UILabel *)[UIAccessibilityElement viewContainingAccessibilityElement:element];;
if ([expectedLabel isEqualToString:lblName.text]) {
return KIFTestStepResultSuccess;
}
}else{
isValid=NO;
navbar = (UINavigationController *)[UIAccessibilityElement viewContainingAccessibilityElement:element];;
if ([expectedLabel isEqualToString:navbar.title]) {
return KIFTestStepResultSuccess;
}
}
KIFTestCondition(NO, error, @"Failed to compare the label text: expected '%@', actual '%@'", expectedLabel,(isValid)?lblName.text:navbar.title);
}];
}
Please do needful for me.I am stuck at this place.
KIF's [tester waitForViewWithAccessibilityLabel:myLabel]
method returns the actual view itself, which you can then use to assert. So for example:
NSString *accessibilityLabel = @"yourLabel";
NSString *expectedValue = @"whateveryouexpect";
UILabel *label = (UILabel*)[tester waitForViewWithAccessibilityLabel:accessibilityLabel];
XCTAssert([label.text isEqualToString:expectedValue], @"BADONKADONK");
You don't need to run a whole step for it. This also has the advantage of being much more readable and straight forward: get a label, make sure it's text value is as expected. If the value isn't found then the test will naturally fail.