我想使用KIF V3.0来解析文本来自UI以及从WebService获得的内容。我知道如何比较KIF 1.0,但KIF V3.0我不知道。
对于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);
}];
}
请为我做点什么。我被困在这个地方。
答案 0 :(得分:2)
KIF' [tester waitForViewWithAccessibilityLabel:myLabel]
方法返回实际视图本身,然后您可以使用它来断言。例如:
NSString *accessibilityLabel = @"yourLabel";
NSString *expectedValue = @"whateveryouexpect";
UILabel *label = (UILabel*)[tester waitForViewWithAccessibilityLabel:accessibilityLabel];
XCTAssert([label.text isEqualToString:expectedValue], @"BADONKADONK");
你不需要为它完成整个步骤。这也具有更易读和直接的优点:获取标签,确保其文本值符合预期。如果没有找到该值,则测试自然会失败。
答案 1 :(得分:1)
我认为我的问题是正确的。你遇到了与字符串比较的问题,如果只有这样你可以直接通过自定义代码,如:
if(yourFirstString isEqualTo:YourSecondString)
{
//Text Matches.
}
否则
{
//Text not matches.
}