简体   繁体   中英

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

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.

I think i an getting right your question. you are facing the problem to compare to string if this only then you can directly by your custom code like :

if (yourFirstString isEqualTo:YourSecondString)

  {
       //Text Matches.
  }

else

 {
      //Text not matches.
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM