如何比较 TextFrom UI 和 Text Which is received from Web Service in KIF 3.1.1?

How to compare TextFrom UI and Text Which is received from Web Service in KIF 3.1.1?

我想比较来自 UI 的文本和我使用 KIF V3.0 从 WebService 获得的内容。我知道如何在 KIF 1.0 中进行比较,但我不知道如何在 KIF V3.0 中进行比较。

对于 V1.0

+(id)stepToverifyOutput:(NSString *) expectedLabel 可访问性:(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);
}];

}

请为 me.I 卡在这个地方做必要的事情。

KIF 的 [tester waitForViewWithAccessibilityLabel:myLabel] 方法 returns 实际视图本身,然后您可以使用它来断言。例如:

NSString *accessibilityLabel = @"yourLabel";
NSString *expectedValue = @"whateveryouexpect";

UILabel *label = (UILabel*)[tester waitForViewWithAccessibilityLabel:accessibilityLabel];
XCTAssert([label.text isEqualToString:expectedValue], @"BADONKADONK");

您不需要 运行 整个步骤。这也具有更易读和直接的优势:获取标签,确保其文本值符合预期。如果找不到该值,那么测试自然会失败。

我想我答对了你的问题。如果只有这样,您就面临着与字符串进行比较的问题,那么您可以直接通过您的自定义代码,如:

if (yourFirstString isEqualTo:YourSecondString)

  {
       //Text Matches.
  }

其他

 {
      //Text not matches.
 }